Module 13: ALV Reporting
ALV (ABAP List Viewer) is the standard SAP framework for tabular data display.
It provides sorting, filtering, aggregation, layouts, and events out of the box, making it the preferred reporting approach in ABAP.
1. Why ALV?
Compared to classical WRITE output, ALV provides:
- Sorting & filtering
- Totals & subtotals
- Layout variants
- Export to Excel
- User interaction
In ABAP 7.5+, never build reports using WRITE unless maintaining legacy code.
2. Classic ALV (Function Module Based)
Classic ALV is based on function modules such as:
REUSE_ALV_GRID_DISPLAYREUSE_ALV_LIST_DISPLAY
2.1 Basic Example (Classic ALV)
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_structure_name = 'SPFLI'
TABLES
t_outtab = lt_spfli.
2.2 Characteristics
-
Procedural
-
Uses field catalog
-
Limited OO extensibility
-
Still found in legacy systems
Classic ALV should not be used in new developments.
3. Field Catalog (ALV Metadata)
The field catalog controls:
-
Column labels
-
Visibility
-
Output length
-
Editability
-
Hotspots
3.1 Field Catalog Structure
DATA gt_fcat TYPE slis_t_fieldcat_alv.
Example entry:
DATA gs_fcat TYPE slis_fieldcat_alv.
gs_fcat-fieldname = 'CARRID'.
gs_fcat-seltext_m = 'Carrier'.
APPEND gs_fcat TO gt_fcat.
Field catalogs decouple data structure from presentation logic.
4. OO ALV (CL_GUI_ALV_GRID)
OO ALV uses class CL_GUI_ALV_GRID and is more flexible than classic ALV.
4.1 Basic OO ALV Flow
-
Create container
-
Create ALV grid object
-
Set table & field catalog
-
Register events
DATA lo_alv TYPE REF TO cl_gui_alv_grid.
CREATE OBJECT lo_alv
EXPORTING
i_parent = lo_container.
lo_alv->set_table_for_first_display(
EXPORTING
is_layout = ls_layout
CHANGING
it_outtab = lt_data
it_fieldcatalog = lt_fcat
).
4.2 Characteristics
-
Fully object-oriented
-
Supports custom events
-
Flexible UI control
-
Complex to implement
OO ALV is powerful but verbose and UI-heavy. For simple reports, prefer SALV.
5. SALV Model (Recommended – 7.5+)
SALV (Simple ALV) is the modern, lightweight ALV framework.
5.1 Why SALV?
-
No field catalog required
-
Minimal code
-
OO-based
-
Clean and readable
-
Ideal for reports
Use SALV by default unless you need editable grids or custom containers.
5.2 Basic SALV Example
DATA lo_alv TYPE REF TO cl_salv_table.
cl_salv_table=>factory(
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = lt_spfli
).
lo_alv->display( ).
5.3 Column Customization (SALV)
DATA lo_columns TYPE REF TO cl_salv_columns_table.
lo_columns = lo_alv->get_columns( ).
DATA lo_column TYPE REF TO cl_salv_column.
lo_column = lo_columns->get_column( 'CARRID' ).
lo_column->set_long_text( 'Carrier ID' ).
6. Events & Layout Handling
6.1 ALV Events (OO / SALV)
Common events:
-
Double click
-
User command
-
Toolbar action
Example (SALV event handler):
SET HANDLER lo_handler->on_double_click FOR lo_alv.
Events enable interactive reports (drill-down, navigation).
6.2 Layout Handling
Layouts allow users to:
-
Save column order
-
Apply filters
-
Store variants
SALV layout:
lo_alv->get_layout( )->set_save_restriction( if_salv_c_layout=>restrict_none ).
Always allow layout saving for business users.
7. Comparison: ALV Approaches
| Feature | Classic ALV | OO ALV | SALV |
|---|---|---|---|
| Paradigm | Procedural | OO | OO |
| Complexity | Medium | High | Low |
| Editable Grid | ❌ | ✅ | ❌ |
| Field Catalog | Required | Required | ❌ |
| New Dev | ❌ | ⚠️ | ✅ |
8. Modern ABAP Reporting Strategy
-
CDS View (data model)
-
SALV for reporting
-
Fiori / UI5 for UI
- Common Mistakes
-
Using WRITE instead of ALV
-
Building new classic ALVs
-
Over-customizing field catalogs
-
Ignoring layout variants
-
Mixing business logic into ALV code
10. Summary
-
ALV is the standard reporting framework
-
Classic ALV is legacy
-
OO ALV is powerful but complex
-
SALV is simple and modern
-
Field catalogs control presentation
-
Events enable interaction
-
Layouts improve usability
11. Practice Exercises
-
Create a SALV report using internal table data.
-
Customize column headings.
-
Enable layout saving.
-
Add a double-click event.
-
Compare SALV vs OO ALV complexity.
12. What’s Next?
➡️ Module 14: File Handling & Data Transfer
Strong ALV skills are mandatory for ABAP interviews and daily work.