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: 

Commit in RFC function module called in background task (tRFC)

lou_
Explorer
0 Kudos

Hello everyone,

I'm currently struggling with a design perspective. I need to call a BAPI_GOODSMVT_CREATE in a User-Exit.

As we know, it's strongly recommended to commit the change after the BAPI call with BAPI_TRANSACTION_COMMIT, or, in case of errors, BAPI_TRANSACTION_ROLLBACK.

But, it not permitted to commit in User-Exit/BAdI. One of the solutions is to wrap the BAPI with the commit/rollback in RFC Function, and call it in sRFC/aRFC mode (but an implicit commit take place in the calling program), or, call it in Background Task (tRFC).

If I go with tRFC mode, the documentation say:

"The statements COMMIT WORK  and ROLLBACK WORK  must not be executed within a LUW. In addition, no implicit database commit  can be triggered there."

When I read other post on the subject, there are some answers which "allow" a commit in this FM. I think I'm OK with that but I would have your thoughts on about this... Is it really OK to bending the rules for this kind of need? Or maybe I'm just overthinking it a little bit and should go with the answers already given 😅?

See:

Can we use BAPI inside Customer Exits or BADIs? 

Is it ok to use commit work in a FM called in a background task ? 

And also, if commit inside tRFC must not happen, it means that every DB update in function called in this mode only depend of an implicit commit at the end of the process?

Thanks !

3 REPLIES 3

tmt-cpro
Explorer
0 Kudos

It is a bad idea, to call COMMIT WORK in a BAdI or User Exit, don't do it.

But after your BAdI was processed, the outer LUW will call COMMIT WORK, and then the goods movement will be created too.

If asynchronous processing is ok, think of creating an IDoc instead. Then you can monitor the processing and you may find errors, if they eventually happens.

And yes, it will also work to wrap the BAPI in a function module and call in backround task, i used this too.

0 Kudos

Hi tmt-cpro, I don't intend to commit in BAdI or UE, I know this is a bad practice (but it always good to be reminded 😉), the question was more about commit inside a function which are called in background task, because doc say we mustn't , but there are some special case where it seems OK (according to all the post I've read on the subject). 

I will check the IDoc method, thanks for your input !

raga1234
Discoverer
0 Kudos

Hi you can call an RFC FM in a separate task and execute it in background. you can use commit statement inside the RFC since a separate LUW will be created. the only Challenge here is the Goods movement will be an asynchronous process. you can execute the Goods movement BAPI in test run mode inside the user exit for error handling, if the test run mode is executed without any errors, then call the RFC FM as separate task.