*&---------------------------------------------------------------------*
*& Report ZMMD0007_TEST_DL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZMMD0007_TEST_DL.
TABLES :sscrfields,ztmm0045,marc."引用数据表
*---form不可以做DATA定义。
PERFORM get_alv_select."第三步
PERFORM get_alv_lfc. "第四步
PERFORM get_alv_reuse. "第五步
*---第一步:声明ALV相关变量---*
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."参考内表再定义一个内表
*---第三步:读取数据---*
FORM get_alv_select.
SELECT
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 @gt_alv.
ENDFORM.
*---第四步:格式控制,布局结构---*
FORM get_alv_lfc.
*layout*
gs_layout-zebra = 'X'."ALV 控制: 可选行颜色 (带)-呈现颜色交替斑马纹
gs_layout-cwidth_opt = 'X'."' '."优化列管-X&空格
gs_layout-sel_mode = 'A'."总计
*fieldcat*
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:"插入宏-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) '' '' 'L' '',
'ZZBAXH' '备案序号'(m07) '' '' 'L' ''.
ENDFORM.
*---第五步:显示ALV---*
FORM get_alv_reuse.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fieldcat
TABLES
t_outtab = gt_alv
EXCEPTIONS
program_error = 1
OTHERS = 2.
"BREAK-POINT."断点-显示ALV
IF sy-subrc <> 0.
ENDIF.
ENDFORM.
SAP ABAP学习代码笔记07
最新推荐文章于 2024-08-21 23:32:17 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)