CL_SALV_TABLE : ALV Object Model – Display ALV Table

Use the below steps to display simple table using ALV Object Model (Class CL_SALV_TABLE).

  • Declare an internal table and fill the internal table with required data.
  • Generate an instance of the ALV table object
  • Display the ALV table.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: gt_spfli TYPE TABLE OF spfli.
DATA: gr_table TYPE REF TO   cl_salv_table.

*&---------------------------------------------------------------------*
*& Start-of-Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  SELECT * UP TO 10 ROWS FROM spfli INTO TABLE gt_spfli.

*Generate an instance of the ALV table object
  CALL METHOD cl_salv_table=>factory
    IMPORTING
      r_salv_table = gr_table
    CHANGING
      t_table      = gt_spfli.

*Display the ALV table.
  gr_table->display( ).

Output

sap-alv-object-model-display-table-1

You can display the simple ALV table in the following ways:

  • As a classic ABAP list : In order to display as classic ABAP list, just set the LIST_DISPLAY parameter as TRUE in the factory method of CL_SALV_TABLE.
  • As a table control

    Here, there are also two options:
    • Full screen table (ALV Grid) : As default the ALV will be displayed as ALV grid as shown in the above example
    • in a SAP-GUI container

      You generate a container of the class CL_GUI_CONTAINER in your screen. The table is displayed in this container. You can use this type of table, for example, to display multiple tables on the screen or to mix with other SAP Enjoy Controls. For this option use R_CONTAINER and CONTAINER_NAME parameters in the factory method of CL_SALV_TABLE.

Below code displays simple table as classic ABAP list.

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: gt_spfli  TYPE TABLE OF spfli.
DATA: gr_table  TYPE REF TO   cl_salv_table.

*&---------------------------------------------------------------------*
*& Start-of-Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  SELECT * UP TO 10 ROWS FROM spfli INTO TABLE gt_spfli.

*Generate an instance of the ALV table object
  CALL METHOD cl_salv_table=>factory
    EXPORTING
      list_display = if_salv_c_bool_sap=>true
    IMPORTING
      r_salv_table = gr_table
    CHANGING
      t_table      = gt_spfli.

*Display the ALV table.
  gr_table->display( ).

Output

sap-alv-object-model-display-table-2

Following are the restrictions with CL_SALV_TABLE (ALV Object Model)

  • The number of columns is restricted to 90.
  • The output length of a column is restricted to 128 characters.
  • For sorting and subtotals, you use a total of nine levels or columns.
  • For columns that can be aggregated, note that the internal length of the column is large enough for both single values and the result.
  • The output is column-oriented. You are only able to display flat, structured tables. You are not able to display nested tables.
  • Tables displayed with ALV are not ready for input.
  • If you insert the table as grid in container, you are not able to use batch mode.