功能:批量显示MD04 采购和计划信息、库存/范围信息
MD04图示1:
MD04图示2:
最终实现结果:
主要函数:MD_STOCK_REQUIREMENTS_LIST_API MRP信息以及可用数量。批量比较耗时。
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
*& BY XXXXXXXX
*&
*&---------------------------------------------------------------------*
REPORT zppr0038_ta.
TYPE-POOLS:slis.
TABLES:mara,marc,mdps,resb.
DATA: BEGIN OF ztpp_mrp_h OCCURS 0,
werks LIKE marc-werks,
matnr LIKE mara-matnr,
datum LIKE sy-datum,
r_num(20) TYPE c,
mtart LIKE mara-mtart,
matkl LIKE mara-matkl,
maktx TYPE makt-maktx,
meins TYPE mara-meins,
plifz TYPE marc-plifz, "计划交货
webaz TYPE marc-webaz, "交货处理
bstmi TYPE marc-bstmi, "批量大小
verpr TYPE mbew-verpr,
stprs TYPE mbew-stprs,
sum01 TYPE mdsta-sum01, "可用库存
sum02 TYPE mdsta-sum02, "固定的收货
sum03 TYPE mdsta-sum03, "月消耗量
sum04 TYPE mdsta-sum04,
eisbe LIKE marc-eisbe, "安全库存
mark1(10) TYPE c,
mark2(10) TYPE c,
mark3(10) TYPE c,
vbeln LIKE vbak-vbeln,
vbeln_num(10) TYPE c,
vbeln_yc(10) TYPE c,
END OF ztpp_mrp_h.
DATA: BEGIN OF ztpp_mrp_i OCCURS 0,
werks LIKE mard-werks, "工厂
matnr LIKE mara-matnr, "物料号
datum LIKE sy-datum, "日期
r_num(20) TYPE c, "序号
r_item TYPE mdps-rsnum, "行项目计数器
delkz LIKE mdps-delkz, "MRP 元素
dat00 LIKE mdps-dat00, "收货/需求日期
plumi LIKE mdps-plumi , "收货/发货标识
mng01 LIKE mdps-mng01 , "收货数量或需求数量
umdat LIKE sy-datum, "再计划日期
lgort LIKE mard-lgort, "库存地点
charg LIKE mdps-charg, "批号
delnr LIKE mdps-delnr, "MRP元素号
del12 LIKE mdps-del12, "MRP元素号
delps LIKE mdps-delps, "MRP元素项
baugr LIKE mdps-baugr, "高层次组装的物料号
kdauf LIKE mdps-kdauf, "销售订单数
kdpos LIKE mdps-kdpos, "销售订单中的项目编号
aufvr LIKE mdps-aufvr, "订单的货源号
posvr LIKE mdps-posvr, "货源项目号
lifnr(10) TYPE c, "供应商或债权人的帐号
mng03 LIKE mdps-mng03,
tpmng LIKE mdps-tpmng,
sum04 LIKE mdps-mng03,
END OF ztpp_mrp_i.
DATA:BEGIN OF it_mat_num OCCURS 0,
werks LIKE marc-werks,
matnr LIKE mara-matnr,
matkl TYPE mara-matkl,
maktx TYPE makt-maktx,
meins TYPE mara-meins,
plifz TYPE marc-plifz, "计划交货
webaz TYPE marc-webaz, "交货处理
bstmi TYPE marc-bstmi, "批量大小
verpr TYPE mbew-verpr,
stprs TYPE mbew-stprs,
sum04(13) TYPE p DECIMALS 3,
END OF it_mat_num.
DATA:it_mrph LIKE TABLE OF ztpp_mrp_h WITH HEADER LINE,
it_mdps LIKE TABLE OF ztpp_mrp_i WITH HEADER LINE.
DATA : BEGIN OF itab OCCURS 0 ,
matnr LIKE mseg-matnr, "訂單物料號碼訂單物料號碼
bwart LIKE mseg-bwart, " 移動類型(存貨管理)101
erfmg LIKE mseg-erfmg, "收貨數量(以訂購單位計)
sobkz LIKE mseg-sobkz, "特殊庫存
budat LIKE mkpf-budat, "過帳日期
END OF itab .
DATA:l_menge TYPE p DECIMALS 3.
DATA:it_mdpsx LIKE TABLE OF mdps WITH HEADER LINE,
it_mdezx LIKE TABLE OF mdez WITH HEADER LINE,
it_mdsux LIKE TABLE OF mdsu WITH HEADER LINE.
DATA: g_lfgja LIKE marv-lfgja. "當期年度
DATA: i_lfmon TYPE zmm6002b_ta_1-lfmon.
TYPES: BEGIN OF tab,
werks TYPE zmm6002b_ta_1-werks,
matnr TYPE zmm6002b_ta_1-matnr,
mark TYPE zmm6002b_ta_1-mark,
status(6) TYPE c,
udate TYPE zmm6002b_ta_1-udate,
uname TYPE zmm6002b_ta_1-uname,
END OF tab.
DATA tab1 TYPE STANDARD TABLE OF tab.
DATA wa_itab TYPE tab.
DATA: gw_layout TYPE slis_layout_alv,
t_fieldcat TYPE slis_t_fieldcat_alv,
w_fieldcat TYPE LINE OF slis_t_fieldcat_alv,
gw_glay TYPE lvc_s_glay.
DEFINE field_frame.
CLEAR W_FIELDCAT.
W_FIELDCAT-FIELDNAME = &1.
W_FIELDCAT-SELTEXT_S = &2.
W_FIELDCAT-NO_ZERO = &3.
W_FIELDCAT-EMPHASIZE = &4.
APPEND W_FIELDCAT TO T_FIELDCAT.
END-OF-DEFINITION.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS:
p_bukrs LIKE marv-bukrs OBLIGATORY DEFAULT 'WXTA',
p_werks LIKE marc-werks OBLIGATORY.
SELECT-OPTIONS:
s_matnr FOR marc-matnr ."NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN.
START-OF-SELECTION.
IF s_matnr = ''.
CALL FUNCTION 'POPUP_DISPLAY_MESSAGE'
EXPORTING
titel = '物料错误'
msgid = '00'
msgty = 'E'
msgno = '001'
msgv1 = '输入无效,物料号码必须输入!'.
RETURN.
ENDIF.
PERFORM get_material.
PERFORM read_mrp.
PERFORM down_mrp.
PERFORM frm_display_alv .
*&---------------------------------------------------------------------*
*& FORM get_material
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM get_material .
SELECT a~werks a~matnr INTO CORRESPONDING FIELDS OF TABLE it_mat_num FROM marc AS a
INNER JOIN mara AS b
ON a~matnr = b~matnr
WHERE a~werks = p_werks
AND a~matnr IN s_matnr.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& FORM READ_MRP
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM read_mrp .
DATA: p_num(6) TYPE n VALUE 0.
CLEAR:p_num.
LOOP AT it_mat_num.
p_num = p_num + 1.
it_mrph-werks = it_mat_num-werks.
it_mrph-matnr = it_mat_num-matnr.
it_mrph-datum = sy-datum. "保存日期
it_mrph-r_num = sy-datum && p_num.
APPEND it_mrph.
PERFORM read_md04 USING it_mat_num-matnr
it_mat_num-werks
p_num.
ENDLOOP.
ENDFORM. " READ_MRP
*&-------------------------------------------------------------------*
*& FORM READ_MD04
*&-------------------------------------------------------------------*
* TEXT
*--------------------------------------------------------------------*
FORM read_md04 USING it_mat_num_matnr LIKE mara-matnr
p_werks LIKE marc-werks
p_num TYPE n.
DATA: p_line(3) TYPE n VALUE 0.
CLEAR:p_line.
DATA:
lt_headinfo TYPE TABLE OF mt61d,
ls_headinfo LIKE LINE OF lt_headinfo,
lt_innerinfo TYPE TABLE OF mdez,
ls_innerinfo LIKE LINE OF lt_innerinfo.
CALL FUNCTION 'MD_STOCK_REQUIREMENTS_LIST_API'
EXPORTING
* PLSCN =
matnr = it_mat_num_matnr
werks = p_werks
IMPORTING
e_mt61d = ls_headinfo
TABLES
mdpsx = it_mdpsx
EXCEPTIONS
material_plant_not_found = 1
plant_not_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
* IMPLEMENT SUITABLE ERROR HANDLING HERE
ENDIF.
it_mat_num-maktx = ls_headinfo-maktx.
it_mat_num-matkl = ls_headinfo-matkl.
it_mat_num-meins = ls_headinfo-meins.
it_mat_num-plifz = ls_headinfo-plifz.
it_mat_num-stprs = ls_headinfo-stprs.
it_mat_num-verpr = ls_headinfo-verpr.
it_mat_num-webaz = ls_headinfo-webaz.
it_mat_num-bstmi = ls_headinfo-bstmi.
MODIFY it_mat_num.
CLEAR it_mat_num.
LOOP AT it_mdpsx.
CLEAR:it_mdps.
p_line = p_line + 1.
it_mdps-werks = it_mat_num-werks.
it_mdps-matnr = it_mat_num-matnr.
it_mdps-datum = sy-datum.
it_mdps-r_num = sy-datum && p_num.
it_mdps-r_item = p_line.
it_mdps-delkz = it_mdpsx-delkz."MRP标示
it_mdps-dat00 = it_mdpsx-dat00."收货/需求日期
IF it_mdps-dat00 IS INITIAL.
it_mdps-dat00 = sy-datum.
ENDIF.
it_mdps-plumi = it_mdpsx-plumi."收发标识+ / -
it_mdps-mng01 = it_mdpsx-mng01."收货数量或需求数量
it_mdps-umdat = it_mdpsx-umdat."再计划日期
it_mdps-lgort = it_mdpsx-lgort."库存地点
it_mdps-charg = it_mdpsx-charg.
it_mdps-delnr = it_mdpsx-delnr.
IF it_mdpsx-delkz = 'AR'.
it_mdps-tpmng = it_mdpsx-tpmng.
ENDIF.
IF it_mdpsx-delkz = 'SB'.
it_mdps-delnr = it_mdpsx-aufvr.
ENDIF.
IF it_mdpsx-delkz = 'LK'.
it_mdps-delnr = it_mdpsx-planr.
ENDIF.
it_mdps-del12 = it_mdpsx-del12."MRP元素号(工单)
it_mdps-delps = it_mdpsx-delps."MRP元素项
it_mdps-baugr = it_mdpsx-baugr.
IF it_mdps-del12 IS INITIAL AND it_mdps-delkz = 'BB'. "委外采购订单不显示工单时,抓委外采购订单号码
it_mdps-delnr = it_mdpsx-aufvr.
ENDIF.
IF it_mdps-delkz = 'AR' OR it_mdps-delkz = 'BB'."生产订单OR委外生产订单
SELECT SINGLE kdauf kdpos INTO (it_mdps-kdauf ,it_mdps-kdpos)
FROM aufk WHERE aufnr = it_mdps-del12.
ENDIF.
IF it_mdps-delkz = 'SB'. "计划订单
SELECT SINGLE kdauf kdpos INTO (it_mdps-kdauf ,it_mdps-kdpos)
FROM plaf WHERE plnum = it_mdps-delnr.
ENDIF.
it_mdps-aufvr = it_mdpsx-aufvr.
it_mdps-posvr = it_mdpsx-posvr.
it_mdps-lifnr = it_mdpsx-lifnr.
*-----保存所有数据避免报表数据结构错误-------
* IF IT_MDPS-MNG01 NE 0.
APPEND it_mdps.
* ENDIF.
ENDLOOP.
" APPEND IT_MDPS.
ENDFORM. " READ_MD04
*&---------------------------------------------------------------------*
*& 包含 ZRPP0023_ALV
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& 包含 ZRPP0021_ALV
*&---------------------------------------------------------------------*
FORM frm_init_fieldcat USING fu_fieldname LIKE w_fieldcat-fieldname
fu_seltext LIKE w_fieldcat-seltext_l
f_no_zero
f_color.
field_frame fu_fieldname fu_seltext f_no_zero f_color.
ENDFORM. "FRM_INIT_FIELDCAT
*&---------------------------------------------------------------------*
*& FORM FRM_OUTPUT_ALV
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
FORM frm_output_alv .
DATA:l_repid TYPE sy-repid.
l_repid = sy-repid.
gw_glay-edt_cll_cb = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = l_repid
is_layout = gw_layout
it_fieldcat = t_fieldcat
i_save = 'A'
i_grid_settings = gw_glay
TABLES
t_outtab = it_mrph[]
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "FRM_OUTPUT_ALV
*&---------------------------------------------------------------------*
*& FORM FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM frm_set_fieldcat .
PERFORM frm_init_fieldcat USING 'WERKS' '工厂' '' '' .
PERFORM frm_init_fieldcat USING 'MATNR' '物料' '' '' .
PERFORM frm_init_fieldcat USING 'DATUM' '记录日期' '' '' .
PERFORM frm_init_fieldcat USING 'MAKTX' '描述' '' '' .
PERFORM frm_init_fieldcat USING 'SUM01' '可用库存' '' '' .
PERFORM frm_init_fieldcat USING 'EISBE' '安全库存' '' '' .
PERFORM frm_init_fieldcat USING 'SUM02' '未结采购单' '' '' .
PERFORM frm_init_fieldcat USING 'SUM04' '工单需求量' '' '' .
PERFORM frm_init_fieldcat USING 'BSTMI' '批量大小' '' '' .
PERFORM frm_init_fieldcat USING 'MEINS' '单位' '' '' .
PERFORM frm_init_fieldcat USING 'PLIFZ' '计划交货时间' '' '' .
PERFORM frm_init_fieldcat USING 'WEBAZ' '交货处理时间' '' '' .
PERFORM frm_init_fieldcat USING 'VERPR' '移动平均价' '' '' .
PERFORM frm_init_fieldcat USING 'STPRS' '标准价' '' '' .
ENDFORM. "FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*& FORM FRM_INIT_LAYOUT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
FORM frm_init_layout .
gw_layout-colwidth_optimize = 'X'.
" GW_LAYOUT-ZEBRA = 'X'.
" GW_LAYOUT-BOX_FIELDNAME = 'BOX'.
ENDFORM. "FRM_INIT_LAYOUT
*&---------------------------------------------------------------------*
*& FORM FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
FORM frm_display_alv .
PERFORM frm_init_layout.
PERFORM frm_set_fieldcat.
PERFORM frm_output_alv.
ENDFORM. "FRM_DISPLAY_ALV
FORM down_mrp .
"DELETE ADJACENT DUPLICATES FROM IT_MDPS COMPARING DELNR DELPS.
LOOP AT it_mrph.
LOOP AT it_mdps.
IF it_mrph-r_num = it_mdps-r_num."AND IT_MRPH-MATNR = IT_MDPS-MATNR.
IF it_mdps-delkz = 'WB' .
it_mrph-sum01 = it_mdps-mng01.
ENDIF.
IF it_mdps-delkz = 'BE' .
it_mrph-sum02 = it_mrph-sum02 + it_mdps-mng01.
ENDIF.
IF it_mdps-delkz = 'AR' .
it_mrph-sum04 = it_mrph-sum04 + it_mdps-tpmng.
ENDIF.
MODIFY it_mrph.
ENDIF.
ENDLOOP.
ENDLOOP.
LOOP AT it_mrph.
READ TABLE it_mat_num WITH KEY matnr = it_mrph-matnr.
IF sy-subrc = 0.
it_mrph-maktx = it_mat_num-maktx.
it_mrph-matkl = it_mat_num-matkl.
it_mrph-meins = it_mat_num-meins.
it_mrph-plifz = it_mat_num-plifz.
it_mrph-stprs = it_mat_num-stprs.
it_mrph-verpr = it_mat_num-verpr.
it_mrph-webaz = it_mat_num-webaz.
it_mrph-bstmi = it_mat_num-bstmi.
MODIFY it_mrph.
ENDIF.
SELECT SINGLE eisbe INTO ( it_mrph-eisbe ) FROM marc WHERE matnr = it_mrph-matnr AND werks = it_mrph-werks.
IF sy-subrc = 0.
MODIFY it_mrph.
ENDIF.
ENDLOOP.
ENDFORM.