ALV Reports
ABAP Developmentbeginner

ALV Reports Part 2: Quick ALV with CL_SALV_TABLE

Key takeaway

Use the SALV object model: cl salv table= factory, functions (toolbar), columns (texts, hiding, optimizing), display settings, aggregations and layout saving — with error handling for CX SALV MSG and CX SALV NOT FOUND.

Explanation

📌 KEY POINTS
✅ CL_SALV_TABLE creates a full ALV with a few lines: cl_salv_table=>factory( … ) then ->display( ).

✅ The field catalog is derived automatically from the internal table's types (DDIC data elements give labels).

✅ Settings are objects: get_functions( ), get_columns( ), get_aggregations( ), get_layout( ), get_display_settings( ).

⚠️ CL_SALV_TABLE is display-only — for editable grids use CL_GUI_ALV_GRID (Part 9).

━━━━━━━━━━━━━━━━━━━━
▶ WHERE WE ARE

Part 1 used the classic FM. SALV is the simpler OO alternative for display reports and is widely used in ECC 6.0 and S/4HANA on-premise.

━━━━━━━━━━━━━━━━━━━━
▶ 1. THE FACTORY

cl_salv_table=>factory( IMPORTING r_salv_table = go_alv CHANGING t_table = gt_out ).

  • t_table is CHANGING — pass a global or long-lived table (the ALV keeps a reference to it).
  • Raises CX_SALV_MSG — always wrap in TRY/CATCH.
  • Optional: list_display = abap_true for a classic list; r_container for display inside a container.

━━━━━━━━━━━━━━━━━━━━
▶ 2. FUNCTIONS (TOOLBAR)

go_alv->get_functions( )->set_all( abap_true ). switches on sort, filter, sum, export, layout buttons. Without it, the full-screen grid shows only a minimal toolbar.

━━━━━━━━━━━━━━━━━━━━
▶ 3. COLUMNS

lo_columns = go_alv->get_columns( ).

  • set_optimize( abap_true ) — optimize widths.
  • lo_column = lo_columns->get_column( 'SEATSMAX' ). — raises CX_SALV_NOT_FOUND for wrong names.
  • lo_column->set_long_text( 'Capacity' ), set_medium_text, set_short_text.
  • lo_column->set_visible( abap_false ) or set_technical( abap_true ) to hide.
  • Cast to CL_SALV_COLUMN_TABLE for table-specific features (hotspot, color, cell type).

━━━━━━━━━━━━━━━━━━━━
▶ 4. AGGREGATIONS AND SORTS

go_alv->get_aggregations( )->add_aggregation( columnname = 'SEATSOCC' ).

go_alv->get_sorts( )->add_sort( columnname = 'CONNID' subtotal = abap_true ).

━━━━━━━━━━━━━━━━━━━━
▶ 5. LAYOUT AND DISPLAY SETTINGS

  • get_layout( ): set_key( VALUE #( report = sy-repid ) ), set_save_restriction( if_salv_c_layout=>restrict_none ) so users can save layouts.
  • get_display_settings( ): set_striped_pattern( abap_true ), set_list_header( 'Flights' ).\n\n━━━━━━━━━━━━━━━━━━━━\n▶ 6. SALV VS REUSE_ALV VS CL_GUI_ALV_GRID\nSALV: least code, no field catalog, display-only. REUSE_ALV: legacy, still fine. CL_GUI_ALV_GRID: most control (editing, many events, own screen).

━━━━━━━━━━━━━━━━━━━━
▶ STEP BY STEP

  1. Create ZALV_SALV_FLIGHTS from the code example.
  2. Remove set_all( ) and compare the toolbar.
  3. Misspell a column name and observe CX_SALV_NOT_FOUND being caught.

💡 Modern syntax: VALUE #( ) for the layout key and inline declarations are allowed from 7.40.

✅ CHECKPOINT: you can build a complete display ALV with CL_SALV_TABLE and configure columns, totals and layouts.

Code example

ABAP Code
REPORT zalv_salv_flights. TYPES: BEGIN OF ty_out,         carrid   TYPE s_carr_id,         connid   TYPE s_conn_id,         fldate   TYPE s_date,         seatsmax TYPE s_seatsmax,         seatsocc TYPE s_seatsocc,       END OF ty_out. DATA: gt_out TYPE STANDARD TABLE OF ty_out,        " global: SALV keeps a reference      go_alv TYPE REF TO cl_salv_table. PARAMETERS p_carr TYPE s_carr_id DEFAULT 'LH'. START-OF-SELECTION.  SELECT carrid connid fldate seatsmax seatsocc    FROM sflight INTO TABLE gt_out WHERE carrid = p_carr.   PERFORM display_alv. *----------------------------------------------------------------------*FORM display_alv.  DATA: lo_functions TYPE REF TO cl_salv_functions_list,        lo_columns   TYPE REF TO cl_salv_columns_table,        lo_column    TYPE REF TO cl_salv_column_table,        lo_aggr      TYPE REF TO cl_salv_aggregations,        lo_sorts     TYPE REF TO cl_salv_sorts,        lo_layout    TYPE REF TO cl_salv_layout,        lo_display   TYPE REF TO cl_salv_display_settings,        ls_key       TYPE salv_s_layout_key,        lx_msg       TYPE REF TO cx_salv_msg,        lx_not_found TYPE REF TO cx_salv_not_found,        lx_data      TYPE REF TO cx_salv_data_error,        lx_exist     TYPE REF TO cx_salv_existing. * ===== Step 1: create the ALV =====  TRY.      cl_salv_table=>factory( IMPORTING r_salv_table = go_alv                              CHANGING  t_table      = gt_out ).    CATCH cx_salv_msg INTO lx_msg.      MESSAGE lx_msg TYPE 'E'.  ENDTRY. * ===== Step 2: toolbar functions =====  lo_functions = go_alv->get_functions( ).  lo_functions->set_all( abap_true ). * ===== Step 3: columns =====  lo_columns = go_alv->get_columns( ).  lo_columns->set_optimize( abap_true ).  TRY.      lo_column ?= lo_columns->get_column( 'SEATSMAX' ).      lo_column->set_long_text( 'Capacity' ).      lo_column->set_medium_text( 'Capacity' ).      lo_column->set_short_text( 'Cap.' ).      lo_column ?= lo_columns->get_column( 'CARRID' ).      lo_column->set_key( abap_true ).                   " key column (fixed, colored)    CATCH cx_salv_not_found INTO lx_not_found.      MESSAGE lx_not_found TYPE 'I'.  ENDTRY. * ===== Step 4: totals and subtotals =====  TRY.      lo_aggr = go_alv->get_aggregations( ).      lo_aggr->add_aggregation( columnname = 'SEATSOCC' ).      lo_sorts = go_alv->get_sorts( ).      lo_sorts->add_sort( columnname = 'CONNID' subtotal = abap_true ).    CATCH cx_salv_not_found cx_salv_data_error cx_salv_existing.      MESSAGE 'Aggregation setup failed' TYPE 'I'.  ENDTRY. * ===== Step 5: layouts and display settings =====  lo_layout = go_alv->get_layout( ).  ls_key-report = sy-repid.  lo_layout->set_key( ls_key ).  lo_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).   lo_display = go_alv->get_display_settings( ).  lo_display->set_striped_pattern( abap_true ).  lo_display->set_list_header( 'Flights' ). * ===== Step 6: show it =====  go_alv->display( ).ENDFORM.

Real project scenario

A logistics team needed 15 small display reports for warehouse supervisors. Using CL_SALV_TABLE, each report needed about 40 lines of ALV code with no manual field catalog, and labels came from the DDIC data elements.
One report later needed editable quantity cells; the developer switched only that report to CL_GUI_ALV_GRID rather than trying to force SALV into edit mode — the rest stayed on SALV.

Common mistakes

  • Not calling set_all( ), leaving users without sort/filter/export buttons.
  • Passing a local table that goes out of scope.
  • No TRY/CATCH around factory and get_column.
  • Trying to make SALV editable via unsupported tricks.
  • Local types with generic fields (no DDIC data elements) → empty column headers.

Best practices

  • Use DDIC data elements in the output structure for labels.
  • Always enable functions and layout saving.
  • Wrap SALV calls in TRY/CATCH.
  • Keep the ALV setup in its own routine or method.
  • Use CL_GUI_ALV_GRID when editing or complex events are needed.

Interview angle

Questions: "How do you create an ALV with CL_SALV_TABLE?", "How do you hide or rename a column in SALV?", "SALV limitations?"
Strong answer: cl_salv_table=>factory with the table as CHANGING, then get_functions( )->set_all( ), get_columns( )->get_column( )->set_long_text/set_visible, get_aggregations/get_sorts for totals, get_layout for variants, display( ); catch CX_SALV_MSG/NOT_FOUND; SALV is display-only — editing needs CL_GUI_ALV_GRID.

Practice this lesson

Quick check

1. Which requirement is the strongest reason to use CL_GUI_ALV_GRID instead of CL_SALV_TABLE?

2. ALV export to Excel is enabled by:

3. Which class is the modern OO ALV wrapper for full-screen display?

Interview questions

1. Difference between CL_SALV_TABLE and CL_GUI_ALV_GRID.

Answer it in your own words first, then compare.

2. What are the main differences between CL_SALV_TABLE and REUSE_ALV_GRID_DISPLAY?

Answer it in your own words first, then compare.

Practice more with Interview AI →

Reference-verified: the steps are checked against official SAP documentation and tutorials, and object and field names in the sample code are checked for consistency. The code has not been compiled or run on an SAP system by ERPClimb. Syntax marked release-dependent varies by SAP release, so check it in your own system.

More lessons in this topic

Interview questions on this topic

Related SAP topics