TYPE-POOLS: slis. " SLIS contains all the ALV data types *&---------------------------------------------------------------------* *& Data Types *&---------------------------------------------------------------------* TYPES: BEGINOF ty_sbook. INCLUDESTRUCTURE sbook. TYPES: iconTYPEc, " Add field to hold traffic light value ENDOF ty_sbook. *&---------------------------------------------------------------------* *& Data Declaration *&---------------------------------------------------------------------* DATA: it_sbook TYPETABLEOF ty_sbook. DATA: wa_sbook TYPE ty_sbook. DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv. DATA: is_layout TYPE slis_layout_alv. DATA: g_repid TYPE sy-repid. *&---------------------------------------------------------------------* *& START-OF-SELECTION *&---------------------------------------------------------------------*
START-OF-SELECTION.
g_repid = sy-repid. *Fetch data from the database SELECT * UPTO20ROWSFROM sbook INTOTABLE it_sbook.
*Assign different traffic lights to each row based on condition LOOPAT it_sbook INTO wa_sbook. IF wa_sbook-luggweight LE0.
wa_sbook-icon = 1. " Red Traffic Light ELSEIF wa_sbook-luggweight LE10.
wa_sbook-icon = 2. " Yellow Traffic Light ELSE.
wa_sbook-icon = 3. " Green Traffic Light ENDIF. MODIFY it_sbook FROM wa_sbook TRANSPORTINGicon. CLEAR: wa_sbook. ENDLOOP.
*Build field catalog
wa_fieldcat-fieldname = 'CARRID'. " Fieldname in the data table
wa_fieldcat-seltext_m = 'Airline'. " Column description in the output APPEND wa_fieldcat TO it_fieldcat. CLEAR wa_fieldcat.
*Fill layout info. *Fill traffic lights field name in the ALV layout
is_layout-lights_fieldname = 'ICON'.
*Pass data and field catalog to ALV function module to display ALV list CALLFUNCTION'REUSE_ALV_GRID_DISPLAY' EXPORTING
i_callback_program = g_repid
is_layout = is_layout
it_fieldcat = it_fieldcat TABLES
t_outtab = it_sbook EXCEPTIONS
program_error = 1 OTHERS = 2.
Serkan AKKAVAK Computer Engineer ABAP Developer & SAP S/4 HANA Logistics Team Lead Contact : serkurumsal@yandex.com
Social Plugin