溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

pdm和SAP創(chuàng)建BOM接口

發(fā)布時(shí)間:2020-08-08 06:53:45 來源:ITPUB博客 閱讀:223 作者:myp9999 欄目:建站服務(wù)器

  SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style. italic; color: #808080; } .L0S32 { color: #3399FF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } </STYLE. function zcsap_mat_bom_maintain.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(MATERIAL) TYPE  CSAP_MBOM-MATNR OPTIONAL
*"     VALUE(PLANT) TYPE  CSAP_MBOM-WERKS OPTIONAL
*"     VALUE(BOM_USAGE) TYPE  CSAP_MBOM-STLAN OPTIONAL
*"     VALUE(ALTERNATIVE) TYPE  CSAP_MBOM-STLAL OPTIONAL
*"     VALUE(VALID_FROM) TYPE  CSAP_MBOM-DATUV OPTIONAL
*"     VALUE(CHANGE_NO) TYPE  CSAP_MBOM-AENNR OPTIONAL
*"     VALUE(REVISION_LEVEL) TYPE  CSAP_MBOM-REVLV OPTIONAL
*"     VALUE(I_STKO) TYPE  STKO_API01 OPTIONAL
*"     VALUE(FL_NO_CHANGE_DOC) TYPE  CAPIFLAG-NO_CHG_DOC DEFAULT SPACE
*"     VALUE(FL_COMMIT_AND_WAIT) TYPE  CAPIFLAG-COMM_WAIT DEFAULT 'X'
*"     VALUE(FL_CAD) TYPE  CSDATA-CHAR1 DEFAULT SPACE
*"     VALUE(FL_BOM_CREATE) TYPE  CSDATA-XFELD DEFAULT 'X'
*"     VALUE(FL_NEW_ITEM) TYPE  CSDATA-XFELD DEFAULT 'X'
*"     VALUE(FL_COMPLETE) TYPE  CSDATA-XFELD DEFAULT SPACE
*"     VALUE(FL_DEFAULT_VALUES) TYPE  CSDATA-XFELD DEFAULT 'X'
*"     VALUE(FL_IDENTIFY_BY_GUID) TYPE  CSDATA-XFELD DEFAULT SPACE
*"     VALUE(IS_UPDATE_STATUS) TYPE  CHAR1 DEFAULT ''
*"  EXPORTING
*"     VALUE(FL_WARNING) LIKE  CAPIFLAG-FLWARNING
*"     VALUE(O_STKO) LIKE  STKO_API02 STRUCTURE  STKO_API02
*"     VALUE(MATERIAL1) LIKE  CSAP_MBOM-MATNR
*"     VALUE(RETURN) TYPE  CHAR100
*"     VALUE(RETURN2) TYPE  CHAR100
*"     VALUE(PRO_CODE) TYPE  CHAR1
*"  TABLES
*"      T_STPO STRUCTURE  STPO_API03 OPTIONAL
*"      T_DEP_DATA STRUCTURE  CSDEP_DAT OPTIONAL
*"      T_DEP_DESCR STRUCTURE  CSDEP_DESC OPTIONAL
*"      T_DEP_ORDER STRUCTURE  CSDEP_ORD OPTIONAL
*"      T_DEP_SOURCE STRUCTURE  CSDEP_SORC OPTIONAL
*"      T_DEP_DOC STRUCTURE  CSDEP_DOC OPTIONAL
*"      T_DOC_LINK STRUCTURE  CSDOC_LINK OPTIONAL
*"      T_DMU_TMX STRUCTURE  CSDMU_TMX OPTIONAL
*"      T_LTX_LINE STRUCTURE  CSLTX_LINE OPTIONAL
*"      T_STPU STRUCTURE  STPU_API01 OPTIONAL
*"----------------------------------------------------------------------
* 項(xiàng)目文本只放在項(xiàng)目文本1,項(xiàng)目文本2放替代組,,需要將項(xiàng)目文本2中的3位替代組轉(zhuǎn)成一個(gè)2位的放入原有2位替代組

  data: w_matnr like csap_mbom-matnr.
  data w_stlan type mast-stlan.
  clear w_stlan.
  data wa_sbdkz like marc-sbdkz.
  clear wa_sbdkz.

*取物料的生命周期狀態(tài)。
  data: w_mstae type mara-mstae.



  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input  = material
    importing
      output = material.



  select single mstae into w_mstae
   from mara where matnr = material.
  if sy-subrc  eq 0.
    if w_mstae = '26' or w_mstae = '27' or w_mstae = '22' ."試產(chǎn)\生產(chǎn)\停產(chǎn)
      bom_usage = '1'.
    else.
      if w_mstae = '25'.  "開發(fā)
        bom_usage = 'A'.
      else.
        concatenate '物料:' material+9(9) '生命周期狀態(tài)不在范圍內(nèi)(22、25、26、27)' into
        return.
        pro_code = 3.

        return..
      endif.
    endif.
  else.
    concatenate '物料:' material '沒有找到生命周期狀態(tài)' into
     return.
    pro_code = 3.

    return..
  endif.

  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input  = material
    importing
      output = w_matnr.

  select single stlan into w_stlan
  from mast
  where werks = plant and matnr = w_matnr and stlan = bom_usage.



  if sy-subrc eq and w_stlan eq bom_usage.
    return 'BOM已經(jīng)存在,不用創(chuàng)建'.
    pro_code = 2.


    if pro_code eq 2.                                       "70檢查
      call function 'ZPDM_BOM_CHANGE_MAT'
        exporting
          matnr    = material
          plant_s  = plant
          stlan    = '1'
*          stlst    = 1
          p_d1     = 'X'
          return_i = return
        importing
          return_e = return
          pro_code = pro_code.
    endif.
*
    return.

  endif.

*替代組中物料和BOM中的BOM物料要相同 MODIFY BY LU.X 2010.08.09
  data i_stpo like table of stpo_api03 with header line.
  data: i_zbomstd like table of zbomstd with header line.

 "檢查下層半品是否都有BOM.
  data i_halb like table of stpo_api03 with header line."所有半品
  data l_matnr like mara-matnr."
  data l_count_halb type i.
  data l_count_mast type i.

  "檢查下層半品是否都有BOM.
  if t_stpo[] is not initial.
    select matnr
    into corresponding fields of table i_halb
    from mara
    for all entries in t_stpo
    where matnr = t_stpo-component and mtart = 'ZHLB'.

    if i_halb[] is not initial.
      loop at i_halb.
        select single matnr   "查物料BOM是否存在
        into l_matnr
        from mast
        where matnr = i_halb-component and werks = plant.

        if sy-subrc ne 0.
*          SELECT SINGLE matnr "查訂單BOM是否存在
*        INTO l_matnr
*        FROM kdst
*        WHERE matnr = i_halb-component AND werks = plant.
          concatenate '子件:' i_halb-component+9(9) '的BOM不存在,不能創(chuàng)建BOM:' into return.

          pro_code = 3.

          return..
        endif.

      endloop.



    endif.

  endif.
  clear i_zbomstd[].

  i_stpo[] = t_stpo[].





  delete i_stpo where item_text2 is initial.

  delete adjacent duplicates from i_stpo comparing item_text2.

  if i_stpo[] is not initial.

    loop at i_stpo. "計(jì)算每一個(gè)替代組中的物料和替代庫中是否完全相同


      clear i_zbomstd[].

      select alpgr matnr
      into corresponding fields of table i_zbomstd
      from zbomstd
      where alpgr = i_stpo-item_text2 and xloek ne 'X'.

      loop at i_zbomstd.
        read table t_stpo with key component = i_zbomstd-matnr+9(9) item_text2 = i_zbomstd-alpgr.
        if sy-subrc ne 0.
          concatenate '替帶庫:' i_stpo-item_text2 '中的物料:' i_zbomstd-matnr+9(9)
        '在BOM中不存在' into return.

          pro_code = 3.

          return..
        endif.



      endloop.



    endloop.


  endif.

*替代組中物料和BOM中的BOM物料要相同 MODIFY BY LU.X 2010.08.09




*  先將所有的項(xiàng)目文本二的值轉(zhuǎn)成2位的替代組。
  data: wa_item_text2 like stpo_api03-item_text2,wa_sortstring like stpo_api03-sortstring.
  data: wa_ai_group type i.
  wa_ai_group = 9.
  sort t_stpo by item_text2 sortstring."當(dāng)替代組號(hào)相同排序字符串也相同時(shí)才用相同的兩位替代組 MODIFY BY LU.X 2010.08.20
  wa_item_text2 = ''.
  wa_sortstring = ''.

  loop at t_stpo where item_text2 is not initial.
    if ( wa_item_text2 ne t_stpo-item_text2 ) or ( wa_sortstring ne t_stpo-sortstring ).
      wa_ai_group = wa_ai_group + 1.
      wa_item_text2 = t_stpo-item_text2.
      wa_sortstring = t_stpo-sortstring.
    endif.
    t_stpo-ai_group = wa_ai_group.
    modify t_stpo.
  endloop.



  tables: msta.

  i_stko-base_quan = 1.
*  I_STKO-BOM_STATUS = '01'.

  data: lt_zbomfix like table of zbomfix with header line ,lt_zbomstd like table of zbomstd with header line.

  select into corresponding fields of table lt_zbomfix
  from zbomfix .
  sort lt_zbomfix by matnr.
  select into corresponding fields of table lt_zbomstd
  from zbomstd where xloek <>'X'..
  sort lt_zbomstd by matnr.

  if t_stpo[] is initial and is_update_status = ''.
    concatenate '物料:' material '沒有子件信息,不能創(chuàng)建BOM!' into return.
    pro_code = 3.
    return..
  endif.










*檢查母件MRP視圖存在
*  data W_DISMM TYPE MARc-DISMM.
*  SELECT SINGLE DISMM INTO W_DISMM FROM MARC
*  WHERE MATNR = MATERIAL AND WERKS = PLANT.
*  IF SY-SUBRC NE 0.
*
*  ENDIF.

*
*  SELECT SINGLE * FROM msta WHERE matnr = material AND statm = 'D' AND werks = plant.
*  IF sy-subrc NE 0.
*    pro_code = 3.
*    CONCATENATE material+9(9) '母件MRP視圖未建立,不能建立BOM' INTO return.
*    return2 = return.
*    RETURN.
*  ENDIF.

  select single sbdkz into wa_sbdkz
  from marc where matnr = material and werks = plant
  and dismm is not null "MRP 類型
  and beskz is not null   "采購類型
  and mtvfp = '02'   "可用性檢查
  and sbdkz = '1'   "獨(dú)立/集中
  and sfcpf is not null.   "生產(chǎn)計(jì)劃參數(shù)文件
  if sy-subrc ne 0.
    pro_code = 3.
    concatenate material+9(9) '母件MRP視圖未建立,不能建立BOM' into return.
    return2 = return.
    return.
  endif.










*固定數(shù)量和替代組處理
  loop at t_stpo.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
      exporting
        input  = t_stpo-component
      importing
        output = t_stpo-component.


**子件MRP視圖檢查
*    SELECT SINGLE * FROM msta WHERE matnr = t_stpo-component AND statm = 'D' AND werks = plant.
*    IF sy-subrc NE 0.
*      pro_code = 3.
*      CONCATENATE t_stpo-component+9(9) '子件MRP視圖未建立,不能建立BOM' INTO return.
*      return2 = return.
*      RETURN.
*    ENDIF.
**子件MRP視圖檢查
    select single sbdkz into wa_sbdkz
 from marc where matnr = t_stpo-component and werks = plant
 and dismm is not null "MRP 類型
 and beskz is not null   "采購類型
 and mtvfp = '02'   "可用性檢查
 and sbdkz is not null.   "獨(dú)立/集中
*  AND sfcpf IS NOT NULL.   "生產(chǎn)計(jì)劃參數(shù)文件
    if sy-subrc ne 0.
      pro_code = 3.
      concatenate t_stpo-component+9(9) '子件MRP視圖未建立,不能建立BOM' into return.
      return2 = return.
      return.
    endif.




*固定數(shù)量




    read table lt_zbomfix with key matnr = t_stpo-component.
    if sy-subrc = 0.
      t_stpo-fixed_qty = 'X'.
*      modify t_stpo.
    endif.




*替代組處理
    if t_stpo-ai_group is not initial.
*      read table lt_ZBOMSTD with key matnr = t_stpo-COMPONENT ALPGR = t_stpo-ai_group.


*原來替代組放在了ITEM_TEXT2中,需要程序3位轉(zhuǎn)成兩位放入AI_GROUP
      read table lt_zbomstd with key matnr = t_stpo-component alpgr =
     t_stpo-item_text2.
      if sy-subrc = 0.
*        t_stpo-AI_GROUP = lt_ZBOMSTD-alpgr."替代項(xiàng)目:組
        t_stpo-ai_prio = lt_zbomstd-alprf."替代項(xiàng)目(優(yōu)先級(jí))
        t_stpo-usage_prob = lt_zbomstd-ewahr."使用可能性按

      else.
        concatenate '物料:' t_stpo-component+9(9) ' 替代組:'  t_stpo-item_text2 'SAP未維護(hù)' into return.
        pro_code = 3.
        return..
      endif.
    endif.
    call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
      exporting
        input  = t_stpo-component
      importing
        output = t_stpo-component.

    t_stpo-rel_cost = 'X'"成本核算標(biāo)識(shí)打鉤



    modify t_stpo.
  endloop.

  call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
    exporting
      input  = material
    importing
      output = material.

  if sy-datum <= '20100704'"為上線后可以展工單BOM成功

    call function 'CSAP_MAT_BOM_MAINTAIN'
      exporting
        material                 = material
       plant                    =  plant
        bom_usage                = bom_usage
       valid_from               =  '20100501'
       change_no                = change_no
*   REVISION_LEVEL           =
        i_stko                   = i_stko
        fl_bom_create            = fl_bom_create
        fl_new_item              = fl_new_item
*   FL_NO_CHANGE_DOC         = ' '
*   FL_COMMIT_AND_WAIT       = ' '
*   FL_CAD                   = ' '
*   FL_DEFAULT_VALUES        = 'X'
*    fl_commit_and_wait = 'X'
*    fl_default_values = 'X'
       importing
       fl_warning               =  fl_warning
      o_stko                   =  o_stko
     tables
       t_stpo                   =   t_stpo
*   T_DEP_DATA               =
*   T_DEP_DESCR              =
*   T_DEP_ORDER              =
*   T_DEP_SOURCE             =
*   T_DEP_DOC                =
*   T_LTX_LINE               =
       t_stpu                   = t_stpu
     exceptions
       error                    = 1
       others                   2.
  else.
    call function 'CSAP_MAT_BOM_MAINTAIN'
   exporting
     material                 = material
    plant                    =  plant
     bom_usage                = bom_usage
*     valid_from               =  SY-DATUM
    change_no                = change_no
*   REVISION_LEVEL           =
     i_stko                   = i_stko
     fl_bom_create            = fl_bom_create
     fl_new_item              = fl_new_item
*   FL_NO_CHANGE_DOC         = ' '
*   FL_COMMIT_AND_WAIT       = ' '
*   FL_CAD                   = ' '
*   FL_DEFAULT_VALUES        = 'X'
*    fl_commit_and_wait = 'X'
*    fl_default_values = 'X'
    importing
    fl_warning               =  fl_warning
   o_stko                   =  o_stko
  tables
    t_stpo                   =   t_stpo
*   T_DEP_DATA               =
*   T_DEP_DESCR              =
*   T_DEP_ORDER              =
*   T_DEP_SOURCE             =
*   T_DEP_DOC                =
*   T_LTX_LINE               =
    t_stpu                   = t_stpu
  exceptions
    error                    = 1
    others                   2.


  endif.

  commit work.
  if  sy-msgty ne 'S'.
    pro_code = 3.
  else.
    pro_code = 2.
  endif.

  clear t_stpo[].
  clear t_stpu[].

  call function 'MESSAGE_TEXT_BUILD'
    exporting
      msgid               = sy-msgid
      msgnr               = sy-msgno
      msgv1               = sy-msgv1
      msgv2               = sy-msgv2
      msgv3               = sy-msgv3
      msgv4               = sy-msgv4
    importing
      message_text_output = return.



  if sy-subrc <> 0.
    return2 = return+12(10).
    write:/    '建立時(shí)錯(cuò)誤信息:','工廠:',plant, return2 color col_negative.
*    WRITE: return2.
  else.
    write:/ return2.
    write:/ '建立時(shí)信息:','工廠:',plant,return color col_positive.
  endif.

  if pro_code eq 2.
    call function 'ZPDM_BOM_CHANGE_MAT'
      exporting
       matnr          = material
       plant_s        = plant
       stlan          = bom_usage
*       stlst          = 1
       p_d1           = 'X'
*    aennr          = aennr
        return_i       = return
     importing
       return_e       = return
       pro_code       = pro_code
              .

  endif.
  data: plnnr_001 like bdcdata-fval,
  matnr_001 like bdcdata-fval.
  data: l_mstae like mara-mstae.
  data: l_subrc like syst-subrc.
  data: l_mtart like mara-mtart.

  call function 'CONVERSION_EXIT_ALPHA_INPUT'
    exporting
      input  = material
    importing
      output = material.

  select single mstae mtart
  into (l_mstae,l_mtart)
  from mara
  where matnr eq material .

  if l_mstae eq 27 or plant ne '1000'."當(dāng)物料狀態(tài)是生產(chǎn)或工廠不是1000時(shí)不執(zhí)行分配參考工藝路線
    exit.
  endif.




  if l_mtart eq 'ZFRT'.
    plnnr_001 = '90000008'.
  else.
    plnnr_001 = '90000007'.
  endif.


  call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
    exporting
      input  = material
    importing
      output = matnr_001.


  call function 'ZCA12'
   exporting
*     CTU                 = 'X'
*     MODE                = 'N'
*     UPDATE              = 'L'
*     GROUP               = GROUP
*     USER                = USER
*     KEEP                = KEEP
*     HOLDDATE            = HOLDDATE
*     NODATA              = '/'
     plnnr_001           = plnnr_001
*     STTAG_002           = '2011.05.18'
*     PLNAL_003           = '1'
*     ENTRY_ACT_004       = '1'
     matnr_01            =  matnr_001
*     WERKS_01            = '1000'
*     ENTRY_ACT_008       = '1'
   importing
     subrc               = l_subrc
*   TABLES
*     MESSTAB             = MESSTAB
            .

  if l_subrc ne 0.
    concatenate return '給物料分配參考工藝路線失敗' into return.
  else.
    concatenate return '給物料分配參考工藝路線成功' into return.

  endif.




endfunction.
SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } </STYLE.

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI