*Item Parameters to be passed:
Ordered (Subcontracting) Material:
Parameter Field Description Value
GOODSMVT_ITEM MATERIAL Material Number 100-200
PLANT Plant 1000
ENTRY_QNT Quantity in Unit of Entry 0.000
MOVE_TYPE Movement Type 121
PO_NUMBER Purchase Order Number 4500000007
PO_ITEM Item Number of Purchasing Document 00010
MVT_IND Movement Indicator O
LINE_ID Unique identification of document line 000001
PARENT_ID Identifier of immediately superior line 000000
Note: Quantity of ordered material must be zero.
Component Material 1:
Parameter Field Description Value
GOODSMVT_ITEM MATERIAL Material Number 100-100
PLANT Plant 1000
ENTRY_QNT Quantity in Unit of Entry 2.000
LINE_ID Unique identification of document line 000002
PARENT_ID Identifier of immediately superior line 000001
Note: LINE_ID should be incremented for each component and the PARENT_ID remains same for all the components of an ordered material. Component negative quantity can be given in case of Under Consumption.
Component Material 2:
Parameter Field Description Value
GOODSMVT_ITEM MATERIAL Material Number 100-100
PLANT Plant 1000
ENTRY_QNT Quantity in Unit of Entry 3.000
LINE_ID Unique identification of document line 000003
PARENT_ID Identifier of immediately superior line 000001
Encapsulated function :
FUNCTION z_subcontractadjustment.
*"----------------------------------------------------------------------
*"*"Local interface:
*" EXPORTING
*" VALUE(MBLNR) TYPE MKPF-MBLNR
*" VALUE(FLAG) TYPE CHAR1
*" VALUE(MESSAGE) TYPE CHAR200
*" TABLES
*" INPUT STRUCTURE ZSUBCONTRACTADJUSTMENT_INPUT OPTIONAL
*"----------------------------------------------------------------------
DATA:goodsmvt_header TYPE bapi2017_gm_head_01.
DATA:goodsmvt_code TYPE bapi2017_gm_code.
DATA:materialdocument TYPE bapi2017_gm_head_ret-mat_doc.
DATA:matdocumentyear TYPE bapi2017_gm_head_ret-doc_year.
DATA:goodsmvt_item TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE.
DATA:return TYPE TABLE OF bapiret2 WITH HEADER LINE.
DATA:t_output TYPE TABLE OF zwms_get_sampling_info_output WITH HEADER LINE.
DATA:lv_werks LIKE ekpo-werks,
lv_lgort LIKE ekpo-lgort,
lv_meins LIKE ekpo-meins.
CLEAR goodsmvt_header.
CLEAR goodsmvt_code.
CLEAR materialdocument.
CLEAR matdocumentyear.
goodsmvt_header-pstng_date = sy-datum.
goodsmvt_header-doc_date = sy-datum.
goodsmvt_code-gm_code = '07'.
REFRESH goodsmvt_item.
CLEAR goodsmvt_item.
LOOP AT input.
goodsmvt_item-material = input-matnr. "'000000000000207560'." Material Number 100-200
goodsmvt_item-plant = input-werks. "'6100'." Plant 1000
goodsmvt_item-entry_qnt = '0'. "Quantity in Unit of Entry 0.000
goodsmvt_item-move_type = '121'. "Movement Type 121
goodsmvt_item-po_number = input-ebeln. "'4500038045'." Purchase Order Number 4500000007
goodsmvt_item-po_item = input-ebelp. "'00010'." Item Number of Purchasing Document 00010
goodsmvt_item-mvt_ind = 'O'. "Movement Indicator O
goodsmvt_item-line_id = '000001'. "Unique identification of document line 000001
goodsmvt_item-parent_id = '000000'. " Identifier of immediately superior line 000000
APPEND goodsmvt_item.
CLEAR goodsmvt_item.
"Component Material 3:
"Parameter Field Description Value
goodsmvt_item-material = input-zjtnr. "'YZCA-00019-101'. " Material Number 100-100
goodsmvt_item-plant = input-werks. "'6100'. " Plant 1000
goodsmvt_item-entry_qnt = input-entry_qnt. "'1'. " Quantity in Unit of Entry 3.000
* GOODSMVT_ITEM-LINE_ID = '000004'. "Unique identification of document line 000003
goodsmvt_item-parent_id = '000001'. " Identifier of immediately superior line 000001
goodsmvt_item-batch = input-batch. "'CPD10709'.
APPEND goodsmvt_item.
CLEAR goodsmvt_item.
ENDLOOP.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = goodsmvt_header
goodsmvt_code = goodsmvt_code
IMPORTING
materialdocument = materialdocument
matdocumentyear = matdocumentyear
TABLES
goodsmvt_item = goodsmvt_item
return = return.
IF materialdocument NE ''.
flag = 'S'.
mblnr = materialdocument.
message = '创建凭证成功!'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
flag = 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
CLEAR return.
READ TABLE return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
CONCATENATE '凭证创建失败:' return-message '!' INTO message.
ENDIF.
ENDIF.
ENDFUNCTION.