In the context of SAP ALV (ABAP List Viewer), a traffic light system is a visual representation used to indicate the status of certain data points. Typically, it uses color-coded indicators similar to traffic lights (red, yellow, green) to convey different states or conditions of the data. The traffic light system is used to quickly convey information at a glance, making it easier for users to understand the status of data without having to analyze detailed numbers or descriptions.
Steps
1. ALV needs to be displayed using FM ''REUSE_ALV_GRID_DISPLAY"2. One field needs to be included to hold traffic light value in the internal table structure (type C length 1). Value 1 will be assigned for red light, 2 will be assigned for yellow light and 3 will be assigned for green light.
Example:
***If the field is defined as ICON and included in internal table structure
***For condition 1:
ICON = 1. "Red Traffic Light
***For condition 2:
ICON = 2. "Yellow Traffic Light
***For condition 3:
ICON = 3. "Green Traffic Light
3. One work area needs to be defined using 'SLIS_LAYOUT_ALV' structure.
Example:
DATA: wa_layout TYPE SLIS_LAYOUT_ALV.
4. Now assign the internal table structure field (ICON) into layout work area (wa_layout) field "LIGHTS_FIELDNAME"
Example:
wa_layout-lights_fieldname = 'ICON'.
5. Assign exporting parameters of the FM "IS_LAYOUT" as wa_layout.
Example:
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = wa_layout
Code Example:
TYPE-POOLS: slis. " SLIS contains all the ALV data types *&---------------------------------------------------------------------* *& Data Types *&---------------------------------------------------------------------* TYPES: BEGIN OF ty_sbook. INCLUDE STRUCTURE sbook. TYPES: icon TYPE c, " Add field to hold traffic light value END OF ty_sbook. *&---------------------------------------------------------------------* *& Data Declaration *&---------------------------------------------------------------------* DATA: it_sbook TYPE TABLE OF 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 * UP TO 20 ROWS FROM sbook INTO TABLE it_sbook. *Assign different traffic lights to each row based on condition LOOP AT it_sbook INTO wa_sbook. IF wa_sbook-luggweight LE 0. wa_sbook-icon = 1. " Red Traffic Light ELSEIF wa_sbook-luggweight LE 10. wa_sbook-icon = 2. " Yellow Traffic Light ELSE. wa_sbook-icon = 3. " Green Traffic Light ENDIF. MODIFY it_sbook FROM wa_sbook TRANSPORTING icon. 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. wa_fieldcat-fieldname = 'CONNID'. wa_fieldcat-seltext_m = 'Con. No.'. APPEND wa_fieldcat TO it_fieldcat. CLEAR wa_fieldcat. wa_fieldcat-fieldname = 'FLDATE'. wa_fieldcat-seltext_m = 'Date'. APPEND wa_fieldcat TO it_fieldcat. CLEAR wa_fieldcat. wa_fieldcat-fieldname = 'BOOKID'. wa_fieldcat-seltext_m = 'Book. ID'. APPEND wa_fieldcat TO it_fieldcat. CLEAR wa_fieldcat. wa_fieldcat-fieldname = 'FORCURAM'. wa_fieldcat-seltext_m = 'Price'. APPEND wa_fieldcat TO it_fieldcat. CLEAR wa_fieldcat. wa_fieldcat-fieldname = 'FORCURKEY'. wa_fieldcat-seltext_m = 'Currency'. APPEND wa_fieldcat TO it_fieldcat. CLEAR wa_fieldcat. wa_fieldcat-fieldname = 'LUGGWEIGHT'. wa_fieldcat-seltext_m = 'Weight'. APPEND wa_fieldcat TO it_fieldcat. CLEAR wa_fieldcat. wa_fieldcat-fieldname = 'WUNIT'. wa_fieldcat-seltext_m = 'Unit'. 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 CALL FUNCTION '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.
Comments
Post a Comment