BAPI_GOODSMVT_CREATE的参数GOODSMVT_CODE的说明
其功能就是用于货物移动,其主要可以实现MB*事物的一些功能,其中该BAPI的参数
GOODSMVT_CODE就控制了对应哪个事物码的功能,下面给出该参数的值和对应的事务码:
01 MB01
02 MB31
03 MB1A
04 MB1B
05 MB1C
06 MB11
07 MB04
这些值存储在表T158G中。
MVT_IND
* Domain: KZBEW - Movement Indicator
* Goods movement w/o reference
* B - Goods movement for purchaseorder
* F - Goods movement for productionorder
* L - Goods movement for deliverynote
* K - Goods movement for kanbanrequirement (WM - internal only)
* O - Subsequent adjustment of"material-provided" consumption
* W - Subsequent adjustment ofproportion/product unit material
洋河案例: 回酒入库
FORM excute_bapi USING pw_table STRUCTUREgw_table
CHANGINGp_type
p_message.
DATA: ls_goodsmvt_header TYPEbapi2017_gm_head_01,
ls_goodsmvt_code TYPEbapi2017_gm_code.
DATA: lt_goodsmvt_item TYPE TABLE OFbapi2017_gm_item_create,
ls_goodsmvt_item TYPEbapi2017_gm_item_create.
DATA: pz1 TYPE bapi2017_gm_head_ret-mat_doc,
pz1year TYPEbapi2017_gm_head_ret-doc_year,
pz2 TYPEbapi2017_gm_head_ret-mat_doc,
pz2year TYPEbapi2017_gm_head_ret-doc_year,
pz3 TYPEbapi2017_gm_head_ret-mat_doc,
pz3year TYPEbapi2017_gm_head_ret-doc_year.
DATA: lt_return TYPE TABLE OF bapiret2,
ls_return TYPEbapiret2.
*&---------------------------------------------------------------------*
*& 回酒入库
*&---------------------------------------------------------------------*
"header
ls_goodsmvt_header-pstng_date =pw_table-zredat. "凭证中的过帐日期
ls_goodsmvt_header-doc_date = sy-datum. "凭证中的凭证日期
ls_goodsmvt_header-pr_uname = sy-uname. "制单人
ls_goodsmvt_code-gm_code = '05'. "MB1C依据生产订单收货
"items
ls_goodsmvt_item-orderid = pw_table-aufnr. "生产订单号
ls_goodsmvt_item-order_itno = '0001'. "订单项目编号
ls_goodsmvt_item-plant =pw_table-werks_bz. "包装公司工厂
ls_goodsmvt_item-stge_loc = 'X001'. "包装公司仓库
pw_table-lgort_bz = 'X001'. "包装公司仓库
* ls_goodsmvt_item-mvt_ind = 'F'. "有关生产单的货物移动
ls_goodsmvt_item-batch =pw_table-batch. "批次
ls_goodsmvt_item-move_type = '531'. "移动类型
ls_goodsmvt_item-material = pw_table-matnr. "物料
ls_goodsmvt_item-entry_qnt = pw_table-menge. "数量
ls_goodsmvt_item-entry_uom = pw_table-meins. "单位
APPEND ls_goodsmvt_item TOlt_goodsmvt_item.
CALL FUNCTION'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = ls_goodsmvt_header
goodsmvt_code =ls_goodsmvt_code
IMPORTING
materialdocument = pz1
matdocumentyear = pz1year
TABLES
goodsmvt_item =lt_goodsmvt_item
return = lt_return.
READ TABLE lt_return INTO ls_returnWITH KEY type = 'E'.
IF sy-subrc = 0.
CALL FUNCTION'BAPI_TRANSACTION_ROLLBACK'.
p_type ='E'.
p_message =ls_return-message.
ELSE.
CALL FUNCTION'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
*&---------------------------------------------------------------------*
*& 回酒出库
*&---------------------------------------------------------------------*
REFRESHlt_goodsmvt_item.
CLEAR: ls_goodsmvt_item-move_type.
ls_goodsmvt_item-move_type = 'ZF1'.
APPENDls_goodsmvt_item TO lt_goodsmvt_item.
REFRESHlt_return.
CALL FUNCTION'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header =ls_goodsmvt_header
goodsmvt_code = ls_goodsmvt_code
IMPORTING
materialdocument = pz2
matdocumentyear =pz2year
TABLES
goodsmvt_item = lt_goodsmvt_item
return =lt_return.
READ TABLE lt_returnINTO ls_return WITH KEY type = 'E'.
IF sy-subrc =0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
p_type = 'E'.
p_message = ls_return-message.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
*&---------------------------------------------------------------------*
*& 股份入库
*&---------------------------------------------------------------------*
REFRESH lt_goodsmvt_item.
CLEAR: ls_goodsmvt_item-orderid,
ls_goodsmvt_item-plant,
ls_goodsmvt_item-stge_loc,
ls_goodsmvt_item-move_type.
ls_goodsmvt_item-move_type = 'ZE1'.
IF pw_table-werks_bz EQ '3100'.
ls_goodsmvt_item-plant = '1100'. "股份公司工厂
ls_goodsmvt_item-stge_loc ='X001'. "股份公司仓库
pw_table-werks = '1100'."股份公司工厂
pw_table-lgort = 'X001'."股份公司仓库
ELSEIF pw_table-werks_bz EQ '3200'.
ls_goodsmvt_item-plant = '1100'. "股份公司工厂
ls_goodsmvt_item-stge_loc ='X002'. "股份公司仓库
pw_table-werks = '1100'."股份公司工厂
pw_table-lgort = 'X002'."股份公司仓库
ELSE.
ls_goodsmvt_item-plant = '1200'. "股份公司工厂
ls_goodsmvt_item-stge_loc ='X001'. "股份公司仓库
pw_table-werks = '1200'."股份公司工厂
pw_table-lgort = 'X001'."股份公司仓库
ENDIF.
ls_goodsmvt_item-item_text =pw_table-aufnr.
APPEND ls_goodsmvt_item TO lt_goodsmvt_item.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = ls_goodsmvt_header
goodsmvt_code = ls_goodsmvt_code
IMPORTING
materialdocument =pz3
matdocumentyear = pz3year
TABLES
goodsmvt_item = lt_goodsmvt_item
return = lt_return.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc = 0.
CALL FUNCTION'BAPI_TRANSACTION_ROLLBACK'.
p_type = 'E'.
p_message = ls_return-message.
ELSE.
CALL FUNCTION'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait ='X'.
p_type = 'S'.
CONCATENATE '包装公司入库凭证:' pz1 ' 包装公司出库凭证:' pz2 '股份公司入库凭证:' pz3 INTO p_message.
PERFORM write_log USING pw_table
pz1
pz2
pz3.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " EXCUTE_BAPI