Application Development 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: 

Usage of BAPI in Userexit/BADI

Former Member
0 Kudos
2,160

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

1 ACCEPTED SOLUTION

SimoneMilesi
Active Contributor
574

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.

6 REPLIES 6

SimoneMilesi
Active Contributor
575

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.

574

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.

0 Kudos
574

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.

574

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?

kjyothiraditya
Participant
0 Kudos
574

Hi experts,

Even I have a similar requirement. Can you please guide how to do it please as consistency should be there.

Regards

Aditya

matt
Active Contributor
574

Simone Melisa gives an answer that works.