Application Development and Automation 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: 
Read only

commit

Former Member
0 Likes
665

hi all,

i developed a custom transaction in which i am doing several database updates. i want these to take place like standard SAP LUW all or none changes.

what has to be done to accomplish this..

presently i have something like this:

update xxx .

commit work.

update yyy.

commit work.

call 'z_bapi_xxx' in update task.

call function 'bapi_transaction_commit'.

thanks..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
644

If you put commit work after every table then it will commit till that time and if something goes wrong later the previous one will not rollback.

So, you have put commit work after all. so that it will either commit all or rollback all.

5 REPLIES 5
Read only

Former Member
0 Likes
645

If you put commit work after every table then it will commit till that time and if something goes wrong later the previous one will not rollback.

So, you have put commit work after all. so that it will either commit all or rollback all.

Read only

0 Likes
644

you can issue commit work after every logical point you want to save data.

Read only

Clemenss
Active Contributor
0 Likes
644

Hi,

usually you do not need any COMMIT WORK in your program, because at the end of the program run, a commit work is issued automatically and all data are stored in the database.

If the program ends with an error (message type E, A, X), the data are rolled baxk and nothing is stored.

But note: Any interruption of the program flow (also and especially online acreen input) will do a commit work too.

And there are exceptions: Any PERFORM ... ON COMMIT will need an explicit COMMIT WORK. The auto commit work will not trigger PERFORM ON COMMIT. Thats why you have to do a COMMIT WORK explicitly after calling any updating BAPI modules.

The best and safest and most efficient way is always to do as SAP does:

Put all to-be-stored data into internal tables. At the end of your transaction, if everything is fine, call a function module IN UPDATE TASK. Create this function module as an UPDATE module, the interface should have all your internal tables. In the module, just do the necessary updates and inserts.

After the CALL FUNCTION ... IN UPDATE TASK

issue the COMMIT WORK.

regards,

C.

Read only

sreekanthgo
Contributor
0 Likes
644

Hi KP,

Keep your code sequence like this.

Update XXX.

Update YYY.

Commit Work.

Call 'Z_BAPI_XXX'.

Call 'BAPI_TRANSACTION_COMMIT'.

Thanks,

Sreekanth G

Read only

0 Likes
644

If your BAPI has RETURN table..


    CLEAR V_ERROR.
    LOOP AT RETURN WHERE TYPE = K_E OR
                         TYPE = K_A OR
                         TYPE = K_X.
      MOVE K_X TO V_ERROR.
      EXIT.
    ENDLOOP.

    IF V_ERROR IS INITIAL.
*-- BAPI COMMIT
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ELSE.
*-- BAPI ROll BACK
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK.
    ENDIF.    " V_ERROR is initial

Thanks,

Sreekanth G