2006 Mar 19 12:06 AM
Hi, I have to do a material stock movement from one batch to another. I'm trying to use the BAPI 'BAPI_GOODSMVT_CREATE' that will allow me to
do a 309 movement. Anyone has done something similar or has an example to share? Also I want to know what data are necessary, and what fields are mandatory to assign in the item table?. Help will be appreciated. Thanks in advance.
Sebastian.
2006 Mar 19 12:48 AM
Here is some sample code from one of my programs, which does a 551 movement type. This should get you started. Just check the RETURN table for messages, they should tell you what you are missing.
* Structures for BAPI
data: gm_header type bapi2017_gm_head_01.
data: gm_code type bapi2017_gm_code.
data: gm_headret type bapi2017_gm_head_ret.
data: gm_item type table of
bapi2017_gm_item_create with header line.
data: gm_return type bapiret2 occurs 0.
data: gm_retmtd type bapi2017_gm_head_ret-mat_doc.
clear: gm_return, gm_retmtd. refresh gm_return.
* Setup BAPI header data.
gm_header-pstng_date = sy-datum.
gm_header-doc_date = sy-datum.
gm_code-gm_code = '06'. " MB11
* Write 551 movement to table
clear gm_item.
move '551' to gm_item-move_type .
move '000000000040001234' to gm_item-material.
move '1' to gm_item-entry_qnt.
move 'EA' to gm_item-entry_uom.
move '0004' to gm_item-plant.
move '4000' to gm_item-stge_loc.
move '201' to gm_item-move_reas.
* Determine cost center per plant
case xresb-werks.
when '0004'.
move '0000041430' to gm_item-costcenter.
when '0006'.
move '0000041630' to gm_item-costcenter.
when '0007'.
move '0000041731' to gm_item-costcenter.
when '0008'.
move '0000041830' to gm_item-costcenter.
endcase.
append gm_item.
* Call goods movement BAPI
call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header = gm_header
goodsmvt_code = gm_code
importing
goodsmvt_headret = gm_headret
materialdocument = gm_retmtd
tables
goodsmvt_item = gm_item
return = gm_return.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
Welcome to SDN! Please remember to award points for helpful answers and mark you post as solved when solved completely. Thanks.
REgards,
Rich Heilman
2006 Mar 19 12:48 AM
Here is some sample code from one of my programs, which does a 551 movement type. This should get you started. Just check the RETURN table for messages, they should tell you what you are missing.
* Structures for BAPI
data: gm_header type bapi2017_gm_head_01.
data: gm_code type bapi2017_gm_code.
data: gm_headret type bapi2017_gm_head_ret.
data: gm_item type table of
bapi2017_gm_item_create with header line.
data: gm_return type bapiret2 occurs 0.
data: gm_retmtd type bapi2017_gm_head_ret-mat_doc.
clear: gm_return, gm_retmtd. refresh gm_return.
* Setup BAPI header data.
gm_header-pstng_date = sy-datum.
gm_header-doc_date = sy-datum.
gm_code-gm_code = '06'. " MB11
* Write 551 movement to table
clear gm_item.
move '551' to gm_item-move_type .
move '000000000040001234' to gm_item-material.
move '1' to gm_item-entry_qnt.
move 'EA' to gm_item-entry_uom.
move '0004' to gm_item-plant.
move '4000' to gm_item-stge_loc.
move '201' to gm_item-move_reas.
* Determine cost center per plant
case xresb-werks.
when '0004'.
move '0000041430' to gm_item-costcenter.
when '0006'.
move '0000041630' to gm_item-costcenter.
when '0007'.
move '0000041731' to gm_item-costcenter.
when '0008'.
move '0000041830' to gm_item-costcenter.
endcase.
append gm_item.
* Call goods movement BAPI
call function 'BAPI_GOODSMVT_CREATE'
exporting
goodsmvt_header = gm_header
goodsmvt_code = gm_code
importing
goodsmvt_headret = gm_headret
materialdocument = gm_retmtd
tables
goodsmvt_item = gm_item
return = gm_return.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
Welcome to SDN! Please remember to award points for helpful answers and mark you post as solved when solved completely. Thanks.
REgards,
Rich Heilman
2006 Mar 20 2:20 PM
Hi Rich, thanks for your answer. In my case, I guess I must call the MB1B transaction assigning 04 as the gm_code because is a transfer posting (a material quantity movement from one batch to another). The BAPI return this messages:
Deficit of BA Unrestr. prev. 90 ST : 5150104 U050 2800 LOTE 2
Deficit of BA Unrestricted-use 80 ST : 5150104 U050 2800 V
And below is the code. Where could be my mistake?
GOODSMVT_ITEM-MATERIAL = '000000000005150104'.
GOODSMVT_ITEM-PLANT = 'U050'.
GOODSMVT_ITEM-STGE_LOC = '2800'.
GOODSMVT_ITEM-BATCH = 'LOTE 2'. "original batch
GOODSMVT_ITEM-MOVE_MAT = '000000000005150104'.
GOODSMVT_ITEM-MOVE_PLANT = 'U050'.
GOODSMVT_ITEM-MOVE_STLOC = '2800'.
GOODSMVT_ITEM-MOVE_BATCH = 'V'. "receiving batch
GOODSMVT_ITEM-MOVE_TYPE = '309'.
GOODSMVT_ITEM-ENTRY_QNT = 90
APPEND GOODSMVT_ITEM.
GOODSMVT_ITEM-MATERIAL = '000000000005150104'.
GOODSMVT_ITEM-PLANT = 'U050'.
GOODSMVT_ITEM-STGE_LOC = '2800'.
GOODSMVT_ITEM-BATCH = 'V'. "receiving batch
GOODSMVT_ITEM-MOVE_MAT = '000000000005150104'.
GOODSMVT_ITEM-MOVE_PLANT = 'U050'.
GOODSMVT_ITEM-MOVE_STLOC = '2800'.
GOODSMVT_ITEM-MOVE_BATCH = 'LOTE 2'. "original batch
GOODSMVT_ITEM-MOVE_TYPE = '309'.
GOODSMVT_ITEM-ENTRY_QNT = 90.
APPEND GOODSMVT_ITEM.
Regards,
Sebastian.
2008 Jun 26 2:57 PM
Hi sir,
I am using 311 movement type for store to store movement.
2006 Mar 19 4:43 AM
Hi Sebastian,
Welcome to SDN.
Please take a look at this links for sample coding of BAPI_GOODSMVT_CREATE.
http://www.sap-img.com/abap/bapi-goodsmvt-create-to-post-goods-movement.htm
http://www.4ap.de/abap/bapi_goodsmvt_create.php
Hope this will help.
Regards,
Ferry Lianto