前言
在ABAP ALV中,使用fieldcat
来定义列表中每个字段的显示属性,包括图标(Icon)的显示。图标可以在ALV列表中为特定列的行或标题添加图形元素,以增强视觉提示或传达附加信息。
ICON查询
图标的名称用事务码”ICON“进入后,第二列就是图标代码,可根据需要进行选择。
实战
展示效果
完整代码
DATA:BEGIN OF gs_spfli .INCLUDE TYPE spfli.
DATA icon_folder(4) TYPE c.
DATA
END OF gs_spfli.DATA: gt_fieldcat TYPE TABLE OF lvc_s_fcat WITH HEADER LINE,gs_layout TYPE lvc_s_layo.DATA: gt_data LIKE TABLE OF gs_spfli WITH HEADER LINE.DATA: gs_style TYPE lvc_s_styl,gt_style TYPE lvc_t_styl.START-OF-SELECTION.PERFORM f_getdata.PERFORM f_catalog.PERFORM f_alvshow.FORM f_getdata .SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_data FROM spfli.LOOP AT gt_data.IF gt_data-carrid = 'AA'.IF gt_data-carrid = 'AA'.gt_data-icon_folder = ICON_CHECKED.ELSE.gt_data-icon_folder = ICON_INCOMPLETE.ENDIF.MODIFY gt_data.ENDLOOP.
ENDFORM. " F_GETDATAFORM f_catalog .CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'EXPORTING
* I_BUFFER_ACTIVE =i_structure_name = 'SPFLI'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =CHANGINGct_fieldcat = gt_fieldcat[]EXCEPTIONSinconsistent_interface = 1program_error = 2OTHERS = 3.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.CLEAR gt_fieldcat.gt_fieldcat-fieldname = 'ICON_FOLDER'.gt_fieldcat-scrtext_l = 'ICON' .gt_fieldcat-icon = 'X' . "启用图标APPEND gt_fieldcat.*对layout设置可编辑信息内表gs_layout-zebra = 'X'.gs_layout-cwidth_opt = 'X'.
ENDFORM. " F_CATALOGFORM f_alvshow .CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'EXPORTINGi_callback_program = sy-repidis_layout_lvc = gs_layoutit_fieldcat_lvc = gt_fieldcat[]TABLESt_outtab = gt_data[].
ENDFORM. " F_ALVSHOW