前言
在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_GETDATA
FORM 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 =
CHANGING
ct_fieldcat = gt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH 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_CATALOG
FORM f_alvshow .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fieldcat[]
TABLES
t_outtab = gt_data[].
ENDFORM. " F_ALVSHOW