Skip to Content
0

Usage of BAPI in Userexit/BADI

Nov 28, 2016 at 10:38 AM

193

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Simone Milesi Nov 29, 2016 at 07:48 AM
2

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.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

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.

2

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.

0

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?

1