*&---------------------------------------------------------------------*
*& Report ZMMD0006_TEST_DL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zmmd0006_test_dl.
*---ALV学习01---*
*Function方式的ALV*
TABLES :sscrfields,ztmm0045,marc."引用数据表
*---第一步:声明ALV相关变量---*
TYPE-POOLS:slis.
DATA: lt_fieldcat_alv TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv, "列栏位属性
ls_layout TYPE slis_layout_alv, "布局属性
lt_event TYPE slis_t_event, "定义事件属性
wa_event TYPE slis_alv_event,
lt_sort TYPE slis_t_sortinfo_alv,"定义排序属性
wa_sort TYPE slis_sortinfo_alv.
DATA lt_col_pos TYPE int2. "定义列号。
*DATA:gt_fieldcat TYPE lvc_t_fcat,
* gs_layout TYPE lvc_s_layo,
* gs_fieldcat TYPE lvc_s_fcat.
*---第二步:定义内表---*
DATA:BEGIN OF zmmd0006_alv OCCURS 0,"定义一个代表头的内表
mandt TYPE marc-mandt, "集团
werks TYPE marc-werks, "工厂
matnr TYPE marc-matnr, "料号
zzhs_code TYPE marc-zzhs_code, "HScode
zzsppm TYPE marc-zzsppm, "商品品名
mc_zzbaxh TYPE marc-zzbaxh, "物料备案序号
zzbaxh TYPE ztmm0045-zzbaxh, "备案序号
END OF zmmd0006_alv.
DATA:gt_alv LIKE TABLE OF zmmd0006_alv WITH HEADER LINE."参考内表再定义一个内表
"BREAK-POINT."断点-内表
*---第三步:读取数据---*
SELECT
"m~mandt m~werks m~matnr m~zzhs_code m~zzsppm m~zzbaxh AS mc_zzbaxh z~zzbaxh"旧SQL不加逗号。
m~mandt,m~werks,m~matnr,m~zzhs_code,m~zzsppm,m~zzbaxh AS mc_zzbaxh,z~zzbaxh
FROM ztmm0045 AS z INNER JOIN marc AS m
ON z~zzhs_code = m~zzhs_code AND z~zzsppm = m~zzsppm
INTO TABLE @DATA(ls_alv)."gt_alv."旧SQL不用加@,新SQL功能更强大
"GROUP BY z~zzhs_code, z~zzsppm.
*BREAK-POINT."断点-数据
*---第四步:格式控制,布局结构---*
"layout*
ls_layout-zebra = 'X'."ALV 控制: 可选行颜色 (带)-呈现颜色交替斑马纹
ls_layout-f2code = '&ETA'."设置触发弹出详细信息窗口的功能码,这里是双击
ls_layout-colwidth_optimize = 'X'."优化列宽选项是否设置
ls_layout-detail_titlebar = '详细内容'."设置弹出窗口的标题栏
* ls_layout-edit = 'X'."是否为可编辑模式
* ls_layout-detail_popup = 'X'."是否弹出详细信息窗口
* ls_layout-no_vline = 'X'."这个用来设置列间隔线
* ls_layout-detail_initial_lines = 'X'."是否出现细节屏幕
* ls_layout-edit_mode = 'X'.
* ls_layout-totals_only = 'X'.
* gs_layout-excp_conds = 'X'.
* gs_layout-zebra = 'X'."ALV 控制: 可选行颜色 (带)-呈现颜色交替斑马纹
* gs_layout-cwidth_opt = 'X'."' '."优化列管-X&空格
* gs_layout-sel_mode = 'A'."总计
* gs_layout-detail_popup = 'X'."是否弹出详细信息窗口
* gs_layout-f2code = '&ETA'."设置触发弹出详细信息窗口的功能码,这里是双击
* gs_layout-no_vline = 'X'."这个用来设置列间隔线
* gs_layout-colwidth_optimize = 'X'."优化列宽选项是否设置
* gs_layout-detail_initial_lines = 'X'."是否出现细节屏幕
* gs_layout-detail_titlebar = '详细内容'."设置弹出窗口的标题栏
*fieldcat*
* it_col_pos = 1."初始为1
* wa_fieldcat-fieldname = 'mandt'.
* wa_fieldcat-col_pos = lt_col_pos.
* wa_fieldcat-key = 'X'.
* "wa_fieldcat-datatype = ''.
* "wa_fieldcat-outputlen = ''.
* wa_fieldcat-seltext_m = '集团'.
* APPEND wa_fieldcat TO lt_fieldcat.
DEFINE mcr_set_fieldcat."定义宏-fieldcat
wa_fieldcat-fieldname = &1. "字段名称
wa_fieldcat-seltext_m = &2. "字段文本
wa_fieldcat-key = &3.
wa_fieldcat-edit = &4. "可编辑状态
wa_fieldcat-lowercase = 'X'. "文本小写
wa_fieldcat-just = &5. "对齐方式
wa_fieldcat-checkbox = &6. "设置是否选择框
IF wa_fieldcat-outputlen IS INITIAL. "当coltext不存在显示filedtext,如字段没域,只有手工描述的情况
wa_fieldcat-outputlen = 80.
ENDIF.
APPEND wa_fieldcat TO lt_fieldcat_alv.
END-OF-DEFINITION.
*DEFINE mcr_set_fieldcat."定义宏-fieldcat
* gs_fieldcat-fieldname = &1. "字段名称
* gs_fieldcat-seltext = &2. "字段文本
* gs_fieldcat-key = &3.
* gs_fieldcat-edit = &4. "可编辑状态
* gs_fieldcat-lowercase = 'X'. "文本小写
* gs_fieldcat-just = &5. "对齐方式
* gs_fieldcat-checkbox = &6. "设置是否选择框
* IF gs_fieldcat-outputlen IS INITIAL. "当coltext不存在显示filedtext,如字段没域,只有手工描述的情况
* gs_fieldcat-outputlen = 80.
* ENDIF.
* APPEND gs_fieldcat TO gt_fieldcat.
*END-OF-DEFINITION.
* mcr_set_fieldcat:'msg_text' '消息'(m30) '' 'L' ''.
mcr_set_fieldcat:"插入宏-fieldcat
*'sel' '选择'(m00) 'X' 'L' 'X',
'MANDT' '集团'(m01) 'X' '' 'L' '',
'WERKS' '工厂'(m02) 'X' '' 'L' '',
'MATNR' '料号'(m03) 'X' '' 'L' '',
'ZZHS_CODE' '哈希编号'(m04) '' '' 'L' '',
'ZZSPPM' '商品品名'(m05) '' '' 'L' '',
'MC_ZZBAXH' '物料备案序号'(m06) '' 'X' 'L' '',
'ZZBAXH' '备案序号'(m07) '' '' 'L' ''.
"BREAK-POINT."断点-格式控制
*---第五步:定义事件---*
wa_event-name = 'PF_STATUS_SET'."设置GUI-STATUS状态
wa_event-form = 'FORM_PF_STATUS_SET'.
APPEND wa_event TO lt_event.
CLEAR lt_event.
*wa_event-name = 'USER_COMMAND'."用户响应事件
*wa_event-form = 'FORM_USER_COMMAND'."子例程,非执行语句,需要调用才可以执行、
*APPEND wa_event TO lt_event."插入到内表(每条子例程都需要插入一次)
wa_event-name = 'TOP_OF_PAGE'."显示标题(大小标题)
wa_event-form = 'FORM_TOP_OF_PAGE'.
APPEND wa_event TO lt_event.
CLEAR lt_event.
CLEAR wa_event.
"BREAK-POINT."断点-定义事件
*---定义排序---*
wa_sort-fieldname = 'ZZHS_CODE'.
wa_sort-down = 'X'.
APPEND wa_sort TO lt_sort.
wa_sort-fieldname = 'ZZBAXH'.
wa_sort-up = 'X'.
APPEND wa_sort TO lt_sort.
"BREAK-POINT."断点-排序事件
*---第六步:显示ALV---*
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'"网格显示
EXPORTING
is_layout = ls_layout
it_fieldcat = lt_fieldcat_alv
it_events = lt_event
TABLES
t_outtab = ls_alv
EXCEPTIONS
program_error = 1
OTHERS = 2.
"BREAK-POINT."断点-显示ALV
IF sy-subrc <> 0.
ENDIF.
*CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
*EXPORTING
* is_layout_lvc = gs_layout
* it_fieldcat_lvc = gt_fieldcat
* TABLES
* t_outtab = ls_alv
*EXCEPTIONS
* program_error = 1
* OTHERS = 2.
******************************* 注册事件 ******************************************
***********FORM定义************
*FORM form_user_command.
*
*ENDFORM.
FORM form_top_of_page.
DATA it_commentary TYPE slis_t_listheader.
DATA wa_commentary TYPE slis_listheader.
wa_commentary-typ = 'H'.
wa_commentary-info = '备案序号主档'.
APPEND wa_commentary to it_commentary.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_commentary
* I_LOGO =
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
ENDFORM.
FORM form_pf_status_set USING rt_extab TYPE slis_t_extab.
SET PF-STATUS '0006_GUI'."GUI状态栏-0006-GUI
ENDFORM.
SAP ABAP学习代码笔记06
于 2024-03-14 18:20:44 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)