How to fill icons in SAP ALV Display of type CL_SALV_TABLE

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.

Step3: Fill the internal table with icon code.

FIELD-SYMBOLS <ls_contact> TYPE ty_contact.

LOOP AT lt_contact ASSIGNING <ls_contact>.

               <ls_contact>-icon = icon_positive.

ENDLOOP.

How to display icon in SAP ALV cell

There are three important steps involved in displaying icon in the ALV cell.

  1. Extension of Internal table with the additional field ICON_D.
  2. Filling the icon field to the records of ALV table.
  3. Assignment of field ‘ICON’ to field catalog.
  • Extension of Internal table with field ICON_D.

TYPES: BEGIN OF ty_contact.

                            INCLUDE STRUCTURE ztt_db_table2.

                            TYPES: icon TYPE icon_d,

              END OF ty_contact.

  • Filling the icon field to the records of ALV table.

FIELD_SYMBOLS <ls_contact> TYPE ty_contact.

DATA lt_contact TYPE TABLE OF ty_contact.

SELECT * FROM ztt_db_table2 INTO CORRESPONDING FIELDS OF TABLE lt_contact.

LOOP AT lt_contact ASSIGNING <ls_contact>.

              <ls_contact>-icon = ICON_YELLOW_LIGHT.

ENDLOOP.

Through the transaction ‘ICON’, you can find the list of all available icons. The corresponding symbol of the icon is also displayed in the list.

If any message needs to be displayed with this icon, it must be referred to the Type group ‘ICON’ with the statement TYPE-POOLS: icon.

  • Assignment of field ‘icon’ to field catalog.

DATA ls_field_cat TYPE lvc_s_fcat.

ls_field_cat-fieldname = ‘ICON’.

ls_field_cat-icon = ‘X’.

ls_field_cat-outputlen = 3.

APPEND ls_field_cat TO lt_field_cat.