In order to fill icons in ALV Table, we must add an additional field of type ICON_D. The type ICON_D is of datatype CHAR with length 4. This is later filled with the icon code.
Step1: Define the icon field
TYPE-POOLS: icon.
TYPES: BEGIN OF ty_contact.
INCLUDE STRUCTURE ztt_db_table2.
TYPES: icon_field TYPE icon_d,
END OF ty_contact.
Step2: Fill the internal table with data contents.
DATA lt_contact TYPE TABLE OF ty_contact.
SELECT * FROM ztt_db_table2 INTO TABLE lt_contact.
It is used just as a display of checkbox. It mentions that the particular line of record is selected.
It can be used to trigger an event of type LINK_CLICK.
The value of the checkbox cannot be changed.
The value of checkbox can be changed.
It is not used to manipulate the values of the fields of ALV Table.
It can be used to manipulate the values of the fields of ALV Table. The ALV Table must be refreshed with the refresh method call {lr_alv_grid -> REFRESH ()}.
The various cell types can be used both in container mode and complete mode. The cell types are constructed based on the Attribute of the Interface ‘IF_SALV_C_CELL_TYPE’.
Type of cell
Attribute of IF_SALV_C_CELL_TYPE
Display mode container / complete
Event
Text
=> Text
Both
–
Checkbox
=> Checkbox
Both
–
Checkbox hotspot
=> checkbox_hotspot
Both
link_click
Button
=> Button
Both
link_click
Dropdown
=> dropdown
Container
Hotspot
=> Hotspot
Both
link_click
The method set_cell_type of the column object ( cl_salv_column_table ) can be used to set the cell type for the cells in the ALV Display.
DATA lr_all_columns TYPE REF TO cl_salv_columns_table.
DATA lr_single_column TYPE REF TO cl_salv_column_table.
The columns can be renamed with the object of the class cl_salv_column_table. There are four methods available such as SET_SHORT_TEXT (), SET_MEDIUM_TEXT(), SET_LONG_TEXT and SET_TOOLTIP(). The method can be chosen based on our requirement of text length.
DATA lr_salv_columns_table TYPE REF TO cl_salv_columns_table.
DATA lr_salv_column_table TYPE REF TO cl_salv_column_table.
If you wish to force the ABAP execution to use the short text instead of other texts, then there is an easy way to achieve this. Just ignore assigning the medium and long text, then it automatically considers the short text. The other two text formats are ignored by default.
The column is inserted through the field catalog of the ALV Table. It is set during the method call FACTORY ().
Step1: Extend the structure either locally or globally through the Transaction SE11 with the additional field.
TYPES: BEGIN OF ty_contact.
INCLUDE STRUCTURE ztt_db_table2.
TYPES: contact_age TYPE ZDE_contact_age.
END OF ty_contact.
DATA lt_contact TYPE STANDARD TABLE OF ty_contact.
It is always recommended to use an unique Data element for the fields of the structure, so that the column heading text can be easily maintained.
Step2: Call the Factory() Method of class CL_SALV_TABLE
CALL METHOD cl_salv_table => factory
IMPORTING
r_salv_table = lr_alv_object
CHANGING
t_table = lt_contact.
Through the field catalog of the ALV Table, a new column can be inserted or deleted.
There is a method REMOVE_COLUMN() for the column class ‘CL_SALV_COLUMN_TABLE’. But it is protected. Therefore the inheritance is needed to remove the column.
By default, the function toolbar is not displayed in the new ALV Display. It must be activated. The functions object is retrieved from the ALV Object. In order to activate the complete function toolbar, the set_all( ) method of the function object must be called.
DATA lr_functions_list TYPE REF TO cl_salv_functions_list.
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.
Fill an Internal table with the Details.
Create an object of class CL_SALV_Table through FACTORY( ) method.
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.
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.