How to create a SAP ALV Display using the class CL_SALV_TABLE

The new ALV Display model based on the class CL_SALV_TABLE provides various functionalities similar to the old ALV Display. But the data fields of the ALV Table are not directly editable.

There are two Display modes for the new SAP ALV Display based on class CL_SALV_TABLE.

Full Screen mode: There is no need of container and Dynpro.

Container mode: It is created through the Dynpro and container.

Full Screen mode: The following steps are necessary to construct an SAP ALV Display based on the class CL_SALV_TABLE.

  1. Fill an Internal table with the Details.
  2. Create an object of class CL_SALV_Table through FACTORY( ) method.
  3. Display ALV.
  • Loading Internal Table

DATA lt_contact TYPE TABLE OF ztt_db_table2.

SELECT * FROM ztt_db_table2 INTO TABLE lt_contact.

  • Creation of object of type CL_SALV_TABLE

The static method ‘FACTORY’ of the class CL_SALV_TABLE returns the object of class CL_SALV_TABLE as an exporting parameter. This is the instance of the ALV object.

DATA lr_salv_table TYPE REF TO cl_salv_table.

CALL METHOD cl_salv_table => factory

              IMPORTING

                            r_salv_table = lr_salv_table

              CHANGING

                            t_table = lt_contact.

  • ALV Display

Finally the ALV List is displayed by calling the Display method of the ALV object.

lr_salv_table -> Display ().

Container mode :

              In order to display the ALV list in container mode, you need a Dynpro with a container.

The following steps are written to Display the ALV.

  1. Creation of container object.

DATA lr_container TYPE REF TO cl_gui_custom_container.

CREATE OBJECT lr_container

              EXPORTING

                            Container_name = ‘SALV_CONTAINER’.

  • Creation of ALV object.

In this mode as well, the static method ‘FACTORY’ of the class cl_salv_table is used to create the ALV object. The container object is given as an exporting parameter in the method call. The Internal table with the ALV contents is specified in the changing parameter.

              DATA lr_salv_table TYPE REF TO cl_salv_table.

              CALL METHOD cl_salv_table => factory

                            EXPORTING

                                          r_container = lr_container

                            IMPORTING

                                          r_salv_table = lr_salv_table

                            CHANGING

                                          t_table = lt_contact.

  • Display the ALV List.

lr_salv_table -> display ().

CALL SCREEN 1000.