2016 Nov 28 10:38 AM
Hello All,
Good Day!
Need info reg usage of BAPI, in user exit/BADI.
Can we use, BAPI inside a exit/BADI?
In general, we are not supposed to use commit/rollback in BADI/User exit. But what we have called a BAPI, in a exit/BADI, and we have error message in return parameter, and transaction was successful.
Will there be inconsistency, if yes, what is the turn around?
Thanks a lot in advance.
Regards,
Naga
2016 Nov 29 7:48 AM
Hi Naga,
I'm pretty sure someone did the same question about 2 weeks ago.
As you pointed out, in BAdI and U.E. we cannot put commit / rollbacks so calling a BAPI in them could lead to incosistency.
It's one of the first thing i learn working with U.E. ages ago 🙂
The most common workaround i found implemented is to raise and event in U.E./BAdI calling a FORM for this ON COMMIT (so it's triggered only when the commit is done) and then create an external report to schedule to intercept the Event.
In the event you put as parameter the document nr you need and in the report retrieve the data.
It's ugly, it's not 100% sure, it's not the best solution.
My suggestion is to study the case and ask yourself you need to call a BAPI in an BAdI and check if you can achieve the same result in other way.
2016 Nov 29 7:48 AM
Hi Naga,
I'm pretty sure someone did the same question about 2 weeks ago.
As you pointed out, in BAdI and U.E. we cannot put commit / rollbacks so calling a BAPI in them could lead to incosistency.
It's one of the first thing i learn working with U.E. ages ago 🙂
The most common workaround i found implemented is to raise and event in U.E./BAdI calling a FORM for this ON COMMIT (so it's triggered only when the commit is done) and then create an external report to schedule to intercept the Event.
In the event you put as parameter the document nr you need and in the report retrieve the data.
It's ugly, it's not 100% sure, it's not the best solution.
My suggestion is to study the case and ask yourself you need to call a BAPI in an BAdI and check if you can achieve the same result in other way.
2016 Nov 29 11:20 PM
Many BAPIs don't actually perform COMMIT. So depending on what particular BAPI we are talking about this might be OK. Although in general I'd avoid using BAPI in UE/BADI. And yes, UE/BADI are not really supposed to be so evolved as to require a BAPI call to begin with.
2016 Nov 30 5:00 AM
You have two options
encapsulate your code in an RFC enabled function module and then you can call a BAPI in background task as separate unit with commit work.
Or simply just call the BAPI and then the commit/update tasks let it update itself.
2016 Nov 30 8:25 AM
Yes, BAPI rarely perform internal commit so you have to put it manually.
@EJ Ermac
And no, you cannot leave the system to perform the commit itself because it's too risky!
You have to trigger the BAPI only when a document is correctly saved, but, after triggering it, the commit perform a rollback (or viceversa): can you see the big issue?
2020 Dec 10 6:21 PM
Hi experts,
Even I have a similar requirement. Can you please guide how to do it please as consistency should be there.
Regards
Aditya
2020 Dec 10 6:51 PM