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

Issue with BAPI_PO_CHANGE

Former Member
0 Likes
1,410

Hello Experts,

I'm facing a problem using the BAPI BAPI_PO_CHANGE to delete some items. My code is like given below:

The issue im facing is lets say I have 10 different POs that have different no of items that needs to be deleted, it works correctly for the first 2 POs and for the third one onwards it gives a 'Account Assignment wrong' error and no PO after that works.

Now if I rerun the program, the first two works again ( which was my third and fourth in prev run ) and will give and error for the next two records !!!

Tried different in background/ foreground modes...with /without wait statements... doesnt work after two POs even though in each time the no of items in each PO is different.

Any clues?

LOOP AT lt_po_del.

AT NEW ebeln.

LOOP AT lt_po_del WHERE ebeln = lt_po_del-ebeln.

lt_poitem-po_item = lt_po_del-ebelp.

lt_poitemx-po_item = lt_po_del-ebelp.

lt_poitem-delete_ind = 'L'.

lt_poitemx-delete_ind = 'X'.

APPEND lt_poitem TO lt_poitem.

APPEND lt_poitemx TO lt_poitemx.

ENDLOOP.

CALL FUNCTION 'BAPI_PO_CHANGE'

EXPORTING

purchaseorder = lt_po_del-ebeln

TABLES

return = lt_return

poitem = lt_poitem

poitemx = lt_poitemx.

READ TABLE lt_return WITH KEY type = 'S'.

IF sy-subrc = 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

CLEAR : lt_poitem[] , lt_poitemx[], lt_return[].

ELSE.

CLEAR : lt_poitem[] , lt_poitemx[], lt_return[].

ENDIF.

ENDAT.

ENDLOOP.

Hello Experts,

I'm facing a problem using the BAPI BAPI_PO_CHANGE to delete some items. My code is like given below:

The issue im facing is lets say I have 10 different POs that have different no of items that needs to be deleted, it works correctly for the first 2 POs and for the third one onwards it gives a 'Account Assignment wrong' error and no PO after that works.

Now if I rerun the program, the first two works again ( which was my third and fourth in prev run ) and will give and error for the next two records !!!

Tried different in background/ foreground modes...with /without wait statements... doesnt work after two POs even though in each time the no of items in each PO is different.

Any clues?

LOOP AT lt_po_del.

AT NEW ebeln.

LOOP AT lt_po_del WHERE ebeln = lt_po_del-ebeln.

lt_poitem-po_item = lt_po_del-ebelp.

lt_poitemx-po_item = lt_po_del-ebelp.

lt_poitem-delete_ind = 'L'.

lt_poitemx-delete_ind = 'X'.

APPEND lt_poitem TO lt_poitem.

APPEND lt_poitemx TO lt_poitemx.

ENDLOOP.

CALL FUNCTION 'BAPI_PO_CHANGE'

EXPORTING

purchaseorder = lt_po_del-ebeln

TABLES

return = lt_return

poitem = lt_poitem

poitemx = lt_poitemx.

READ TABLE lt_return WITH KEY type = 'S'.

IF sy-subrc = 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

CLEAR : lt_poitem[] , lt_poitemx[], lt_return[].

ELSE.

CLEAR : lt_poitem[] , lt_poitemx[], lt_return[].

ENDIF.

ENDAT.

ENDLOOP.

7 REPLIES 7
Read only

Former Member
0 Likes
1,201

Hi,

are you sure that your table LT_PO_DEL is sorted in a correct way?

Otherwise AT NEW won't work correctly and you will get these errors!

Also possible: Duplicate LOOP at LT_PO_DEL destroys internal table loop pointer. In this case remove Duplicate LOOP and AT NEW logic and use AT END OF EBELN. instead for BAPI calls and clears.

Regards,

Klaus

Edited by: Klaus Babl on Feb 8, 2011 9:48 AM

Read only

Former Member
0 Likes
1,201

Hi,

i had a similar issue. Sorting it in the right way is imp.

check somethin of this sort for example:

SORT struc BY ebeln ebelp.

LOOP AT struc.

PERFORM insert_itemdata.

PERFORM insert_headerdata.

AT END OF ebeln.

PERFORM call_bapi.

PERFORM refresh_data.

ENDAT.

ENDLOOP.

Read only

0 Likes
1,201

Thank you for your responses.

IT_PO_DEL has only two fields EBELN and EBELP and before the loop it is sorted by EBELN EBELP.

Also I checked in debugging mode, on each pass to the BAPI, the ITEM and ITEMX table and the PO number passed and it looked all OK. It has the correct POs and respective Item numbers

Someone just told me there is a BAPI to clear the buffer/cache that should be used after the BAPI commit , any clues on that front?

Read only

0 Likes
1,201

Hi,

the BAPI clears all data in the beginning, I don#t believe that there is a prbolem inside.

Are you sure to process each EBELN only one time?

Are you sure to clear your tables? The code you posted is wrong for the first two tables (partially missing brackets).

Have a try with the AT END OF logic above instead of a duplicate LOOP! Remains the error the same?

Regards

Klaus

Read only

0 Likes
1,201

Hi,

Try using DEQUEUE FM after the COMMIT FM.

Regards,

Sreeni.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,201

LOOP AT lt_po_del.
AT NEW ebeln.
LOOP AT lt_po_del WHERE ebeln = lt_po_del-ebeln.

If there is at new and a loop already then what is the need of second loop ???

I donot see any other problem in value mapping. There must be some bug in your code. Please check it.

Read only

0 Likes
1,201

As Keshav suggested, why don't you debug and find out the cause of error? Find out the Corresponding message id and message number and find out if you can pin down the cause of error? You can also check the OSS note

And as others pointed out, do not use the Same internal table (it may not be causing the error, but it will definitely makes the code less readable)... Use 'AT END' to build your internal table.