ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

最近有个业务需要,MRP运行过程中需要根据生产计划订单/子件/供应商对应关系来拆解采购申请。

1.具体实例:

 a.基础数据

  整车物料:NL1G58420151001219

  子件:000000008888002653

  供应商:0000563007 / 0008000005

  配额:

  ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

  订单BOM:

  ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

 b.创建计划独立需求T-CODE:MD61

  ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

 c.MRP运行T-CODE:MD41

  ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

 d.库存/需求清单T-CODE:MD04     

  ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

 综上:MRP运行后子件8888002653生成的采购申请是根据配额来分配供应商的。

 新需求:生产某些车型需要的子件需要特定的供应商专供,针对该子件的其他采购需求还是按照配额来分配供应商。

 该需求很无语,通过SPRO配置已无解,只能通过查找增强出口解决该问题了。

 

2.解决方式:

 2.1自定义表

  ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

  ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

 2.2增强点

  ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

  在程序 LM61YF0J 行70 创建隐式增强点 ZIMP_BADI_MRP_VENDOR ,并插入 include zmmi0001_mrp_vendor.

 2.4 INCLUDE ZMMI0001_MRP_VENDOR程序代码

  1 *&---------------------------------------------------------------------* 
  2 *& Include  ZMMI0001_MRP_VENDOR 
  3 *& 
  4 *&---------------------------------------------------------------------* 
  5 *& Program Name:  MRP运行-根据车型/供应商拆分采购申请 
  6 *& Date written:  2018-08-13 
  7 *& Author's name: 陈** 
  8 *& Business design:陈** 
  9 *& Last update:   2018-08-13 
 10 *& Project Name: *****ERP项目 
 11 *& Version:       V1.0 
 12 *& Modify History: 
 13 *& Sketch:        MRP运行根据车型/供应商拆分采购申请 
 14 *&---------------------------------------------------------------------* 
 15 *& Variables:     变量 
 16 *& MDPSN          采购申请明细 
 17 *& MDPSX          订单需求明细(计划订单/生产订单/销售订单/采购订单) 
 18 *& MDNBX          订单需求每日汇总 
 19 *& CM61X          WERKS/PLMOD/BANER/DISER/LIFKZ/TRMPL 
 20 *& CM61D          MATNR/WERKS 
 21 *&---------------------------------------------------------------------* 
 22 *& 逻辑: 
 23 *& 1.校验工厂,是否执行 
 24 *& 2.获取采购明细MDPSN 
 25 *& 3.获取生产计划需求明细,根据车型获取供应商 
 26 *& 4.根据供应商拆解采购申请MDPSN 
 27 *&---------------------------------------------------------------------* 
 28  
 29 "局部变量定义 
 30   data: 
 31     begin of wa_mdps, 
 32     check  type c, 
 33     poflg  type c, 
 34     vendor type lifnr. 
 35     include structure mdps. 
 36   data:end of wa_mdps. 
 37   data: 
 38     lv_mng01      type mdps-mng01, 
 39     lv_bnfpo      type eban-bnfpo, 
 40     lv_mng02      type mdps-mng02, 
 41     lv_exitdg     type c, 
 42     lv_index      type i. 
 43   data: 
 44     lt_mrp_mdpsn  like table of mdps, 
 45     lt_mrp_mdpso  like table of mdps, 
 46     lt_cop_mdpsn  like table of mdps, 
 47     lt_col_mdpsn  like table of mdps, 
 48     lt_mrp_mdpsx  like table of wa_mdps, 
 49     lt_mrp_mdnbx  like table of mdnb, 
 50     lt_mrp_vendor like table of ztmm0094_mrp_vnd. 
 51   field-symbols: 
 52     <fs_mdpsx>    like wa_mdps, 
 53     <fs_vendor>   like ztmm0094_mrp_vnd, 
 54     <fs_mdps>     like mdps, 
 55     <fs_mdpsn>    like mdps, 
 56     <fs_mdpso>    like mdps, 
 57     <fs_mdnbx>    like mdnb. 
 58  
 59   select single fg_exitdg 
 60     into lv_exitdg 
 61     from ztmm0093_mrp_wrk 
 62    where werks     = cm61x-werks 
 63      and fg_enable = 'X' 
 64      and fg_vendor = 'X'. 
 65   if sy-subrc = 0. 
 66     "是否断点 
 67     if lv_exitdg = 'X'. 
 68       break-point. 
 69     endif. 
 70  
 71     lt_mrp_mdpsn[] = mdpsn[]. 
 72     lt_mrp_mdnbx[] = mdnbx[]. 
 73     lt_mrp_mdpso[] = mdpso[]. 
 74  
 75     loop at mdpsx assigning <fs_mdps>. 
 76       append initial line to lt_mrp_mdpsx assigning <fs_mdpsx>. 
 77       move-corresponding <fs_mdps> to <fs_mdpsx>. 
 78       unassign <fs_mdpsx>. 
 79     endloop. 
 80  
 81     loop at lt_mrp_mdpsn assigning <fs_mdpsn> 
 82     where delnr is not initial. 
 83       "行项目6位转5位 
 84       clear:lv_bnfpo. 
 85       lv_bnfpo = <fs_mdpsn>-delps+1(5). 
 86  
 87       "获取供应商 
 88       select single flief 
 89         into <fs_mdpsn>-lifnr 
 90         from eban 
 91        where banfn = <fs_mdpsn>-delnr 
 92          and bnfpo = lv_bnfpo. 
 93     endloop. 
 94  
 95     "获取组件对应供应商 
 96     select * 
 97       into table lt_mrp_vendor 
 98       from ztmm0094_mrp_vnd 
 99      where werks = cm61x-werks 
100        and idnrk = cm61d-matnr. 
101     sort lt_mrp_vendor by werks idnrk matnr lifnr. 
102  
103     loop at lt_mrp_mdpsx assigning <fs_mdpsx> 
104     where delkz <> 'WB' 
105       and ( plumi = '+' or plumi = '-'). 
106  
107       "判断是否计划订单/生产订单 
108       if  <fs_mdpsx>-stlty = 'M' 
109       and <fs_mdpsx>-stlnr is not initial 
110       and <fs_mdpsx>-stlkn is not initial 
111       and <fs_mdpsx>-stpoz is not initial 
112       and <fs_mdpsx>-baugr is not initial. 
113  
114         read table lt_mrp_vendor 
115         assigning <fs_vendor> 
116         with key matnr = <fs_mdpsx>-baugr 
117         binary search. 
118         if sy-subrc = 0. 
119           "标识-车型/组件/供应商匹配 
120           <fs_mdpsx>-check  = 'X'. 
121           <fs_mdpsx>-vendor = <fs_vendor>-lifnr. 
122         endif. 
123       endif. 
124  
125       "拆分采购申请 
126       if <fs_mdpsx>-plumi = '-'. 
127         loop at lt_mrp_mdpsn assigning <fs_mdpsn> 
128         where mng01 > 0. 
129           "非特殊标识check=space供应商 
130           if <fs_mdpsx>-check = space. 
131             <fs_mdpsx>-vendor = <fs_mdpsn>-lifnr. 
132           endif. 
133           "逐步递减数量 
134           clear:lv_mng01. 
135           if <fs_mdpsx>-mng01 >= <fs_mdpsn>-mng01. 
136             lv_mng01 = <fs_mdpsn>-mng01. 
137           elseif <fs_mdpsx>-mng01 < <fs_mdpsn>-mng01. 
138             lv_mng01 = <fs_mdpsx>-mng01. 
139           endif. 
140  
141           if <fs_mdpsn>-delkz <> 'ZZ'. 
142             read table lt_cop_mdpsn assigning <fs_mdps> 
143             with key plaab = <fs_mdpsn>-plaab 
144                      planr = <fs_mdpsn>-planr 
145                      tag00 = <fs_mdpsn>-tag00 
146                      sort1 = <fs_mdpsn>-sort1 
147                      sort2 = <fs_mdpsn>-sort2 
148                      lgort = <fs_mdpsn>-lgort 
149                      delkz = <fs_mdpsn>-delkz 
150                      lifnr = <fs_mdpsx>-vendor 
151                      vrfkz = <fs_mdpsn>-vrfkz 
152                      plumi = <fs_mdpsn>-plumi 
153                      dat00 = <fs_mdpsn>-dat00 
154                      dat01 = <fs_mdpsn>-dat01 
155                      dat02 = <fs_mdpsn>-dat02. 
156             if sy-subrc = 0. 
157               <fs_mdps>-mng01 = <fs_mdps>-mng01 + lv_mng01. 
158             else. 
159               if cm61x-plmod = '1'  "1  适应计划数据(普通模式) 
160               or cm61x-plmod = '2'. "2  重扩展 BOM 和工艺路线 
161                 read table mdpso assigning <fs_mdpso> 
162                 with key plaab = <fs_mdpsn>-plaab 
163                          planr = <fs_mdpsn>-planr 
164                          tag00 = <fs_mdpsn>-tag00 
165                          sort1 = <fs_mdpsn>-sort1 
166                          sort2 = <fs_mdpsn>-sort2 
167                          lgort = <fs_mdpsn>-lgort 
168                          delkz = <fs_mdpsn>-delkz 
169                          lifnr = <fs_mdpsx>-vendor 
170                          vrfkz = <fs_mdpsn>-vrfkz 
171                          plumi = <fs_mdpsn>-plumi 
172                          dat00 = <fs_mdpsn>-dat00 
173                          dat01 = <fs_mdpsn>-dat01 
174                          dat02 = <fs_mdpsn>-dat02. 
175                 if sy-subrc = 0. 
176                   lv_index = sy-tabix. 
177                   if <fs_mdpsx>-check  = 'X'. 
178                     append initial line to lt_cop_mdpsn assigning <fs_mdps>. 
179                     move-corresponding <fs_mdpso> to <fs_mdps>. 
180                     <fs_mdps>-mng01 = lv_mng01. 
181                     <fs_mdps>-lifnr = <fs_mdpsx>-vendor. 
182                     <fs_mdps>-vstat = <fs_mdpsn>-vstat. 
183                     unassign <fs_mdps>. 
184                   else. 
185                     append initial line to lt_cop_mdpsn assigning <fs_mdps>. 
186                     move-corresponding <fs_mdpso> to <fs_mdps>. 
187                     <fs_mdps>-mng01 = lv_mng01. 
188                     <fs_mdps>-lifnr = <fs_mdpsx>-vendor. 
189                     <fs_mdps>-vstat = <fs_mdpsn>-vstat. 
190                     unassign <fs_mdps>. 
191                   endif. 
192                   delete mdpso index lv_index. 
193                 else. 
194                   if <fs_mdpsx>-check  = 'X'. 
195                     append initial line to lt_cop_mdpsn assigning <fs_mdps>. 
196                     move-corresponding <fs_mdpsn> to <fs_mdps>. 
197                     <fs_mdps>-mng01 = lv_mng01. 
198                     <fs_mdps>-lifnr = <fs_mdpsx>-vendor. 
199                     unassign <fs_mdps>. 
200                   else. 
201                     append initial line to lt_cop_mdpsn assigning <fs_mdps>. 
202                     move-corresponding <fs_mdpsn> to <fs_mdps>. 
203                     <fs_mdps>-mng01 = lv_mng01. 
204                     <fs_mdps>-lifnr = <fs_mdpsx>-vendor. 
205                     unassign <fs_mdps>. 
206                   endif. 
207                 endif. 
208                 unassign <fs_mdpso>. 
209               elseif cm61x-plmod = '3'. "3  删除并重新创建计划数据 
210                 if <fs_mdpsx>-check  = 'X'. 
211                   append initial line to lt_cop_mdpsn assigning <fs_mdps>. 
212                   move-corresponding <fs_mdpsn> to <fs_mdps>. 
213                   <fs_mdps>-mng01 = lv_mng01. 
214                   <fs_mdps>-lifnr = <fs_mdpsx>-vendor. 
215                   unassign <fs_mdps>. 
216                 else. 
217                   append initial line to lt_cop_mdpsn assigning <fs_mdps>. 
218                   move-corresponding <fs_mdpsn> to <fs_mdps>. 
219                   <fs_mdps>-mng01 = lv_mng01. 
220                   <fs_mdps>-lifnr = <fs_mdpsx>-vendor. 
221                   unassign <fs_mdps>. 
222                 endif. 
223               endif. 
224             endif. 
225           endif. 
226  
227           <fs_mdpsn>-mng01 = <fs_mdpsn>-mng01 - lv_mng01. 
228           <fs_mdpsx>-mng01 = <fs_mdpsx>-mng01 - lv_mng01. 
229  
230           if <fs_mdpsx>-mng01 = 0. 
231              exit. 
232           endif. 
233         endloop. 
234       elseif <fs_mdpsx>-plumi = '+'. 
235         append initial line to lt_mrp_mdpsn assigning <fs_mdpsn>. 
236         move-corresponding <fs_mdpsx> to <fs_mdpsn>. 
237         <fs_mdpsn>-delkz = 'ZZ'.   "自定义符号,仅逻辑计算 
238         unassign <fs_mdpsn>. 
239  
240         sort lt_mrp_mdpsn. 
241       endif. 
242     endloop. 
243  
244     "未清记录 
245     loop at lt_mrp_mdpsn assigning <fs_mdpsn> 
246     where delkz <> 'ZZ' 
247       and vstat <> 'L' 
248       and mng01 > 0. 
249  
250       read table lt_cop_mdpsn assigning <fs_mdps> 
251       with key plaab = <fs_mdpsn>-plaab 
252                planr = <fs_mdpsn>-planr 
253                tag00 = <fs_mdpsn>-tag00 
254                sort1 = <fs_mdpsn>-sort1 
255                sort2 = <fs_mdpsn>-sort2 
256                lgort = <fs_mdpsn>-lgort 
257                delkz = <fs_mdpsn>-delkz 
258                lifnr = <fs_mdpsn>-lifnr 
259                vrfkz = <fs_mdpsn>-vrfkz 
260                plumi = <fs_mdpsn>-plumi 
261                dat00 = <fs_mdpsn>-dat00 
262                dat01 = <fs_mdpsn>-dat01 
263                dat02 = <fs_mdpsn>-dat02. 
264       if sy-subrc = 0. 
265         <fs_mdps>-mng01 = <fs_mdps>-mng01 + <fs_mdpsn>-mng01. 
266       else. 
267         append initial line to lt_cop_mdpsn assigning <fs_mdps>. 
268         move-corresponding <fs_mdpsn> to <fs_mdps>. 
269         <fs_mdps>-mng01 = <fs_mdpsn>-mng01. 
270         <fs_mdps>-lifnr = <fs_mdpsn>-lifnr. 
271       endif. 
272       unassign <fs_mdps>. 
273     endloop. 
274  
275     sort lt_cop_mdpsn. 
276  
277     "数量总和对比 
278     clear:lv_mng01,lv_mng02. 
279  
280     loop at lt_cop_mdpsn assigning <fs_mdps>. 
281       lv_mng01 = lv_mng01 + <fs_mdps>-mng01. 
282     endloop. 
283  
284     loop at mdpsn assigning <fs_mdpsn>. 
285       lv_mng02 = lv_mng02 + <fs_mdpsn>-mng01. 
286     endloop. 
287  
288     if lv_mng01 <> lv_mng02. 
289  
290     endif. 
291  
292     "最终执行记录 
293     mdpsn[] = lt_cop_mdpsn[]. 
294  
295     sort mdpsn. 
296  
297   endif.

3.测试

 3.1维护配置表

  ZTMM0093_MRP_WRK

  ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

  ZTMM0094_MRP_VND

  ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

 3.2业务测试

  子件8888002653重新运行MRP,T-CODE:MD41

  ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

  查询子件子件8888002653 MRP运行后的库存需求清单,T-CODE:MD04

  ABAP-增强-MRP运行-根据工厂/父件/子件/供应商拆分采购申请详解编程语言

  整车物料NL1G58420151001219对应子件8888002653获取的供应商编号为 8000005 (配置表ZTMM0094_MRP_VND记录)

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/17977.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论