1、 类型池:SLIS
2、Fieldcat TYPE slis_t_fieldcat_alv
3、 Layout TYPE slis_layout_alv
4、函数:REUSE_ALV_FIELDCDATALOG_MERGE
5、函数:REUSE_ALV_GRID_DISPLAY / REUSE_ALV_LIST_DISPLAY
1、关键字解释:
2、START-OF-SELECTION
3、END-OF-SELECTION
字段 | 说明 |
---|---|
KEY | 将列设置为关键字(‘X’/’’) |
ICON | 以图标显示(‘X’/’’) |
CHECKBOX | 以复选框显示(‘X’/’’) |
JUST | 定义对齐方式(‘X’/’’) |
IZERO | 增加前导零(‘X’/’’) |
NO_SIGN | 不显示符号(‘X’/’’) |
NO_ZERO | 不显示前导零(‘X’/’’) |
COL_POS | 作为第几列输出(数字) |
DO_SUM | 对字段进行汇总(‘X’/’’) |
SELTEXT_L/M/S | 字段名称描述长/中/短(字符串) |
HOTSPOT | 设置为热点(显示为有下划线)(‘X’/’’) |
REPORT z_test_01.
INCLUDE z_test_01top. "存放变量
INCLUDE z_test_01form. “存放子历程
START-OF-SELECTION.
PERFORM get_data. “获取数据
END-OF-SELECTION.
IF gty_ekpo[] IS NOT INITIAL.
PERFORM write_data. “展示数据
ENDIF.
TYPE-POOLS slis . "类型池
DATA:gt_fieldcat TYPE slis_t_fieldcat_alv, "fieldcat内表
gs_fieldcat TYPE slis_fieldcat_alv. "fieldcat结构
DATA:BEGIN OF gty_ekpo OCCURS 0 . “输出的内表
INCLUDE STRUCTURE ekpo.
DATA: icon TYPE char4.
DATA:END OF gty_ekpo.
*&---------------------------------------------------------------------*
*& 包含 Z_TEST_01FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM get_data .
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gty_ekpo
FROM ekpo UP TO 20 ROWS ORDER BY ebeln.
LOOP AT gty_ekpo.
gty_ekpo-icon = ICON_GREEN_LIGHT.
MODIFY gty_ekpo.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form WRITE_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM write_data .
PERFORM build_fieldcat.
PERFORM build_alv.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM build_fieldcat .
CLEAR gt_fieldcat[].
PERFORM add_fieldcat USING 'ICON' 'ICON' '1' '10' ''.
PERFORM add_fieldcat USING 'EBELN' '采购凭证' '1' '10' ''.
PERFORM add_fieldcat USING 'EBELP' '项目' '1' '10' ''.
PERFORM add_fieldcat USING 'MENGE' '采购订单数量' '1' '10' 'X'.
ENDFORM.
FORM add_fieldcat USING p_fieldname
p_seltext
p_col
p_len
p_sum.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = p_fieldname.
gs_fieldcat-seltext_m = p_seltext.
gs_fieldcat-col_pos = p_col.
gs_fieldcat-outputlen = p_len.
gs_fieldcat-do_sum = p_sum.
APPEND gs_fieldcat TO gt_fieldcat.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form BUILD_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM build_alv .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = gt_fieldcat
TABLES
t_outtab = gty_ekpo.
ENDFORM.