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

BAPI error

Former Member
0 Likes
887

Hi,

when i use BAPI TO CREATE MATERIAL,I USE THE bapi during a loop&endloop. But not all the loop is executed.

the code as follow:

loop AT it_massdata.

  • transfer BAPI data

.....

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

headdata = BAPIMATHEAD

CLIENTDATA = BAPI_MARA

CLIENTDATAX = BAPI_MARAx

PLANTDATA = BAPI_MARc

PLANTDATAX = BAPI_MARcx

VALUATIONDATA = BAPI_MBEW

VALUATIONDATAX = BAPI_MBEWX

IMPORTING

RETURN = IT_RETURN

TABLES

MATERIALDESCRIPTION = IT_MATERIALDESC.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

commit work and wait.

endloop.

any advice?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
827

Hey,

Add the following code after the call to 'BAPI_MATERIAL_SAVEDATA'.

READ TABLE it_return WITH KEY type = 'E' BINARY SEARCH.

IF sy-subrc NE 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

ElSE.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .

*Logic to collect errors

ENDIF.

-Kiran

7 REPLIES 7
Read only

Former Member
0 Likes
827

You have to read the contents of IT_RETURN before doing a commit. If IT_RETURN has any message of type 'E', that means that material will not be created.

See the message description to find out why the material was not created, it could be because of the kind of data you are passing to the BAPI.

Read only

Former Member
0 Likes
827

Do you have any errors on it_return ??

BR, JAcek

Read only

0 Likes
827

Hi,

there is no error. ie. there are ten loops, but the prog just execute 8 loops.

But when i execute it in debug mode, it is ok.

so that is with SAP process i think, but i do not know how to make sure it execute each loop.(i have tried commit work and wait but with no effect).

Read only

Former Member
0 Likes
827

Hi,

i just remove the statement

  • CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

  • commit work and wait.

and it seems right, but i am not sure about it.

any points?

Read only

Former Member
0 Likes
828

Hey,

Add the following code after the call to 'BAPI_MATERIAL_SAVEDATA'.

READ TABLE it_return WITH KEY type = 'E' BINARY SEARCH.

IF sy-subrc NE 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

ElSE.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .

*Logic to collect errors

ENDIF.

-Kiran

Read only

0 Likes
827

Hi,Kiran and all

Tks for ur help. it works. and i have learned a new FM

'BAPI_TRANSACTION_ROLLBACK'

tks again.

Read only

0 Likes
827

Have you probed making only one commit work when you get out of the loop, or perhaps you have to put

wait up to 3 seconds.

Normally when the program works in debugging, but not in normal execution, it is problem of synchronism, probe both solutions.

regards