前言
业务需求:在ME2M、ME28增加客制化显示字段。
一、获取展示显示结构
F1如下:
结构:MEREP_OUTTAB_PURCHDOC
二、显示结构新增客制化字段
三、增强点:
BADI->ES_BADI_ME_REPORTING
代码如下:
上图物料编码为:EMATN
METHOD if_ex_me_change_outtab_cus~fill_outtab.
BREAK itl_abap04.
FIELD-SYMBOLS:
<fs_matnr> TYPE mara-matnr,
<fs_zclph> TYPE mara-zclph,
<fs_zthgg> TYPE mara-zthgg.
FIELD-SYMBOLS:
<fs_ebeln> TYPE ekkn-ebeln,
<fs_ebelp> TYPE ekkn-ebelp,
<fs_aufnr> TYPE afpo-aufnr,
<fs_matnr2> TYPE afpo-matnr,
<fs_maktx> TYPE makt-maktx.
IF ( sy-tcode EQ 'ME2M' AND im_struct_name EQ 'MEREP_OUTTAB_PURCHDOC' )
OR ( sy-tcode EQ 'ME28' AND im_struct_name EQ 'MEREP_OUTTAB_PURCHDOC_REL' ).
LOOP AT ch_outtab ASSIGNING <fs_outtab>.
ASSIGN COMPONENT 'EMATN' OF STRUCTURE <fs_outtab> TO <fs_matnr>.
ASSIGN COMPONENT 'ZZCLPH' OF STRUCTURE <fs_outtab> TO <fs_zclph>.
ASSIGN COMPONENT 'ZZTHGG' OF STRUCTURE <fs_outtab> TO <fs_zthgg>.
IF <fs_matnr> IS ASSIGNED
AND <fs_zclph> IS ASSIGNED
AND <fs_zthgg> IS ASSIGNED.
SELECT SINGLE zclph,zthgg FROM mara WHERE matnr = @<fs_matnr> INTO ( @<fs_zclph>,@<fs_zthgg> ).
ENDIF.
UNASSIGN <fs_matnr>.
UNASSIGN <fs_zclph>.
UNASSIGN <fs_zthgg>.
ASSIGN COMPONENT 'EBELN' OF STRUCTURE <fs_outtab> TO <fs_ebeln>.
ASSIGN COMPONENT 'EBELP' OF STRUCTURE <fs_outtab> TO <fs_ebelp>.
ASSIGN COMPONENT 'ZZAUFNR' OF STRUCTURE <fs_outtab> TO <fs_aufnr>.
ASSIGN COMPONENT 'ZZMATNR' OF STRUCTURE <fs_outtab> TO <fs_matnr2>.
ASSIGN COMPONENT 'ZZMAKTX' OF STRUCTURE <fs_outtab> TO <fs_maktx>.
IF <fs_ebeln> IS ASSIGNED
AND <fs_ebelp> IS ASSIGNED
AND <fs_aufnr> IS ASSIGNED
AND <fs_matnr2> IS ASSIGNED
AND <fs_maktx> IS ASSIGNED.
SELECT SINGLE
ekkn~aufnr,
afpo~matnr,
makt~maktx
FROM ekkn
INNER JOIN afpo ON afpo~aufnr = ekkn~aufnr
LEFT JOIN makt ON makt~matnr = afpo~matnr AND makt~spras = '1'
WHERE ekkn~ebeln = @<fs_ebeln>
AND ekkn~ebelp = @<fs_ebelp>
INTO ( @<fs_aufnr>,@<fs_matnr2>,@<fs_maktx> ).
ENDIF.
UNASSIGN <fs_ebeln>.
UNASSIGN <fs_ebelp>.
UNASSIGN <fs_aufnr>.
UNASSIGN <fs_matnr2>.
UNASSIGN <fs_maktx>.
ENDLOOP.
ENDIF.
ENDMETHOD.
四、效果如下
ME2M
ME28
五、LAYOUT
如果客制化字段长度较长,展示效果比较长,没有最优化列宽,隐士增强代码如下:
SE24:CL_ALV_CML_CONFIGURATION
方法:SET_DATA_TO_GRID
总结
很多报表增加客制化字段都可用增强点:ES_BADI_ME_REPORTING 会同步发布文章,比较清晰,谢谢~~~