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/rollback

Former Member
0 Likes
762

There is a record having many fields & I want to insert the record in 3 custom tables designed accordingly . but either all the tables should get filled or none of the table should get filled.Should I use commit/rollback?? How??

The following is the syntax in a function module.

INSERT ZTEST1 FROM ZTEST1.

INSERT ZTEST2 FROM ZTEST2.

INSERT ZTEST3 FROM ZTEST3.

IF SY-SUBRC = 0.

COMMIT WORK.

ELSE.

ROLLBACK WORK.

ENDIF.

This does not work. Any Solution??

4 REPLIES 4
Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
599

Hi,

If u want to check all the tables :

Try this:

INSERT ZTEST1 FROM ZTEST1.

IF SY-SUBRC = 0.

INSERT ZTEST2 FROM ZTEST2.

IF SY-SUBRC = 0.

INSERT ZTEST3 FROM ZTEST3.

IF SY-SUBRC = 0.

COMMIT WORK.

ELSE.

ROLLBACK WORK.

ENDIF.

endif.

endif.

So u can check the commit work for all the three .

Hope this helps.

Read only

Former Member
0 Likes
599

the code you are writte will check only third insert.<br>

do in the following way <br>

form save_data. <br>

INSERT ZTEST1 FROM ZTEST1.<br>

if sy-subrc = 0<br>

INSERT ZTEST2 FROM ZTEST2.<br>

if sy-subrc = 0<br>

INSERT ZTEST3 FROM ZTEST3.<br>

else.<br>

rollback work<br>

exit.<br>

endif.<br>

else.<br>

rollback work<br>

exit.<br>

endif..<br>

commit work.<br>

endform.

Message was edited by:

SHEFALI GANGRADE

Read only

Former Member
0 Likes
599

Hi Deepali,

1. Never ever use a insert to pdate any table , always use a function module in

update mode, this is the best industry practise.

2. Use all the three insert statements insde a custom function module in

update mode, this will udate all if sucess and roll back if any one fails.

Regards,

Vaibhav B Gawali.

Read only

Former Member
0 Likes
599

Hi,

The following code will helps to you.

INSERT ZTEST1 FROM ZTEST1.
if sy-subrc ne 0.
rollback work.
exit.
endif. 

INSERT ZTEST2 FROM ZTEST2.
if sy-subrc ne 0.
rollback work.
exit.
endif. 

INSERT ZTEST3 FROM ZTEST3.
if sy-subrc ne 0.
rollback work.
exit.
endif. 

commit work.

Regards

Bhupal Reddy