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.