2006 Jul 18 8:03 PM
Hello,
I need to do a goods receipt for a purchase order using bapi_goodsmvt_create for movement type 101. My function module does not return the material document number. Can someone help me with my code?
Thanks,
A.P.
FUNCTION Z_GR_BAPI.
*"----
""Local interface:
*" IMPORTING
*" REFERENCE(I_CODE) TYPE GM_CODE
*" REFERENCE(I_MOVE_TYPE) TYPE CHAR3
*" REFERENCE(I_EKKO) TYPE EKKO
*" EXPORTING
*" REFERENCE(E_DOCUMENT) TYPE BAPI2017_GM_HEAD_RET-MAT_DOC
*" REFERENCE(E_RETURN) TYPE BAPIRET2
*" TABLES
*" T_EKPO STRUCTURE EKPO
*"----
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.
data: x_ekpo type table of ekpo with header line.
x_ekpo[] = t_ekpo[].
clear: gm_return, gm_retmtd.
refresh gm_return.
gm_code-gm_code = i_code.
gm_header-pstng_date = sy-datum.
gm_header-doc_date = sy-datum.
gm_header-pr_uname = sy-uname.
loop at x_ekpo.
gm_item-material = x_ekpo-matnr.
gm_item-plant = x_ekpo-werks.
gm_item-stge_loc = x_ekpo-lgort.
gm_item-move_type = i_move_type.
gm_item-mvt_ind = 'B'.
gm_item-stck_type = space.
gm_item-entry_qnt = x_ekpo-menge.
gm_item-entry_uom = x_ekpo-meins.
append gm_item.
endloop.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = gm_header
GOODSMVT_CODE = gm_code
TESTRUN = ' '
IMPORTING
GOODSMVT_HEADRET = gm_headret
MATERIALDOCUMENT = gm_retmtd
MATDOCUMENTYEAR =
TABLES
GOODSMVT_ITEM = gm_item
GOODSMVT_SERIALNUMBER =
RETURN = gm_return.
e_document = gm_retmtd.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
IMPORTING
RETURN =
ENDFUNCTION.
2006 Jul 18 8:13 PM
Hello,
I need to do a goods receipt for a purchase order using bapi_goodsmvt_create for movement type 101. My function module does not return the material document number. Can someone help me with my code?
Thanks,
A.P.
FUNCTION Z_GR_BAPI.
*"----
""Local interface:
*" IMPORTING
*" REFERENCE(I_CODE) TYPE GM_CODE
*" REFERENCE(I_MOVE_TYPE) TYPE CHAR3
*" REFERENCE(I_EKKO) TYPE EKKO
*" EXPORTING
*" REFERENCE(E_DOCUMENT) TYPE BAPI2017_GM_HEAD_RET-MAT_DOC
*" REFERENCE(E_RETURN) TYPE BAPIRET2
*" TABLES
*" T_EKPO STRUCTURE EKPO
*"----
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.
data: x_ekpo type table of ekpo with header line.
x_ekpo[] = t_ekpo[].
clear: gm_return, gm_retmtd.
refresh gm_return.
gm_code-gm_code = i_code.
gm_header-pstng_date = sy-datum.
gm_header-doc_date = sy-datum.
gm_header-pr_uname = sy-uname.
loop at x_ekpo.
gm_item-material = x_ekpo-matnr.
gm_item-plant = x_ekpo-werks.
gm_item-stge_loc = x_ekpo-lgort.
gm_item-move_type = i_move_type.
gm_item-mvt_ind = 'B'.
gm_item-stck_type = space.
gm_item-entry_qnt = x_ekpo-menge.
gm_item-entry_uom = x_ekpo-meins.
append gm_item.
endloop.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = gm_header
GOODSMVT_CODE = gm_code
TESTRUN = ' '
IMPORTING
GOODSMVT_HEADRET = gm_headret
MATERIALDOCUMENT = gm_retmtd
MATDOCUMENTYEAR =
TABLES
GOODSMVT_ITEM = gm_item
GOODSMVT_SERIALNUMBER =
RETURN = gm_return.
e_document = gm_retmtd.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
IMPORTING
RETURN =
ENDFUNCTION.
2006 Jul 18 8:06 PM
If function module does not return the material document number, may be you have errors in gm_return.
Regards.
2006 Jul 18 8:08 PM
Hi Peluka,
Thnaks for ur reply. Any idea as to why I'm might get an error?
A.P.
2006 Jul 18 8:12 PM
Hi,
Does BAPI_GOODSMVT_CREATE return your material doc number in structure GOODSMVT_HEADRET field MAT_DOC? According to the BAPI documentation for GOODSMVT_HEADRET, "This structure transfers the fields that are filled to the initiator when the material document was successfully posted."
Regards,
James G.
2006 Jul 18 8:13 PM
2006 Jul 18 8:14 PM
Hi,
This piece of code may be helpful.
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'.
regards,
keerthi.
2006 Jul 18 8:15 PM
Hi A.P,
Please try to place the code e_document = gm_retmtd after BAPI_TRANSACTION_COMMIT.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
e_document = gm_retmtd.Hope this will help.
Regards,
Ferry Lianto
2006 Jul 18 8:19 PM
For example, this example program works very will for me in doing a GR against a PO.
report zrich_0001.
* 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 with header line.
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.
<b>gm_code-gm_code = '01'. "" GR for PO</b>
* Write 101 movement to table
clear gm_item.
move '101' to gm_item-move_type .
move '000000000040003572' to gm_item-material.
move '100' to gm_item-entry_qnt.
move 'BF' to gm_item-entry_uom.
move '0008' to gm_item-plant.
move '8003' to gm_item-stge_loc.
<b>move '0000095851' to gm_item-po_number.
move '000001' to gm_item-po_item.
move 'B' to gm_item-mvt_ind.</b>
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.
if not gm_retmtd is initial.
commit work and wait.
call function 'DEQUEUE_ALL'.
else.
commit work and wait.
call function 'DEQUEUE_ALL'.
endif.
write:/ gm_retmtd.
loop at gm_return.
write:/ gm_return.
endloop.
Regards,
Rich Heilman
2006 Jul 18 8:46 PM
Hello Guys,
BAPI works great now. I forgot the add the PO to the gm_item table (thanks to Rich) and I had to write the e_return line after bapi_transaction_commit(thanks to Ferry). I guess it was trying to fish without a fishing rod. Anyways, thank you all for your super quick replies.
Regards,
A.P.