Display Traffic lights ALV
* If student id < 5 display red color.
* If student id = 5 display yellow color.
* If student id > 5 display green color.
Report program
REPORT YRP_ALV_TRAFIC_LIGHTS.
TABLES: ZST_DET.
TYPES: BEGIN OF TY_STU,
ZST_ID TYPE ZST_DET-ZST_ID,
ZST_NAME TYPE ZST_DET-ZST_NAME,
ZST_DEPT TYPE ZST_DET-ZST_DEPT,
ZST_FEE TYPE ZST_DET-ZST_FEE,
ICON TYPE C,
END OF TY_STU.
DATA: IT_STU TYPE TABLE OF TY_STU,
WA_STU TYPE TY_STU,
WA_fieldcat TYPE slis_fieldcat_alv,
it_fieldcat TYPE slis_t_fieldcat_alv,
is_layout TYPE slis_layout_alv.
SELECT-OPTIONS : S_ID FOR ZST_DET-ZST_ID.
IF S_ID IS INITIAL.
MESSAGE 'PLEASE GIVE STUDENT ID' TYPE 'W'.
ELSE.
SELECT ZST_ID
ZST_NAME
ZST_DEPT
ZST_FEE
FROM ZST_DET
INTO TABLE IT_STU
WHERE ZST_ID IN S_ID.
ENDIF.
" 1 -RED 2 -YELLOW 3-GREEN
LOOP AT IT_STU INTO WA_STU.
IF WA_STU-ZST_ID < 5.
WA_STU-ICON = 1.
ELSEIF WA_STU-ZST_ID = 5.
WA_STU-ICON = 2.
ELSEIF WA_STU-ZST_ID > 5.
WA_STU-ICON = 3.
ENDIF.
ENDLOOP.
wa_fieldcat-fieldname = 'ZST_ID'.
wa_fieldcat-seltext_m = 'STU ID'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ZST_NAME'.
wa_fieldcat-seltext_m = 'STU NAME'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ZST_DEPT'.
wa_fieldcat-seltext_m = 'STU DEPT'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'ZST_FEE'.
wa_fieldcat-seltext_m = 'STU FEE'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
IS_LAYOUT-LIGHTS_FIELDNAME = 'ICON'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IS_LAYOUT = IS_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
TABLES
T_OUTTAB = IT_STU
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
Input
Output
Comments
Post a Comment