It is the only ALV variant which is editable. We need an internal table which is based on a global structure to show the data.
There are two Display modes to display the data.
- Full screen display : The output of the ALV List occupies the whole screen. It does not contain Container and Dynpro.
- Container mode: It needs a Dynpro and a container.
ALV Table is built based on the following steps
- Loading the data in the internal table
- Creation of Containers. This step is optional.
- Assign the structure of the internal table to the Field catalog. This step is also optional.
- Creation of ALV Object.
- Definition of layout. This step is optional.
- Display ALV Table contents.
- Loading data in an internal table: The data from the database table are loaded in to the internal table.
DATA lt_contact TYPE TABLE OF ztt_db_table2.
SELECT * FROM ztt_db_table2 INTO TABLE lt_contact UP TO 50 ROWS.
Container object is created with an unique ID. It is used for the created Dynpro. This is mainly used to show the ALV List in a particular area of the screen. If the display is not a requirement, then you can opt for the full screen display and skip this step. But it is necessary to provide the parameter cl_gui_custom_container=>default_screen in the constructor during the creation of the ALV List.
DATA lr_container TYPE REF TO cl_gui_custom_container.
CREATE OBJECT lr_container
EXPORTING
container_name = ‘container_id’.
- Assignment of Structure to Field catalog
The structure of the internal table is assigned to the field catalog. It includes important elements such as column heading, Display size, Data type of the column. It is always recommended to use the global structure created from Transaction SE11.
DATA lt_field_cat TYPE lvc_t_fcat.
CALL FUNCTION ‘LVC_FIELDCATALOG_MERGE’
EXPORTING
i_structure_name = ‘ZTT_DB_TABLE2’
CHANGING
ct_fieldcat = lt_field_cat.
Note: This step can be skipped , if you would not like to modify the columns in the display. But the parameter i_structure_name must be specified during the call of the method SET_TABLE_FOR_FIRST_DISPLAY of the ALV Object. The field catalog is automatically assigned in the ALV.
An object is created for the class CL_GUI_ALV_GRID. Assign the created container object in the parameter of the constructor. For the full screen display, instead of the container object, cl_gui_custom_container=>default_screen is assigned to the parameter.
DATA lr_gui_alv_grid TYPE REF TO cl_gui_alv_grid.
CREATE OBJECT lr_gui_alv_grid
EXPORTING i_parent = lr_container.
The layout of the ALV Table can be changed further using this option. The various fields of the layout structure is used to design the layout of the ALV table in different formats.
DATA ls_struc_layout TYPE lvc_s_layo.
ls_struc_layout-no_toolbar = abap_true.
If this field is set, then the ALV Grid Toolbar is hidden. There are also other fields such as GRID_TITLE which displays the title on the ALV Grid.
The SET_TABLE_FOR_FIRST_DISPLAY( ) method of the ALV object is called in the final step. The layout structure is given as the exporting parameter, the internal table and field catalog is specified as the changing parameter. After this method call, the Dynpro is called using the command CALL SCREEN.
CALL METHOD lr_gui_alv_grid->set_table_for_first_display
EXPORTING
is_layout = ls_struc_layout
CHANGING
it_outtab = lt_contact
it_fieldcatalog = lt_field_cat.
CALL SCREEN 1000.