基于SAP采购订单的收货可使用物料移动中常用的Bapi函数“BAPI_GOODSMVT_CREATE”来处理,其中GOODSMVT_CODE采用“01”,也就是MB01界面的功能。其中支持多个不同采购订单的收货,最后不会忘记Commit提交,否则只会产生物料凭证,而不会实质记录。
下面是一个测试Demo。
*&---------------------------------------------------------------------*
*& Report ZTEST_POGR
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTEST_POGR.
START-OF-SELECTION.
DATA: LS_HEADER LIKE BAPI2017_GM_HEAD_01,
LV_CODE LIKE BAPI2017_GM_CODE VALUE '01',
LV_DOC TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_YEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR,
LT_ITEM LIKE BAPI2017_GM_ITEM_CREATE OCCURS 0 WITH HEADER LINE,
LT_RET LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
*** Header
LS_HEADER-PSTNG_DATE = '20160701'.
LS_HEADER-DOC_DATE = '20160701'.
LS_HEADER-HEADER_TXT = 'Header Text'.
*** Item
LT_ITEM-MATERIAL = 'F-F-H300'.
PERFORM CONVERSION_EXIT_MATN1_INPUT USING LT_ITEM-MATERIAL.
LT_ITEM-VENDOR = 'H5Q9'.
PERFORM CONVERSION_EXIT_ALPHA_INPUT USING LT_ITEM-VENDOR.
LT_ITEM-PLANT = 'CN32'.
LT_ITEM-PO_NUMBER = '4500039125'.
LT_ITEM-PO_ITEM = '10'.
PERFORM CONVERSION_EXIT_MATN1_INPUT USING LT_ITEM-PO_ITEM.
LT_ITEM-ITEM_TEXT = LT_ITEM-PO_ITEM.
LT_ITEM-ENTRY_QNT = 10.
LT_ITEM-STGE_LOC = 'RC10'.
LT_ITEM-MVT_IND = 'B'.
LT_ITEM-MOVE_TYPE = '101'.
LT_ITEM-ENTRY_UOM = 'EA'.
APPEND LT_ITEM.CLEAR LT_ITEM.
LT_ITEM-MATERIAL = 'C-S1-300'.
PERFORM CONVERSION_EXIT_MATN1_INPUT USING LT_ITEM-MATERIAL.
LT_ITEM-VENDOR = 'H5Q9'.
PERFORM CONVERSION_EXIT_ALPHA_INPUT USING LT_ITEM-VENDOR.
LT_ITEM-PLANT = 'CN32'.
LT_ITEM-PO_NUMBER = '4500039124'.
LT_ITEM-PO_ITEM = '10'.
PERFORM CONVERSION_EXIT_MATN1_INPUT USING LT_ITEM-PO_ITEM.
LT_ITEM-ITEM_TEXT = LT_ITEM-PO_ITEM.
LT_ITEM-ENTRY_QNT = 10.
LT_ITEM-STGE_LOC = 'RC10'.
LT_ITEM-MVT_IND = 'B'.
LT_ITEM-MOVE_TYPE = '101'.
LT_ITEM-ENTRY_UOM = 'EA'.
APPEND LT_ITEM.CLEAR LT_ITEM.
"过账
PERFORM BAPI_GOODS_MOVE TABLES LT_ITEM LT_RET
USING LS_HEADER LV_CODE LV_DOC LV_YEAR .
COMMIT WORK.
WRITE : / LV_DOC,LV_YEAR.
IF LT_RET[] IS NOT INITIAL.
LOOP AT LT_RET.
WRITE : / LT_RET-TYPE,LT_RET-MESSAGE.
ENDLOOP.
ENDIF.
*&---------------------------------------------------------------------*
*& Form BAPI_GOODS_MOVE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_ITEM text
* -->P_LT_RET text
* -->P_LS_HEADER text
* -->P_LV_CODE text
* -->P_LV_DOC text
* -->P_LV_YEAR text
*----------------------------------------------------------------------*
FORM BAPI_GOODS_MOVE TABLES LT_ITEM STRUCTURE BAPI2017_GM_ITEM_CREATE
LT_RET STRUCTURE BAPIRET2
USING LS_HEADER STRUCTURE BAPI2017_GM_HEAD_01
LV_CODE
LV_DOC
LV_YEAR.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LS_HEADER
GOODSMVT_CODE = LV_CODE
IMPORTING
MATERIALDOCUMENT = LV_DOC
MATDOCUMENTYEAR = LV_YEAR
TABLES
GOODSMVT_ITEM = LT_ITEM
RETURN = LT_RET.
ENDFORM. " BAPI_GOODS_MOVE
*&---------------------------------------------------------------------*
*& Form CONVERSION_EXIT_MATN1_INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_MATNR text
*----------------------------------------------------------------------*
FORM CONVERSION_EXIT_MATN1_INPUT USING P_MATNR.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
INPUT = P_MATNR
IMPORTING
OUTPUT = P_MATNR
EXCEPTIONS
LENGTH_ERROR = 1
OTHERS = 2.
ENDFORM. " CONVERSION_EXIT_MATN1_INPUT
*&---------------------------------------------------------------------*
*& Form CONVERSION_EXIT_ALPHA_INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_101_LIFNR text
*----------------------------------------------------------------------*
FORM CONVERSION_EXIT_ALPHA_INPUT USING P_LIFNR.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = P_LIFNR
IMPORTING
OUTPUT = P_LIFNR.
ENDFORM. " CONVERSION_EXIT_ALPHA_INPUT
附加内容:
GMCODE TCODE:
- GM_Code 01: Goods receipt for purchase order
- GM_Code 02: Goods receipt for production order
- GM_Code 03: Goods issue
- GM_Code 04: Transfer posting
- GM_Code 05: Other goods receipts
- GM_Code 06: Reversal of goods movements
- GM_Code 07: Subsequent adjustment to a subcontract order