本文介绍红绿灯的效果:
REPORT ZLM_ALV01.
TYPE-POOLS: SLIS, ICON.
DATA:BEGIN OF STR_DATA,
STATUS LIKE ICON-NAME,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID,
FLDATE LIKE SFLIGHT-FLDATE,
PRICE LIKE SFLIGHT-PRICE,
CURRENCY LIKE SFLIGHT-CURRENCY,
END OF STR_DATA.
DATA: GT_DATA LIKE TABLE OF STR_DATA,
GS_DATA LIKE STR_DATA.
FIELD-SYMBOLS <GS_DATA> LIKE STR_DATA.
DATA:GS_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA:GT_FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV .
START-OF-SELECTION.
SELECT * FROM SFLIGHT INTO CORRESPONDING FIELDS OF TABLE GT_DATA.
LOOP AT GT_DATA ASSIGNING <GS_DATA>.
IF <GS_DATA>-PRICE <= 185 .
<GS_DATA>-STATUS = ICON_LED_GREEN.
ELSEIF <GS_DATA>-PRICE <= 250 .
<GS_DATA>-STATUS = ICON_LED_RED.
ENDIF.
ENDLOOP.
CLEAR GT_FIELDCATALOG[].
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = 'STR_DATA'
I_INCLNAME = SY-REPID
CHANGING
CT_FIELDCAT = GT_FIELDCATALOG
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
IF GT_FIELDCATALOG[] IS INITIAL.
RETURN.
ENDIF.
FIELD-SYMBOLS <LS_FILEDCAT> LIKE LINE OF GT_FIELDCATALOG.
LOOP AT GT_FIELDCATALOG ASSIGNING <LS_FILEDCAT>.
<LS_FILEDCAT>-DDICTXT ='L'.
IF <LS_FILEDCAT>-FIELDNAME = 'STATUS'.
<LS_FILEDCAT>-SELTEXT_L = '红绿灯'.
<LS_FILEDCAT>-SELTEXT_M = '红绿灯'.
<LS_FILEDCAT>-SELTEXT_S = '红绿灯'.
ENDIF.
<LS_FILEDCAT>-JUST = 'R'.
ENDLOOP.
GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GS_LAYOUT-ZEBRA = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_GRID_TITLE = 'SAP干货铺测试'
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = GT_FIELDCATALOG
TABLES
T_OUTTAB = GT_DATA
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.