‎2006 Jul 28 8:11 AM
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?
‎2006 Jul 28 8:25 AM
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
‎2006 Jul 28 8:15 AM
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.
‎2006 Jul 28 8:15 AM
‎2006 Jul 28 8:21 AM
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).
‎2006 Jul 28 8:23 AM
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?
‎2006 Jul 28 8:25 AM
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
‎2006 Jul 28 9:16 AM
Hi,Kiran and all
Tks for ur help. it works. and i have learned a new FM
'BAPI_TRANSACTION_ROLLBACK'
tks again.
‎2006 Jul 28 9:18 AM
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