最近有个业务需要,MRP运行过程中需要根据生产计划订单/子件/供应商对应关系来拆解采购申请。
1.具体实例:
a.基础数据
整车物料:NL1G58420151001219
子件:000000008888002653
供应商:0000563007 / 0008000005
配额:
订单BOM:
b.创建计划独立需求T-CODE:MD61
c.MRP运行T-CODE:MD41
d.库存/需求清单T-CODE:MD04
综上:MRP运行后子件8888002653生成的采购申请是根据配额来分配供应商的。
新需求:生产某些车型需要的子件需要特定的供应商专供,针对该子件的其他采购需求还是按照配额来分配供应商。
该需求很无语,通过SPRO配置已无解,只能通过查找增强出口解决该问题了。
2.解决方式:
2.1自定义表
2.2增强点
在程序 LM61YF0J 行70 创建隐式增强点 ZIMP_BADI_MRP_VENDOR ,并插入 include zmmi0001_mrp_vendor.
2.4 INCLUDE ZMMI0001_MRP_VENDOR程序代码
*&---------------------------------------------------------------------*
*& Include ZMMI0001_MRP_VENDOR
*&
*&---------------------------------------------------------------------*
*& Program Name: MRP运行-根据车型/供应商拆分采购申请
*& Date written: 2018-08-13
*& Author's name: 陈**
*& Business design:陈**
*& Last update: 2018-08-13
*& Project Name: *****ERP项目
*& Version: V1.0
*& Modify History:
*& Sketch: MRP运行根据车型/供应商拆分采购申请
*&---------------------------------------------------------------------*
*& Variables: 变量
*& MDPSN 采购申请明细
*& MDPSX 订单需求明细(计划订单/生产订单/销售订单/采购订单)
*& MDNBX 订单需求每日汇总
*& CM61X WERKS/PLMOD/BANER/DISER/LIFKZ/TRMPL
*& CM61D MATNR/WERKS
*&---------------------------------------------------------------------*
*& 逻辑:
*& 1.校验工厂,是否执行
*& 2.获取采购明细MDPSN
*& 3.获取生产计划需求明细,根据车型获取供应商
*& 4.根据供应商拆解采购申请MDPSN
*&---------------------------------------------------------------------* "局部变量定义
data:
begin of wa_mdps,
check type c,
poflg type c,
vendor type lifnr.
include structure mdps.
data:end of wa_mdps.
data:
lv_mng01 type mdps-mng01,
lv_bnfpo type eban-bnfpo,
lv_mng02 type mdps-mng02,
lv_exitdg type c,
lv_index type i.
data:
lt_mrp_mdpsn like table of mdps,
lt_mrp_mdpso like table of mdps,
lt_cop_mdpsn like table of mdps,
lt_col_mdpsn like table of mdps,
lt_mrp_mdpsx like table of wa_mdps,
lt_mrp_mdnbx like table of mdnb,
lt_mrp_vendor like table of ztmm0094_mrp_vnd.
field-symbols:
<fs_mdpsx> like wa_mdps,
<fs_vendor> like ztmm0094_mrp_vnd,
<fs_mdps> like mdps,
<fs_mdpsn> like mdps,
<fs_mdpso> like mdps,
<fs_mdnbx> like mdnb. select single fg_exitdg
into lv_exitdg
from ztmm0093_mrp_wrk
where werks = cm61x-werks
and fg_enable = 'X'
and fg_vendor = 'X'.
if sy-subrc = .
"是否断点
if lv_exitdg = 'X'.
break-point.
endif. lt_mrp_mdpsn[] = mdpsn[].
lt_mrp_mdnbx[] = mdnbx[].
lt_mrp_mdpso[] = mdpso[]. loop at mdpsx assigning <fs_mdps>.
append initial line to lt_mrp_mdpsx assigning <fs_mdpsx>.
move-corresponding <fs_mdps> to <fs_mdpsx>.
unassign <fs_mdpsx>.
endloop. loop at lt_mrp_mdpsn assigning <fs_mdpsn>
where delnr is not initial.
"行项目6位转5位
clear:lv_bnfpo.
lv_bnfpo = <fs_mdpsn>-delps+(). "获取供应商
select single flief
into <fs_mdpsn>-lifnr
from eban
where banfn = <fs_mdpsn>-delnr
and bnfpo = lv_bnfpo.
endloop. "获取组件对应供应商
select *
into table lt_mrp_vendor
from ztmm0094_mrp_vnd
where werks = cm61x-werks
and idnrk = cm61d-matnr.
sort lt_mrp_vendor by werks idnrk matnr lifnr. loop at lt_mrp_mdpsx assigning <fs_mdpsx>
where delkz <> 'WB'
and ( plumi = '+' or plumi = '-'). "判断是否计划订单/生产订单
if <fs_mdpsx>-stlty = 'M'
and <fs_mdpsx>-stlnr is not initial
and <fs_mdpsx>-stlkn is not initial
and <fs_mdpsx>-stpoz is not initial
and <fs_mdpsx>-baugr is not initial. read table lt_mrp_vendor
assigning <fs_vendor>
with key matnr = <fs_mdpsx>-baugr
binary search.
if sy-subrc = .
"标识-车型/组件/供应商匹配
<fs_mdpsx>-check = 'X'.
<fs_mdpsx>-vendor = <fs_vendor>-lifnr.
endif.
endif. "拆分采购申请
if <fs_mdpsx>-plumi = '-'.
loop at lt_mrp_mdpsn assigning <fs_mdpsn>
where mng01 > .
"非特殊标识check=space供应商
if <fs_mdpsx>-check = space.
<fs_mdpsx>-vendor = <fs_mdpsn>-lifnr.
endif.
"逐步递减数量
clear:lv_mng01.
if <fs_mdpsx>-mng01 >= <fs_mdpsn>-mng01.
lv_mng01 = <fs_mdpsn>-mng01.
elseif <fs_mdpsx>-mng01 < <fs_mdpsn>-mng01.
lv_mng01 = <fs_mdpsx>-mng01.
endif. if <fs_mdpsn>-delkz <> 'ZZ'.
read table lt_cop_mdpsn assigning <fs_mdps>
with key plaab = <fs_mdpsn>-plaab
planr = <fs_mdpsn>-planr
tag00 = <fs_mdpsn>-tag00
sort1 = <fs_mdpsn>-sort1
sort2 = <fs_mdpsn>-sort2
lgort = <fs_mdpsn>-lgort
delkz = <fs_mdpsn>-delkz
lifnr = <fs_mdpsx>-vendor
vrfkz = <fs_mdpsn>-vrfkz
plumi = <fs_mdpsn>-plumi
dat00 = <fs_mdpsn>-dat00
dat01 = <fs_mdpsn>-dat01
dat02 = <fs_mdpsn>-dat02.
if sy-subrc = .
<fs_mdps>-mng01 = <fs_mdps>-mng01 + lv_mng01.
else.
if cm61x-plmod = '' "1 适应计划数据(普通模式)
or cm61x-plmod = ''. "2 重扩展 BOM 和工艺路线
read table mdpso assigning <fs_mdpso>
with key plaab = <fs_mdpsn>-plaab
planr = <fs_mdpsn>-planr
tag00 = <fs_mdpsn>-tag00
sort1 = <fs_mdpsn>-sort1
sort2 = <fs_mdpsn>-sort2
lgort = <fs_mdpsn>-lgort
delkz = <fs_mdpsn>-delkz
lifnr = <fs_mdpsx>-vendor
vrfkz = <fs_mdpsn>-vrfkz
plumi = <fs_mdpsn>-plumi
dat00 = <fs_mdpsn>-dat00
dat01 = <fs_mdpsn>-dat01
dat02 = <fs_mdpsn>-dat02.
if sy-subrc = .
lv_index = sy-tabix.
if <fs_mdpsx>-check = 'X'.
append initial line to lt_cop_mdpsn assigning <fs_mdps>.
move-corresponding <fs_mdpso> to <fs_mdps>.
<fs_mdps>-mng01 = lv_mng01.
<fs_mdps>-lifnr = <fs_mdpsx>-vendor.
<fs_mdps>-vstat = <fs_mdpsn>-vstat.
unassign <fs_mdps>.
else.
append initial line to lt_cop_mdpsn assigning <fs_mdps>.
move-corresponding <fs_mdpso> to <fs_mdps>.
<fs_mdps>-mng01 = lv_mng01.
<fs_mdps>-lifnr = <fs_mdpsx>-vendor.
<fs_mdps>-vstat = <fs_mdpsn>-vstat.
unassign <fs_mdps>.
endif.
delete mdpso index lv_index.
else.
if <fs_mdpsx>-check = 'X'.
append initial line to lt_cop_mdpsn assigning <fs_mdps>.
move-corresponding <fs_mdpsn> to <fs_mdps>.
<fs_mdps>-mng01 = lv_mng01.
<fs_mdps>-lifnr = <fs_mdpsx>-vendor.
unassign <fs_mdps>.
else.
append initial line to lt_cop_mdpsn assigning <fs_mdps>.
move-corresponding <fs_mdpsn> to <fs_mdps>.
<fs_mdps>-mng01 = lv_mng01.
<fs_mdps>-lifnr = <fs_mdpsx>-vendor.
unassign <fs_mdps>.
endif.
endif.
unassign <fs_mdpso>.
elseif cm61x-plmod = ''. "3 删除并重新创建计划数据
if <fs_mdpsx>-check = 'X'.
append initial line to lt_cop_mdpsn assigning <fs_mdps>.
move-corresponding <fs_mdpsn> to <fs_mdps>.
<fs_mdps>-mng01 = lv_mng01.
<fs_mdps>-lifnr = <fs_mdpsx>-vendor.
unassign <fs_mdps>.
else.
append initial line to lt_cop_mdpsn assigning <fs_mdps>.
move-corresponding <fs_mdpsn> to <fs_mdps>.
<fs_mdps>-mng01 = lv_mng01.
<fs_mdps>-lifnr = <fs_mdpsx>-vendor.
unassign <fs_mdps>.
endif.
endif.
endif.
endif. <fs_mdpsn>-mng01 = <fs_mdpsn>-mng01 - lv_mng01.
<fs_mdpsx>-mng01 = <fs_mdpsx>-mng01 - lv_mng01. if <fs_mdpsx>-mng01 = .
exit.
endif.
endloop.
elseif <fs_mdpsx>-plumi = '+'.
append initial line to lt_mrp_mdpsn assigning <fs_mdpsn>.
move-corresponding <fs_mdpsx> to <fs_mdpsn>.
<fs_mdpsn>-delkz = 'ZZ'. "自定义符号,仅逻辑计算
unassign <fs_mdpsn>. sort lt_mrp_mdpsn.
endif.
endloop. "未清记录
loop at lt_mrp_mdpsn assigning <fs_mdpsn>
where delkz <> 'ZZ'
and vstat <> 'L'
and mng01 > . read table lt_cop_mdpsn assigning <fs_mdps>
with key plaab = <fs_mdpsn>-plaab
planr = <fs_mdpsn>-planr
tag00 = <fs_mdpsn>-tag00
sort1 = <fs_mdpsn>-sort1
sort2 = <fs_mdpsn>-sort2
lgort = <fs_mdpsn>-lgort
delkz = <fs_mdpsn>-delkz
lifnr = <fs_mdpsn>-lifnr
vrfkz = <fs_mdpsn>-vrfkz
plumi = <fs_mdpsn>-plumi
dat00 = <fs_mdpsn>-dat00
dat01 = <fs_mdpsn>-dat01
dat02 = <fs_mdpsn>-dat02.
if sy-subrc = .
<fs_mdps>-mng01 = <fs_mdps>-mng01 + <fs_mdpsn>-mng01.
else.
append initial line to lt_cop_mdpsn assigning <fs_mdps>.
move-corresponding <fs_mdpsn> to <fs_mdps>.
<fs_mdps>-mng01 = <fs_mdpsn>-mng01.
<fs_mdps>-lifnr = <fs_mdpsn>-lifnr.
endif.
unassign <fs_mdps>.
endloop. sort lt_cop_mdpsn. "数量总和对比
clear:lv_mng01,lv_mng02. loop at lt_cop_mdpsn assigning <fs_mdps>.
lv_mng01 = lv_mng01 + <fs_mdps>-mng01.
endloop. loop at mdpsn assigning <fs_mdpsn>.
lv_mng02 = lv_mng02 + <fs_mdpsn>-mng01.
endloop. if lv_mng01 <> lv_mng02. endif. "最终执行记录
mdpsn[] = lt_cop_mdpsn[]. sort mdpsn. endif.
3.测试
3.1维护配置表
ZTMM0093_MRP_WRK
ZTMM0094_MRP_VND
3.2业务测试
子件8888002653重新运行MRP,T-CODE:MD41
查询子件子件8888002653 MRP运行后的库存需求清单,T-CODE:MD04
整车物料NL1G58420151001219对应子件8888002653获取的供应商编号为 8000005 (配置表ZTMM0094_MRP_VND记录)