ERPClimb logoERPClimb
ALV Reports
ABAP Developmentintermediate 9 min read

ALV Reports Part 5: Layout, Sort, Filter, Totals and Variants

Preview · a free account unlocks the full lesson

Key takeaway

Control how an ALV opens: layout options, default sort with subtotals, pre-set filters, totals-only views, and user layout variants (DISVARIANT, i save, default variant on the selection screen with F4 help).

In this lessonShow sections

Visual overview

ALV Reports Part 5: Layout, Sort, Filter, Totals and Variants — learning sheetFlow: Run the code example: data sorted by airline with subtotals → Change the layout, save it as default, run again → Choose a variant on the selection screen with F4. Key ideas: LAYOUT (LVC_S_LAYO / SLIS_LAYOUT_ALV); SORT AND SUBTOTALS; FILTERS; LAYOUT VARIANTS. Watch out: Hard-coding a sort the users constantly change is worse than letting them save a default variant.ERPClimb.com / ABAP / LESSON 5/10 / LEARNING SHEETALV Reports Part 5: Layout, Sort, Filter, Totals andVariants1 · HOW IT FLOWS1Run the code exampledata sorted by airline withsubtotals2Change the layout, saveit as default, run again3Choose a variant on theselection screen with F42 · KEY IDEAS EXPLAINEDLayout (LVC_S_LAYO / SLIS_LAYOUT_ALV)zebra, cwidth_opt — readability.totals_bef — show totals above the data.Sort And Subtotalslvc_s_sort: spos (sequence), fieldname, up/down,subtot = 'X'. Example: sort by CARRID withsubtotal, then CONNID. Columns with do_sum show…Filterslvc_s_filt: fieldname, sign, option, low, high(like a range). Users see the filter icon and canremove it.Layout VariantsDISVARIANT with report = sy-repid (and handle ifone program has several ALVs).i_save: ' ' no saving, 'U' user-specific, 'X'global only, 'A' both.3 · REMEMBER · WATCH OUTRememberDefault sort and subtotals come from the sort table (lvc_t_sort /slis_t_sortinfo_alv) with subtot = 'X'.Filters can be pre-set with lvc_t_filt; totals need do_sum in thecatalog or a sort with subtotal.Layout variants (DISVARIANT) let users save column order, sorts andfilters; i_save = 'A' allows user-specific and global.!Watch outHard-coding a sort the usersconstantly change is worse thanletting them save a default variant.4 · IN A REAL PROJECTA sales manager asked for "the report sorted by region with subtotals, but my team wants it bycustomer". The developer first added a radio button for each sort, and requests for new sort options keptcoming. Instead, the team enabled layout variants with i_save = 'A', created a global default layout by…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Parts 1 through 4 covered displaying data in an ALV; this lesson is about controlling the initial view and letting users keep their own. Default sort order and subtotals come from a sort table — lvc_t_sort or slis_t_sortinfo_alv — with subtot = 'X' marking where subtotals appear.

Filters can be pre-set using lvc_t_filt, and totals need either do_sum set in the field catalog or a sort entry with a subtotal attached. Layout variants, built around the DISVARIANT structure, let users save their own column order, sorts, and filters, and setting i_save = 'A' allows both user-specific and global variants to be saved.

One thing worth keeping in mind: hard-coding a sort order that users keep changing anyway is worse than simply letting them save their own default variant.

On the layout settings themselves (LVC_S_LAYO or SLIS_LAYOUT_ALV): zebra and cwidth_opt improve readability through striping and optimized column widths; totals_bef shows totals above the data rather than below; no_totline hides the total line entirely; sel_mode controls the selection mode; and grid_title puts a title above the grid.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.