DATA:gs_layout TYPE slis_layout_alv.
FORM build_layout .
gs_layout-zebra = 'X'. "斑马纹输出
gs_layout-colwidth_optimize = 'X'."优化列宽
gs_layout-box_fieldname = 'BOX'. "选择框的字段,需要在内表增加BOX字段
"详细清单属性
gs_layout-detail_popup = 'X'. "popup对话框
gs_layout-detail_initial_lines = 'X'. "是否显示值为空的字段
gs_layout-detail_titlebar = '详细列表'. "对话框标题
"表单属性
gs_layout-window_titlebar = '窗体抬头'.
gs_layout-confirmation_prompt = 'X'. "退出时弹出确认对话框
ENDFORM.
Sort表为一个内表,将需要排序的字段信息增加到sort表中,在ALV输出按照顺序排序
DATA:gt_sort TYPE slis_t_sortinfo_alv,
gs_sort TYPE slis_sortinfo_alv.
FORM build_sort .
CLEAR gs_sort.
gs_sort-fieldname = 'EBELN'.
gs_sort-spos = '1'. "排序的先后顺序设置
gs_sort-down = 'X'.
APPEND gs_sort TO gt_sort.
CLEAR gs_sort.
gs_sort-fieldname = 'EBELP'.
gs_sort-spos = '2'. "排序的先后顺序设置
gs_sort-up = 'X'.
APPEND gs_sort TO gt_sort.
ENDFORM.
Z_TEST_01FORM
FORM pf_status_set USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'PF_STATUS'.
ENDFORM.
Z_TEST_01TOP
DATA:gt_event TYPE slis_t_event,
gs_event TYPE slis_alv_event.
Z_TEST_01FORM
FORM build_event .
CLEAR gs_event.
gs_event-name = 'PF_STATUS_SET'.
gs_event-form = 'SET_STATUS'.
APPEND gs_event TO gt_event.
ENDFORM.
FORM build_alv .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
it_sort = gt_sort
is_layout = gs_layout
it_fieldcat = gt_fieldcat
it_events = gt_event
TABLES
t_outtab = gty_ekpo.
ENDFORM.
Z_TEST_01FORM p_ucomm:点击事件的功能代码 p_field:点击位置信息光标
FORM user_command USING p_ucomm TYPE sy-ucomm
p_field TYPE slis_selfield.
CASE p_ucomm.
WHEN '&IC1'.
READ TABLE gty_ekpo INDEX p_field-tabindex.
PERFORM display_mm_data USING gty_ekpo-ebeln.
WHEN OTHERS.
ENDCASE.
ENDFORM.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_user_command = 'USER_COMMAND' "功能代码处理
it_sort = gt_sort
is_layout = gs_layout
it_fieldcat = gt_fieldcat
it_events = gt_event
TABLES
t_outtab = gty_ekpo.
Z_TEST_01FORM
FORM TOP_OF_PAGE.
DATA:LT_LISTHEADER TYPE SLIS_T_LISTHEADER .
DATA:LS_LISTHEADER TYPE SLIS_LISTHEADER .
LS_LISTHEADER-TYP = 'H'.
LS_LISTHEADER-INFO = '表头描述文本'.
APPEND LS_LISTHEADER TO LT_LISTHEADER.
LS_LISTHEADER-TYP = 'S'.
LS_LISTHEADER-KEY = '字段KEY'.
LS_LISTHEADER-INFO = '字段VALUE'.
APPEND LS_LISTHEADER TO LT_LISTHEADER.
LS_LISTHEADER-TYP = 'A'.
LS_LISTHEADER-INFO = '结尾斜体'.
APPEND LS_LISTHEADER TO LT_LISTHEADER.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = LT_LISTHEADER.
ENDFORM.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE' "增加表头
IT_SORT = GT_SORT
IS_LAYOUT = GS_LAYOUT
IT_FIELDCAT = GT_FIELDCAT
IT_EVENTS = GT_EVENT
TABLES
T_OUTTAB = GTY_EKPO.
颜色值的设置:C+X(颜色)X(背景色/文字颜色:1/0)X(是否反色1/0)
对FIELDCAT-EMPHASIZE赋值颜色
1、在内表中增加一个字段,CHAR类型,长度为4,例:COLOR字段 2、在获取数据时,对颜色字段进行赋值,例:GTY_EKPO-COLOR = ‘C411’. 3、设置layout,将INFO_FIELDNAME字段,赋值为内表中颜色字段名称
在内表中增加一个字段,LVC_T_SCOL类型内表,例:COLOR字段 在获取数据时,对颜色内表进行赋值, FNAME:字段名;COLOR颜色字段三个数字; NOKEYCOL是否覆盖关键字颜色 设置layout,将COLTAB_FIELDNAME字段,赋值为内表中颜色字段名称
CLEAR LS_SCOL.
LS_SCOL-FNAME = 'EBELP'.
LS_SCOL-COLOR-COL = 6.
LS_SCOL-COLOR-INT = 0.
LS_SCOL-COLOR-INV = 0.
APPEND LS_SCOL TO GTY_EKPO-COLOR.
GS_LAYOUT-COLTAB_FIELDNAME = 'COLOR'.