Skip to content

CL_SALV_TABLE

The modern ALV grid. Replaces REUSE_ALV_GRID_DISPLAY and the older OO classes.

Purpose

Display an internal table as a sortable, filterable, exportable grid — fullscreen or as a control inside a screen — with a fraction of the boilerplate that the old function-module approach required.

Minimum working example

REPORT z_salv_demo.

DATA: lt_users TYPE STANDARD TABLE OF usr02,
      lo_alv   TYPE REF TO cl_salv_table.

START-OF-SELECTION.

  SELECT bname, ustyp, gltgv, gltgb
    FROM usr02
    INTO TABLE @lt_users
    UP TO 100 ROWS.

  TRY.
      cl_salv_table=>factory(
        IMPORTING r_salv_table = lo_alv
        CHANGING  t_table      = lt_users ).

      lo_alv->display( ).

    CATCH cx_salv_msg INTO DATA(lx_salv).
      MESSAGE lx_salv->get_text( ) TYPE 'E'.
  ENDTRY.

That's it. Run it — you get a fully functional grid with sort, filter, sum, layout management, and export to Excel.

Common customisations

DATA(lo_columns) = lo_alv->get_columns( ).
lo_columns->set_optimize( abap_true ).      " auto-fit widths

DATA(lo_col) = lo_columns->get_column( 'BNAME' ).
lo_col->set_short_text( 'User' ).
lo_col->set_medium_text( 'User ID' ).
lo_col->set_long_text( 'User Name' ).
DATA(lo_functions) = lo_alv->get_functions( ).
lo_functions->set_all( abap_true ).         " enable all standard buttons
DATA(lo_sorts) = lo_alv->get_sorts( ).
lo_sorts->add_sort( columnname = 'GLTGB'
                    sequence   = if_salv_c_sort=>sort_down ).
" 1) Mark a column as a hotspot
DATA(lo_col) = lo_alv->get_columns( )->get_column( 'BNAME' ).
lo_col->set_cell_type( if_salv_c_cell_type=>hotspot ).

" 2) Register an event handler
DATA(lo_events) = lo_alv->get_event( ).
SET HANDLER on_link_click FOR lo_events.

Common pitfalls

Don't pass a sorted/hashed table

t_table must be a standard internal table. If yours is sorted or hashed, copy it: lt_display = lt_source.

Editable grids — different class

CL_SALV_TABLE is read-only. For editable cells you still need CL_GUI_ALV_GRID. SAP has signalled CL_SALV_GUI_TABLE_IDA (with IDA) for high-volume scenarios, but plain editable ALV is still the older grid.

  • Empty table message: by default the grid shows nothing helpful. Set it explicitly:
    lo_alv->set_screen_status(
      pfstatus = 'STANDARD'
      report   = 'SAPLSALV' ).
    
  • Currency / quantity columns: they need a reference field for correct formatting. Use set_currency_column( ) / set_quantity_column( ) on the column object.

Variants

Need Use
Fullscreen grid cl_salv_table=>factory( ... )->display( )
Embedded in a screen pass r_container to factory
Hierarchical (tree) display cl_salv_tree
Massive datasets (paged) cl_salv_gui_table_ida

See also

Comments