‎2014 May 13 10:58 AM
Hi
I have a program which creates GR for a purchase order. This program is executed by passing the idocs. Code inside this program is
1. Loop at internal table.
2. Bapi function module to create GR
3. Endloop.
4. Perform to update the idoc status. if the function module returns any error then status is set to 51 else to 53.
Now the requirement is, for any one of the records in internal table if error occurs in function module then the idoc status should be set to 51 and it should not process anything.
So, i thought of adding the code after step2 as
if return table has any error.
lv_flag = X.
Bapi Rollback.
exit.
else.
Bapi commit.
endif.
if lv_flag = X.
idoc status = 51.
else.
idoc status = 53.
endif.
this is not working when the first record in the internal table has no errors because as per the code i have written, it is doing bapi commit but it should not happen.
please suggest to come out of this.
Thanks,
Spandana
‎2014 May 13 11:06 AM
Hi Spanadana,
If I correctly understood then if there is no error it should do commit. That is what you have written,so where is the exact issue.
Regards,
Sandeep Katoch
‎2014 May 13 11:09 AM
Hi Spandana,
Sorry, can you explain your issue in detail?
Regards,
Sudeesh Soni
‎2014 May 13 11:21 AM
we are looping at the data segments of the idoc which is passed to this program.
suppose i have 2 data records which means it creates 2 GR's for the PO. if error occurs for any one of these two the program should not create GR's for both the records and change the idoc status accordingly.
for the first record, i dint get any error while creating then program will do commit i.e, GR is created.
for the second record, if i get any error while creating then program should not process anything, i mean the GR created for the first record also should get deleted.
‎2014 May 13 11:34 AM
Spandana,
you can try one thing as
Create a perform to call bapi and make it as in update task.
take a flag and make it x if any record goes into error. Check this outside loop and if not x do commit and if x do not commit.
In this way it will create a LUW and if LUW fails all records are rolled back and if succeeds all records are saved.
Regards,
Sandeep Katoch
‎2014 May 13 11:50 AM
Hi Spandana,
Let us know which BAPI you used to create GR.
Please check whether BAPI having parameter called testrun.
If BAPI having testrun parameter then you need to call the BAPI twice with and without testrun .
But this method not recommended as part of performance tuning.
For an example BAPI_GOODSMVT_CREATE has testrun
Thanks & Regards,
Arun
‎2014 May 13 11:53 AM
Hi,
Use the BAPI Commit outside loop.
for eg.
Loop..
call BAPI..
if returntable has error..
lv_flag = 'X'.
BAPI rollback back.
exit.
endif.
Endloop.
if lv_flag = X.
idoc status = 51.
else.
BAPI commit work.
idoc status = 53.
endif.
‎2014 May 13 2:41 PM
Hi Digesh,
if we do bapi commit outside the loop then it will do commit for the last record present that internal table right. correct me if i'm wrong.
but we need to do commit for each record in that internal table.
‎2014 May 13 2:55 PM
It will not commit just last record. It will commit for all. eg. if you have 2 error free records, then it will create 2 GRs.
I have used same approach for BAPI_ACC_DOCUMENT_POST. and It's working fine.
‎2014 May 13 3:01 PM
if we do bapi commit outside the loop then it will do commit for the last record present that internal table right.
I don't think so.
COMMIT/ROLLBACK WORK (via BAPI_TRANSACTION_COMMIT/ROLLBACK) will end the LUW. So all the update modules registered (during BAPI calls) should either get called (in case of COMMIT) or get deregistered(in case of ROLLBACK).
But tbh, this depends entirely on how the BAPI is coded.
BR,
Suhas