Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

regarding bapi

Former Member
0 Likes
631

HI experts,

here in my scenario what i want that whenever i pass two material number it will give one document number ..ok ...but after writing this code it is giving two document number these two documnet number containing two material ...no doubt ....

what i want that after executing this bapi will give only one document number containing these two material number ..here the codes is..

  • BAPI header data.

GM_HEADER-PSTNG_DATE = SY-DATUM.

GM_HEADER-DOC_DATE = SY-DATUM.

*Goods receipt for production order

GM_CODE-GM_CODE = '03'. " MB1A

  • Write '261' movement to table

CLEAR GM_ITEM.

MOVE '700000000226' TO GM_ITEM-ORDERID.

MOVE '261' TO GM_ITEM-MOVE_TYPE .

MOVE '000000003000000172' TO GM_ITEM-MATERIAL.

MOVE '.1' TO GM_ITEM-ENTRY_QNT.

MOVE '6000' TO GM_ITEM-PLANT.

MOVE 'WFC1' TO GM_ITEM-STGE_LOC.

MOVE '1000006662' TO GM_ITEM-BATCH.

APPEND GM_ITEM.

clear GM_ITEM.

MOVE '700000000226' TO GM_ITEM-ORDERID.

MOVE '261' TO GM_ITEM-MOVE_TYPE .

MOVE '000000003000000170' TO GM_ITEM-MATERIAL.

MOVE '.1' TO GM_ITEM-ENTRY_QNT.

MOVE '6000' TO GM_ITEM-PLANT.

MOVE 'WFC1' TO GM_ITEM-STGE_LOC.

MOVE '1000007730' TO GM_ITEM-BATCH.

APPEND GM_ITEM.

clear GM_ITEM.

loop at 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.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'.

WRITE:/ GM_RETMTD.

endloop.

1 ACCEPTED SOLUTION
Read only

dev_parbutteea
Active Contributor
0 Likes
610

Hi ,

What i meant is that (here you are hard coding it) you are appending the header data twice. so, two documents will be created.

What you needed to do is append header info only once but with any number of materials!! i.e:

Either

remove the following statement , it will work:

<b>loop at gm_item.</b>

Regards.

4 REPLIES 4
Read only

dev_parbutteea
Active Contributor
0 Likes
610

Hi,

you are calling the bapi for every line of your table. so, here your table contains 2 entries , it will therefore create two documents.

you need to do the loop,

then read next record of table

if sy-subrc <> 0.

call bapi

else

continue.

Regards.

Read only

0 Likes
610

HI soonese plz explain it clearly.......i vud be grateful to you

Read only

Former Member
0 Likes
610

solved by own

Read only

dev_parbutteea
Active Contributor
0 Likes
611

Hi ,

What i meant is that (here you are hard coding it) you are appending the header data twice. so, two documents will be created.

What you needed to do is append header info only once but with any number of materials!! i.e:

Either

remove the following statement , it will work:

<b>loop at gm_item.</b>

Regards.