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: 

DB Update from BAPI

Former Member
0 Kudos

Hi All,

I am trying to create a RFC FM ( BAPI) which will be called from external system. The role of this FM is insert to 3 different Z tables. Table structure's is like Header, Details & Sub details.

Requirement is if the insert/update fails on Header than all other insert/update should fail Also i need to report back any errors to calling system.

I have designed the BAPI in such way that after some initial data check, i call another FM in update task.

Inside this FM i am doing insert/update. After coming out i am doing Commit Work. Also setting SET UPDATE TASK LOCAL

My doubt is

(1) how would this handle a situation where update in header fails so all other update are rejected.

(2) I would like to let the other system know, if the insert is good or fail. Since Update task does not allow export, how to handle this.

Please advice the best solution for this.

5 REPLIES 5

krishnendu_laha
Active Contributor
0 Kudos

hello,

Please use COMMIT WORK AND WAIT and check SY-SUBRC after each table update which will make sure update of every step.

FYI - SET UPDATE TASK LOCAL use same work process and does not update VBLOG table.

Thanks.

0 Kudos

Thanks for the reply.

So you mean that after each update check sy-subrc eq 0, if not then what should be next step

Let's say Sy-subrc comes 4, how should i pass this back to calling FM so that i stop the commit work ( which is outside the FM)

Update task FM does not allow export parameters..

Thanks

0 Kudos

Hello,

My intention was to suggest not to use FM in update task and update one by one (header, details & sub-details) using commit work and wait. Because I understood from requirement, here we do not need complex DB handling...

Just to make clear - update task function module triggered when commit work statement encounters in program (before commit work all update module registered) and although it does not support import but can access global data of function group / program.

Thanks.

0 Kudos

Thanks for the reply once again.

Ideally i would like to do in one go. Insert in 3, if success Commit or roll back. How should i achieve this?

Regards

0 Kudos

Hello,

I agree with the last post, it's useless to use update task for a simple update process.

But if you want to create a BAPI, then COMMIT WORK is forbidden, the commit is the responsibility of the calling application (by calling BAPI_TRANSACTION_COMMIT by RFC).

Now, if you want to know if the INSERT are okay, just test SY-SUBRC, and return an exporting parameter which gives the status if it's okay or not (if it's a BAPI, that should be parameter RETURN of type table of BAPIRET2). The calling program will then be able to commit or rollback (using BAPI_TRANSACTION_ROLLBACK)

BR

Sandra