ABAPintermediate
ALV (ABAP List Viewer) Reporting
Building interactive, sortable, exportable list output using the ALV Grid and ALV Object Model frameworks.
Almost every SAP report request ends up as "show me a table with totals, let me sort it, and let me export to Excel". ALV is the framework that provides all of that without you writing it.
ALV is like a spreadsheet engine bolted onto your SAP report - you hand it rows and column definitions, and it gives users sorting, filtering, and Excel export for free, the way a pivot table gives you interactivity without writing rendering code.
Key Concepts
1
Three generations, and you will meet all of them.
REUSE_ALV_GRID_DISPLAY function module. Oldest, still everywhere.
CL_GUI_ALV_GRID classic object-oriented ALV. Full control,
a lot of setup.
CL_SALV_TABLE the modern one. Far less code for the
standard case.2
The modern one, in full.
TRY.
cl_salv_table=>factory(
IMPORTING r_salv_table = DATA(lo_alv)
CHANGING t_table = lt_data ).
lo_alv->display( ).
CATCH cx_salv_msg.
ENDTRY.3
That produces a sortable, filterable, exportable grid with column headings taken from the data dictionary.
Four lines.
4
The field catalog is the concept to understand. It is metadata describing each column: its heading, the
underlying data element, whether it can be edited, whether it is a hotspot.
5
Three ways to get one:
6
derived from a DDIC structure -- headings, types and
F1 help come free
manual built field by field in code
merged derived, then adjusted7
CL_SALV_TABLE derives it automatically, which is most of why it needs so little code. Building a catalog
by hand for a structure that already exists in the dictionary is wasted work, and it drifts when the
structure changes.
CL_SALV_TABLE
8
Interactivity is event handling. The classic grid registers handlers:
9
HANDLE_USER_COMMAND a toolbar button was pressed
HANDLE_HOTSPOT_CLICK a cell was clicked -- drill down from here
HANDLE_DOUBLE_CLICK10
Layout and sort objects carry subtotals, colours and column widths. Variants let a user save their own
column and sort arrangement and get it back next time, per user — which is a large part of why users like
ALV.
11
The performance point worth making. ALV rendering is rarely the bottleneck. When an ALV report is slow,
it is the SELECT and the internal table build before it.
SELECT
12
So treat ALV as a presentation layer over data you have already retrieved efficiently. Tuning the grid when
the problem is a select inside a loop fixes nothing.
13
A common mistake: changing the underlying table and wondering why the screen is unchanged. The grid
holds a reference and must be told:
14
lo_grid->refresh_table_display( ).15
Where this is heading. In S/4HANA and Fiori, the same requirement is a list report built on a CDS view
with Fiori Elements. ALV remains the answer inside SAP GUI, and a good answer names both — ALV for GUI,
Fiori Elements for anything new and user-facing.
16
What the interviewer is probing.1. "Which ALV approach would you pick today?" Probing: currency. Stalls: "The function
module." Moves up: CL_SALV_TABLE for simple output and the grid control for interactive needs;
REUSE_ALV_GRID_DISPLAY is legacy.
17
2. "How do you handle a user double-clicking a row?" Probing: event handling. Stalls: "Read
the selection." Moves up: register and handle the event, read the selected row from the internal
table, and call the transaction — not a hardcoded index.
18
3. "How do you let users keep their own layout?" Probing: the practical feature. Stalls:
"They cannot." Moves up: layout variants with a save mode, which is what users actually ask for
after the first demo.
19
4. "What drives the column headings and formatting?" Probing: the field catalog. Stalls:
"The code." Moves up: the field catalog, ideally derived from a dictionary structure so texts and
conversion exits come for free.