1. 程式人生 > >物料主資料批導 BAPI_MATERIAL_SAVEDATA

物料主資料批導 BAPI_MATERIAL_SAVEDATA

物料批量匯入,檢視擴充套件注意這個bapi無法實現分類檢視和質量檢視的擴充套件,這個2個檢視需要單獨呼叫2個bapi 分類檢視BAPI:BAPI_OBJCL_CREATE和質量檢視BAPI BAPI_MATINSPCTRL_SAVEREPLICA 這2個bapi必須在下邊bapi成功以後 才能使用

&---------------------------------------------------------------------
*& Form FRM_IMPORT_DATA
&---------------------------------------------------------------------

  •   text
    

----------------------------------------------------------------------

  • –> p1 text
  • <-- p2 text
    ----------------------------------------------------------------------
    FORM frm_import_data .
    DATA: lv_line(10),
    lv_percent(6),
    lv_text(40).
    DATA: ls_header LIKE bapimathead,
    ls_ebew TYPE ebew.

CLEAR: gw_data.
LOOP AT gt_data INTO gw_data WHERE box = ‘X’.
CLEAR :
wa_mbew,
wa_mbewx.
PERFORM frm_add_zero USING gw_data-matnr CHANGING gw_data-matnr."物料號補0

  • TRANSLATE gw_data-lgort TO UPPER CASE.
    lv_line = lv_line + 1.
    lv_percent = lv_line * 100 / g_lines.
    CONCATENATE ‘已完成’ lv_line ‘條/’ g_lines ‘條’ INTO lv_text.
    CONDENSE lv_text.
    CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR’
    EXPORTING
    percentage = lv_percent
    text = lv_text.
CLEAR: lv_percent,lv_text.
CLEAR: wa_header.

*物料擡頭資訊
wa_header-material = gw_data-matnr."物料號
wa_header-matl_type = gw_data-mtart."物料型別

*啟用的擴充套件檢視
wa_header-basic_view = gc_x.
wa_header-purchase_view = gw_data-kz_cgview."擴展采購檢視
wa_header-mrp_view = gw_data-kz_scview."生產檢視

  • wa_header-account_cost_view = gw_data-kz_kjview."會計檢視
    wa_header-storage_view = gc_x.
    wa_header-sales_view = gw_data-kz_xsview."擴充套件銷售檢視
IF gw_data-kz_kjview = gc_x.
  wa_header-account_view = gc_x.
  wa_header-cost_view = gc_x.
ENDIF.

*----------mara-------------------------------------------------
IF gw_data-meins IS NOT INITIAL.
CALL FUNCTION ‘CONVERSION_EXIT_CUNIT_INPUT’
EXPORTING
input = gw_data-meins

  •     LANGUAGE             = SY-LANGU
      IMPORTING
        output = gw_data-meins.
    wa_mara-base_uom                     = gw_data-meins."基本計量單位
    wa_marax-base_uom                    = gc_x."基本計量單位
    

    ENDIF.

    IF gw_data-mhdrz IS NOT INITIAL.
    wa_mara-minremlife = gw_data-mhdrz."最小剩餘貨架壽命
    wa_marax-minremlife = gc_x."最小剩餘貨架壽命
    ENDIF.

    IF gw_data-mhdhb IS NOT INITIAL.
    wa_mara-shelf_life = gw_data-mhdhb."總貨架壽命
    wa_marax-shelf_life = gc_x."總貨架壽命
    ENDIF.
    IF gw_data-iprkz IS NOT INITIAL.

  •  PERIOD_IND_EXPIRATION_DATE
    CALL FUNCTION 'CONVERSION_EXIT_PERKZ_INPUT'
      EXPORTING
        input  = gw_data-iprkz
      IMPORTING
        output = wa_mara-period_ind_expiration_date.
    
  •  wa_mara-period_ind_expiration_date  = gw_data-iprkz."貨架壽命到期日的期間標識
    wa_marax-period_ind_expiration_date  = gc_x."貨架壽命到期日的期間標識
    

    ENDIF.

  • wa_mara-shelf_life = gw_data-mhdhb."總貨架壽命
    *----------marc-------------------------------------------------
    IF gw_data-werks IS NOT INITIAL.
    wa_marc-plant = gw_data-werks."工廠
    wa_marcx-plant = gw_data-werks."工廠
    ENDIF.

IF gw_data-xchpf IS NOT INITIAL.
  wa_marc-batch_mgmt        = gw_data-xchpf."批次管理
  wa_marcx-batch_mgmt        = gc_x."批次管理
ENDIF.

IF gw_data-xchpf IS NOT INITIAL.
  wa_marc-batch_mgmt        = gw_data-xchpf."批次管理
  wa_marcx-batch_mgmt        = gc_x."批次管理
ENDIF.
IF gw_data-ekgrp IS NOT INITIAL.
  wa_marc-pur_group         = gw_data-ekgrp."採購組
  wa_marcx-pur_group         = gc_x."採購組
ENDIF.
IF gw_data-dismm IS NOT INITIAL.
  wa_marc-mrp_type          = gw_data-dismm."MRP型別
  wa_marcx-mrp_type          = gc_x."MRP型別
ENDIF.
  • IF gw_data-disgr IS NOT INITIAL.
    wa_marc-mrp_group = gw_data-disgr."MRP組
    wa_marcx-mrp_group = gc_x."MRP組
    ENDIF.

  • IF gw_data-dispo IS NOT INITIAL.
    wa_marc-mrp_ctrler = gw_data-dispo."MRP控制者
    wa_marcx-mrp_ctrler = gc_x.
    ENDIF.

  • IF gw_data-disls IS NOT INITIAL.
    wa_marc-lotsizekey = gw_data-disls."批量大小
    wa_marcx-lotsizekey = gc_x.
    ENDIF.

*BESKZ
IF gw_data-beskz IS NOT INITIAL.
wa_marc-proc_type = gw_data-beskz."採購型別
wa_marcx-proc_type = gc_x.
ENDIF.
*
IF gw_data-kzkup IS NOT INITIAL.
wa_marc-co_product = gw_data-kzkup."聯產品
wa_marcx-co_product = gc_x."聯產品
ENDIF.
*
IF gw_data-lgpro IS NOT INITIAL.
wa_marc-iss_st_loc = gw_data-lgpro."生產倉儲地點
wa_marcx-iss_st_loc = gc_x."生產倉儲地點
ENDIF.

  • IF gw_data-dzeit IS NOT INITIAL.
    wa_marc-inhseprodt = gw_data-dzeit."自制生產
    wa_marcx-inhseprodt = gc_x."自制生產
    ENDIF.

  • IF gw_data-webaz IS NOT INITIAL.
    wa_marc-gr_pr_time = gw_data-webaz."收貨處理時間
    wa_marcx-gr_pr_time = gc_x."收貨處理時間
    ENDIF.

  • IF gw_data-plifz IS NOT INITIAL.
    wa_marc-plnd_delry = gw_data-plifz."計劃交貨時間
    wa_marcx-plnd_delry = gc_x."計劃交貨時間
    ENDIF.

  • IF gw_data-fhori IS NOT INITIAL.
    wa_marc-sm_key = gw_data-fhori."計劃邊際碼
    wa_marcx-sm_key = gc_x."計劃邊際碼
    ENDIF.

  • IF gw_data-mtvfp_g IS NOT INITIAL.
    wa_marc-availcheck = gw_data-mtvfp_g."可用性檢查的檢查組
    wa_marcx-availcheck = gc_x."可用性檢查的檢查組
    ENDIF.

  • IF wa_marc-availcheck IS INITIAL.
    IF gw_data-mtvfp IS NOT INITIAL.
    wa_marc-availcheck = gw_data-mtvfp."可用性檢查的檢查組
    wa_marcx-availcheck = gc_x."可用性檢查的檢查組
    ENDIF.
    ENDIF.

  • IF gw_data-altsl IS NOT INITIAL.
    wa_marc-alt_bom_id = gw_data-altsl."選擇方法
    wa_marcx-alt_bom_id = gc_x."選擇方法
    ENDIF.

  • IF gw_data-ueetk IS NOT INITIAL .
    wa_marc-unlimited = gw_data-ueetk."允許無限過量交貨
    wa_marcx-unlimited = gc_x."允許無限過量交貨
    ENDIF.

  • IF gw_data-frtme IS NOT INITIAL.
    wa_marc-prod_unit = gw_data-frtme."生產單位
    wa_marcx-prod_unit = gc_x."生產單位
    ENDIF.

  • IF gw_data-prctr IS NOT INITIAL.
    wa_marc-profit_ctr = gw_data-prctr."允許無限過量交貨
    wa_marcx-profit_ctr = gc_x."允許無限過量交貨
    ENDIF.

  • 差異碼
    IF gw_data-awsls IS NOT INITIAL.
    wa_marc-variance_key = gw_data-awsls."差異碼
    wa_marcx-variance_key = gc_x.
    ENDIF.

  • IF gw_data-ueetk IS NOT INITIAL.
    wa_marc-unlimited = gw_data-ueetk."允許無限過量交貨
    wa_marcx-unlimited = gc_x."允許無限過量交貨
    ENDIF.

    IF gw_data-ladgr IS NOT INITIAL.
    wa_marc-loadinggrp = gw_data-ladgr."裝載組
    wa_marcx-loadinggrp = gc_x."裝載組
    ENDIF.

*MBEW
IF gw_data-werks IS NOT INITIAL.
wa_mbew-val_area = gw_data-werks."工廠
wa_mbewx-val_area = gw_data-werks."工廠
ENDIF.
*
IF gw_data-bklas IS NOT INITIAL.
wa_mbew-val_class = gw_data-bklas."評估分類
wa_mbewx-val_class = gc_x."評估分類
ENDIF.

  • IF gw_data-bwtty IS NOT INITIAL.
    wa_mbew-val_cat = gw_data-bwtty."評估類別
    wa_mbewx-val_cat = gc_x."評估類別
    ENDIF.

  • IF gw_data-mlast IS NOT INITIAL.
    wa_mbew-ml_settle = gw_data-mlast."價格確定
    wa_mbewx-ml_settle = gc_x."價格確定
    ENDIF.

  • IF gw_data-vprsv IS NOT INITIAL.
    wa_mbew-price_ctrl = gw_data-vprsv."價格控制
    wa_mbewx-price_ctrl = gc_x."價格控制
    ENDIF.
    *標準價格

    IF wa_mbew-price_ctrl = ‘S’.

  • 標準價格
    CLEAR :gv_std_price.
    gv_std_price = gw_data-stprs.
    IF gv_std_price IS NOT INITIAL .
    wa_mbew-std_price = gv_std_price.
    wa_mbewx-std_price = gc_x.
    ENDIF.

    ELSEIF wa_mbew-price_ctrl = ‘V’.
    CLEAR :gv_std_price.
    gv_std_price = gw_data-stprs.
    wa_mbew-std_price = gv_std_price.
    wa_mbewx-std_price = gc_x.
    IF gw_data-pvprs IS NOT INITIAL.
    wa_mbew-moving_pr = gw_data-pvprs.
    wa_mbewx-moving_pr = gc_x.
    ELSE.
    IF gw_data-stprs IS NOT INITIAL.
    wa_mbew-moving_pr = gw_data-stprs.
    wa_mbewx-moving_pr = gc_x.
    ENDIF.
    ENDIF.

    ENDIF.
    IF gw_data-peinh IS NOT INITIAL.
    wa_mbew-price_unit = gw_data-peinh.“價格單位
    wa_mbewx-price_unit = gc_x.”
    ENDIF.

  • 用QS的成本核算
    IF gw_data-ekalr IS NOT INITIAL.
    wa_mbew-qty_struct = gw_data-ekalr."用QS的成本核算
    wa_mbewx-qty_struct = gc_x.
    ENDIF.

  • 物料來源
    IF gw_data-hkmat IS NOT INITIAL.
    wa_mbew-orig_mat = gw_data-hkmat."用QS的成本核算
    wa_mbewx-orig_mat = gc_x.
    ENDIF.
    --------------------------------------------------

  • 銷售組織
    IF gw_data-vkorg IS NOT INITIAL.
    wa_mvke-sales_org = gw_data-vkorg.
    wa_mvkex-sales_org = gw_data-vkorg.
    ENDIF.

  • 分銷渠道
    IF gw_data-vtweg IS NOT INITIAL.
    wa_mvke-distr_chan = gw_data-vtweg.
    wa_mvkex-distr_chan = gw_data-vtweg.
    ENDIF.

  • 產品層次
    IF gw_data-prodh IS NOT INITIAL.
    wa_mvke-prod_hier = gw_data-prodh."產品層次
    wa_mvkex-prod_hier = gc_x."產品層次
    ENDIF.

  • 銷售單位
    IF gw_data-vrkme IS NOT INITIAL.
    wa_mvke-sales_unit = gw_data-vrkme."銷售單位
    wa_mvkex-sales_unit = gc_x."銷售單位
    ENDIF.

  • 交貨工廠
    IF gw_data-dwerk IS NOT INITIAL.
    wa_mvke-delyg_plnt = gw_data-dwerk."交貨工廠
    wa_mvkex-delyg_plnt = gc_x."交貨工廠
    ENDIF.

  • 物料統計組
    IF gw_data-versg IS NOT INITIAL.
    wa_mvke-matl_stats = gw_data-versg."物料統計組
    wa_mvkex-matl_stats = gc_x."物料統計組
    ENDIF.

  • 科目設定組
    IF gw_data-ktgrm IS NOT INITIAL.
    wa_mvke-acct_assgt = gw_data-ktgrm."物料統計組
    wa_mvkex-acct_assgt = gc_x."物料統計組
    ENDIF.

  • 專案類別組
    IF gw_data-mtpos IS NOT INITIAL.
    wa_mvke-item_cat = gw_data-mtpos."專案類別組
    wa_mvkex-item_cat = gc_x."專案類別組
    ENDIF.

  • 專案類別組
    IF gw_data-prat1 IS NOT INITIAL.
    wa_mvke-prod_att_1 = gw_data-prat1."是否噴碼
    wa_mvkex-prod_att_1 = gc_x."是否噴碼
    ENDIF.

    "稅分類
    CLEAR:it_mlan[].
    IF gw_data-kz_xsview = ‘X’.
    IF gw_data-taxkm IS NOT INITIAL.
    it_mlan-depcountry = ‘CN’.
    it_mlan-depcountry_iso = ‘CN’.
    it_mlan-tax_type_1 = ‘MWST’.
    it_mlan-taxclass_1 = gw_data-taxkm.
    APPEND it_mlan.
    ENDIF.
    ENDIF.
    CLEAR: wa_return.

  • 增加銷售檢視舊物料號
    IF gw_data-kz_xsview = ‘X’.
    t_extensionin-structure = ‘BAPI_TE_MVKE’.

  wa_temvke-sales_org  = gw_data-vkorg.
  wa_temvke-distr_chan = gw_data-vtweg.
  CONDENSE gw_data-zbismt.
  wa_temvke-zbismt = gw_data-zbismt.
  wa_temvke-vrkme  = gw_data-vrkme.
  t_extensionin-valuepart1 = wa_temvke.
  APPEND  t_extensionin.
  t_extensioninx-structure = 'BAPI_TE_MVKEX'.
  wa_temvkex-sales_org  = gw_data-vkorg.
  wa_temvkex-distr_chan = gw_data-vtweg.
  wa_temvkex-zbismt = 'X'.
  wa_temvkex-vrkme = 'X'.
  t_extensioninx-valuepart1 = wa_temvkex.
  APPEND  t_extensioninx.
  CLEAR:
    wa_temvke,
    wa_temvkex.
ENDIF.
  • IF gw_data-sd_text IS NOT INITIAL.
  •  CLEAR: it_mltx,ls_mltx.
    
  •  ls_mltx-applobject  = 'MVKE'.
    
  •  ls_mltx-text_name+0(18) = gw_data-matnr.
    
  •  ls_mltx-text_name+18(4) = gw_data-vkorg.
    
  •  ls_mltx-text_name+22(2) = gw_data-vtweg.
    
  •  ls_mltx-text_id     = '0001'.
    
  •  ls_mltx-langu       = sy-langu.
    
  •  "ls_mltx-format_col  = ''.
    
  •  ls_mltx-text_line   = gt_itab-sd_text.
    
  •  APPEND ls_mltx TO it_mltx.
    
  • ENDIF.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
  EXPORTING
    headdata           = wa_header
    clientdata         = wa_mara
    clientdatax        = wa_marax
    plantdata          = wa_marc
    plantdatax         = wa_marcx
    valuationdata      = wa_mbew
    valuationdatax     = wa_mbewx
    salesdata          = wa_mvke
    salesdatax         = wa_mvkex
  IMPORTING
    return             = wa_return
  TABLES
    materiallongtext   = it_mltx
    taxclassifications = it_mlan
    extensionin        = t_extensionin
    extensioninx       = t_extensioninx.

IF wa_return-type = 'E' OR wa_return-type = 'A'.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  gw_data-msg = wa_return-message.
  gw_data-status = '@[email protected]'.
ELSE.
  COMMIT WORK.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = gc_x.
  MESSAGE s001(zcoft) WITH '檢視擴充套件成功' INTO gw_data-msg.
  gw_data-status = '@[email protected]'.
ENDIF.
MODIFY gt_data FROM gw_data TRANSPORTING status msg.
CLEAR: wa_header,wa_mara,wa_marax,wa_marc,wa_marcx,wa_mard,wa_mardx,

wa_mbew,wa_mbewx,wa_mvke,wa_mvkex,wa_return.
CLEAR: it_makt,it_marm,it_marmx,it_mlan,it_makt[],it_marm[],it_marmx[],
it_mlan[].

CLEAR:t_extensionin[],t_extensioninx[],t_extensionin,t_extensioninx.
CLEAR:gw_data.

ENDLOOP.
ENDFORM.

分類檢視擴充套件
DATA: l_key TYPE bapi1003_key-object.
DATA:
it_return TYPE bapiret2 OCCURS 0,
w_return TYPE bapiret2.

REFRESH it_return.
CALL FUNCTION ‘BAPI_OBJCL_CREATE’
EXPORTING
objectkeynew = ‘000000000000110010’ "物料號或者裝置號
objecttablenew = ‘MARA’ "主資料表 如果是裝置就是“EQUI”
classnumnew = ‘Z_BATCH01’ "
classtypenew = ‘022’ "類別種類
standardclass = ‘X’
TABLES
return = it_return.
READ TABLE it_return INTO w_return WITH KEY type = ‘E’ id = ‘CL’ number = ‘731’.
IF sy-subrc = 0.
DELETE it_return INDEX sy-tabix.
ENDIF.
READ TABLE it_return INTO w_return WITH KEY type = ‘E’.
IF sy-subrc = 0.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.

  • return-message = return-message && ‘/’ && w_return-message.
  •  concatenate '分類特性建立失敗!'(091) RETURN-MESSAGE into RETURN-MESSAGE separated by '/'.
    

ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = ‘X’.
ENDIF.

*REFRESH it_return.
LOOP AT it_return INTO w_return .
WRITE : / w_return-type.
ENDLOOP.

在這裡插入圖片描述