zoukankan      html  css  js  c++  java
  • ABAP-增强-层级BOM-AB件业务

    目前新需求:整车A下挂有委外总成件B,总成件B和子件E是层级BOM,且采购类型均为F,信息记录类型均为寄售,按照现在标准MRP逻辑,只能计算第一层级子件需求,无法运行出子件E的需求。

    1.实现方式

     1.1自定义表

      ZTMM0093_MRP_WRK 

      

      ZTMM0010_MAT_INF:接口-物料主数据明细表

     1.2增强点

      在获取BOM子件中进行增强:函数 GET_STPO 行 311 增加隐式增强点 ZIMP_BADI_MRP_BOM_HIERARCHY

      

      INCLUDE ZMMI0003_MRP_BOM_HIERARCHY程序代码:

      1 *&---------------------------------------------------------------------*
      2 *& Include  ZMMI0003_MRP_BOM_HIERARCHY
      3 *&
      4 *&---------------------------------------------------------------------*
      5 *& Program Name:  MRP运行-BOM层级子件
      6 *& Date written:  2018-10-29
      7 *& Author's name: ***
      8 *& Business design:***
      9 *& Last update:   2018-10-29
     10 *& Project Name:  ***ERP项目
     11 *& Version:       V1.0
     12 *& Modify History:
     13 *& Sketch:        MRP运行-BOM层级子件
     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.获取BOM第一层级总成件是否含子件信息,
     25 *& 3.判断总成件是否为委外件(查询ZTMM0010_MAT_INF 字段MAKEBUYINDICATOR=CSMT-A)
     26 *& 4.若为委外总成件,则将总成下子件运行MRP
     27 *& 5.子件需求日期 = MRP结果中总成件需求日期 - 总成件收货处理时间 - 子件加工时间(可配置);
     28 *& 6.子件的交货日期 = 子件的需求日期 - 子件收货处理时间
     29 *&---------------------------------------------------------------------*
     30 constants:
     31   lc_check            type c          value 'X',
     32   lc_stlty            type stpo-stlty value 'M',
     33   lc_stlan            type mast-stlan value '1',
     34   lc_stlal            type mast-stlal value '01',
     35   lc_postp            type stpo-postp value 'L',
     36   lc_makebuyindicator type string     value 'CSMT-A',
     37   lc_capid            type tc04-capid value 'PP01',
     38   lc_beskz_f          type string     value 'F',
     39   lc_mtart_zycl       type string     value 'ZYCL'.
     40 data:
     41   lv_werks   like marc-werks,
     42   lv_posnr   type stpob-posnr,
     43   lv_index   type cszalt-index,
     44   lv_i_matnr type csap_mbom-matnr,
     45   lv_i_plant type csap_mbom-werks,
     46   lv_i_usage type csap_mbom-stlan,
     47   lv_i_alter type csap_mbom-stlal,
     48   lv_i_datuv type datuv_bi,
     49   lv_i_datub type datub_bi.
     50 data:
     51   ls_mrp     like ztmm0093_mrp_wrk,
     52   ls_wa      type line of cs01_stpob_tab,
     53   ls_matinf  like ztmm0010_mat_inf,
     54   ls_i_stpo  type stpo_api02.
     55 data:
     56   lt_wa      like table of stpob,
     57   lt_addwa   type table of cszalt,
     58   lt_stb     type table of stpo,
     59   lt_e_stpo  type table of stpo_api02.
     60 field-symbols:
     61   <fs_stpo>  like stpo,
     62   <fs_estpo> like stpo_api02,
     63   <fs_cwa>   like stpob,
     64   <fs_cadd>  like cszalt,
     65   <fs_wa>    like stpob,
     66   <fs_addwa> like cszalt.
     67 
     68 read table wa into ls_wa index 1.
     69 
     70 "获取工厂
     71 select single wrkan
     72   into lv_werks
     73   from stko
     74  where stlnr = ls_wa-stlnr
     75    and stlty = ls_wa-stlty.
     76 
     77 select single *
     78   into ls_mrp
     79   from ztmm0093_mrp_wrk
     80  where werks       = lv_werks
     81    and fg_bomlevel = lc_check.
     82 if sy-subrc = 0 and ls_mrp-vl_tcode cs sy-tcode.
     83   if ls_mrp-fg_exitdg = lc_check.
     84     break-point.
     85   endif.
     86 
     87   loop at wa assigning <fs_wa>.
     88     clear:lt_stb,ls_matinf.
     89     "判断是否委外总成件
     90     select single
     91            max( datum ) as datum
     92            max( uzeit ) as uzeit
     93            makebuyindicator
     94       into corresponding fields of ls_matinf
     95       from ztmm0010_mat_inf
     96      where partbase = <fs_wa>-idnrk
     97      group by makebuyindicator.
     98     if ls_matinf-makebuyindicator = lc_makebuyindicator.
     99 *      "获取总成件BOM子件
    100 *      "BOM执行函数涉及嵌套问题,CK11N成本核算报错
    101 *      call function 'CS_BOM_EXPL_MAT_V2'
    102 *        exporting
    103 *          capid                 = lc_capid       "PP01生产用途
    104 *          datuv                 = sy-datum
    105 *          ehndl                 = '1'
    106 *          emeng                 = <fs_wa>-menge
    107 *          mktls                 = 'X'
    108 *          mehrs                 = ''    "分解多层BOM
    109 *          mmory                 = '1'
    110 *          mtnrv                 = <fs_wa>-idnrk
    111 *          stlan                 = '1'    "BOM用途
    112 *          stpst                 = 0
    113 *          svwvo                 = 'X'
    114 *          werks                 = lv_werks
    115 *        tables
    116 *          stb                   = lt_stb
    117 *        exceptions
    118 *          alt_not_found         = 1
    119 *          call_invalid          = 2
    120 *          material_not_found    = 3
    121 *          missing_authorization = 4
    122 *          no_bom_found          = 5
    123 *          no_plant_data         = 6
    124 *          no_suitable_bom_found = 7
    125 *          conversion_error      = 8
    126 *          others                = 9.
    127 
    128       clear:ls_i_stpo,lv_i_matnr,lv_i_plant,lv_i_usage,lv_i_alter,lv_i_datuv,lv_i_datub.
    129       clear:lt_e_stpo,lt_e_stpo[].
    130 
    131       lv_i_matnr = <fs_wa>-idnrk.
    132       lv_i_plant = lv_werks.
    133       lv_i_usage = lc_stlan.
    134       "lv_i_alter = alter.
    135       lv_i_datuv = datuv.
    136       lv_i_datub = datub.
    137 
    138       "获取总成件BOM清单
    139       call function 'CSAP_MAT_BOM_ITEM_SELECT'
    140         exporting
    141           i_stpo                     = ls_i_stpo
    142           material                   = lv_i_matnr
    143           plant                      = lv_i_plant
    144           bom_usage                  = lv_i_usage
    145           alternative                = lv_i_alter
    146           fl_material_check          = lc_check
    147           fl_foreign_key_check       = lc_check
    148           valid_from                 = lv_i_datuv
    149           valid_to                   = lv_i_datub
    150         tables
    151           t_stpo                     = lt_e_stpo
    152         exceptions
    153           error                      = 1
    154           others                     = 2  .
    155       if sy-subrc <> 0.
    156 * Implement suitable error handling here
    157       else.
    158         loop at lt_e_stpo assigning <fs_estpo>.
    159           call function 'CONVERSION_EXIT_ALPHA_INPUT'
    160             exporting
    161               input         = <fs_estpo>-component
    162             importing
    163               output        = <fs_estpo>-component.
    164         endloop.
    165       endif.
    166 
    167       select *
    168         into corresponding fields of table lt_stb
    169         from mast as a inner join stpo as b
    170           on a~stlnr = b~stlnr
    171        where a~stlan = lc_stlan
    172          and a~stlal = lc_stlal
    173          and a~werks = lv_werks
    174          and a~matnr = <fs_wa>-idnrk
    175          and b~stlty = lc_stlty
    176          and b~lkenz = space
    177          and b~datuv <= sy-datum
    178          and b~postp = lc_postp.
    179 
    180       loop at lt_stb assigning <fs_stpo>.
    181         read table lt_e_stpo assigning <fs_estpo>
    182         with key item_guid = <fs_stpo>-guidx.
    183         if sy-subrc <> 0.
    184           continue.
    185         endif.
    186 
    187         select single count(*)
    188           from mara inner join marc
    189             on mara~matnr = marc~matnr
    190          where mara~matnr = <fs_stpo>-idnrk
    191            and mara~mtart = lc_mtart_zycl
    192            and marc~beskz = lc_beskz_f.
    193         if sy-subrc = 0.
    194           append initial line to lt_wa assigning <fs_cwa>.
    195           move-corresponding <fs_wa> to <fs_cwa>.
    196           <fs_cwa>-idnrk = <fs_stpo>-idnrk.
    197           <fs_cwa>-menge = <fs_stpo>-menge.
    198           <fs_cwa>-meins = <fs_stpo>-meins.
    199           <fs_cwa>-posnr = space.
    200           unassign <fs_cwa>.
    201 
    202           read table add_wa assigning <fs_addwa>
    203           with key stlkn = <fs_wa>-stlkn
    204                    stpoz = <fs_wa>-stpoz.
    205           if sy-subrc = 0.
    206             append initial line to lt_addwa assigning <fs_cadd>.
    207             move-corresponding <fs_addwa> to <fs_cadd>.
    208             <fs_cadd>-index = space.
    209             unassign:<fs_addwa>,<fs_cadd>.
    210           endif.
    211         endif.
    212       endloop.
    213     endif.
    214   endloop.
    215 
    216   if lt_wa[] is not initial.
    217     clear:lv_index,lv_posnr.
    218 
    219     sort wa     by posnr descending.
    220     sort add_wa by index descending.
    221 
    222     read table wa assigning <fs_wa> index 1.
    223     if sy-subrc = 0.
    224       lv_posnr = <fs_wa>-posnr.
    225     endif.
    226 
    227     read table add_wa assigning <fs_addwa> index 1.
    228     if sy-subrc = 0.
    229       lv_index = <fs_addwa>-index.
    230     endif.
    231 
    232     loop at lt_wa assigning <fs_cwa>
    233     where posnr = space.
    234       lv_posnr = lv_posnr + 10.
    235 
    236       call function 'CONVERSION_EXIT_ALPHA_INPUT'
    237         exporting
    238           input         = lv_posnr
    239         importing
    240           output        = lv_posnr .
    241 
    242       <fs_cwa>-posnr = lv_posnr.
    243     endloop.
    244 
    245     loop at lt_addwa assigning <fs_cadd>
    246     where index = space.
    247       lv_index = lv_index + 1.
    248       <fs_cadd>-index = lv_index.
    249     endloop.
    250 
    251     append lines of lt_wa[] to wa[].
    252     append lines of lt_addwa[] to add_wa[].
    253   endif.
    254 
    255 endif.

    2.系统测试

     2.1基础数据

      

      整车物料:TWL-ZZCH-003

      总成件:TWL0824(包含子件TWL0825)

      

      总成件TWL0824为委外件(类型CSMT-A)

      

      配置表ZTMM0093_MRP_WRK :工厂3302启用BOM层级子件运算,对应的事务码:MD41/MD42/CK11N

     2.2测试-MRP运行

      创建独立需求MD61:

      

      MRP运行MD41:

      

      查看子件 TWL0825 需求清单MD04:

      

       查看整车TWL-ZZCH-003成本核算CK11N:总成件TWL0824与其子件TWL0825都进行核算

  • 相关阅读:
    日本语教育文法ナ イ形容词
    日本语教育文法和国语教育文法
    Multisim note
    莫比乌斯反演
    【NOIP2015】斗地主(dfs)
    【SCOI2007】降雨量(线段树+讨论)
    CF559C Gerald and Giant Chess(计数DP)
    【NOIP2012】开车旅行(倍增+STL)
    Apache Flink目录遍历(CVE-2020-17519)
    CTF文件包含
  • 原文地址:https://www.cnblogs.com/ricoo/p/10066165.html
Copyright © 2011-2022 走看看