物料異動函式BAPI_GOODSMVT_CREATE的使用

TolyHuang發表於2007-11-22
收貨、發貨可使用BAPI_GOODSMVT_CREATE函式進行操作,具體操作程式碼如下:[@more@]

data: gdsmt_header like bapi2017_gm_head_01.
data: gdsmt_code like bapi2017_gm_code.
data: gdsmt_item like bapi2017_gm_item_create occurs 0 with header line.
data: return like bapiret2 occurs 0.

clear: gdsmt_header, gdsmt_code, gdsmt_item, gdsmt_item[], return.

* Setup BAPI header data.
gdsmt_header-pstng_date = sy-datum.
gdsmt_header-doc_date = sy-datum.
gdsmt_code-gm_code = '01'. "01 - MB01 - Goods Receipts for Purchase Order

* Write 101 movement to table.
loop at it_tab_edit into itab.
move '101' to gdsmt_item-move_type.
move itab-matnr to gdsmt_item-material.
move itab-erfmg to gdsmt_item-entry_qnt.
move itab-meins to gdsmt_item-entry_uom.
move itab-werks to gdsmt_item-plant.
move itab-lgort to gdsmt_item-stge_loc.
move itab-ebeln to gdsmt_item-po_number.
move itab-ebelp to gdsmt_item-po_item.
move 'B' to gdsmt_item-mvt_ind.
* move 'X' to gdsmt_item-no_more_gr. "是否標識完成收貨

append gdsmt_item.
endloop.

if not gdsmt_item[] is initial.
call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header = gdsmt_header
goodsmvt_code = gdsmt_code
tables
goodsmvt_item = gdsmt_item
return = return.

call function 'BAPI_TRANSACTION_COMMIT' .
endif.

其中 gm_code 與 Tcode對應如下:

01 -- MB01
02 -- MB31
03 -- MB1A
04 -- MB1B
05 -- MB1C
06 -- MB11
07 -- MB04

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9437124/viewspace-983217/,如需轉載,請註明出處,否則將追究法律責任。

相關文章