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

What if program with 'INSERT into TABLE' fails

Former Member
0 Likes
527

Hello All,

My program has insert and update to database tables. What happends if my program crashes in the middle? How to COMMIT this transactions to DB table, only after executing whole program?

example:

....

....

LOOP AT itab.

IF x = 100.

UPDATE zdbtable

SET date = sy-datum

userid = ''

WHERE sno = '100'.

ELSEIFx = 200.

UPDATE zdbtable

SET date = sy-datum

userid = ''

WHERE sno = '200'.

ELSEIF lv_days_pending = 300.

int_dbtable-sno = '300'.

int_dbtable-userid = ''.

INSERT into zdbtable values int_dbtable.

DELETE

FROM zdbtable

WHERE sno = '100'

ENDIF.

ENDLOOP.

I would like all this data base transactions to be executed or else if there is any crash in the middle no chages has to be made to the database tables.

Thanks,

Hello All,

My program has insert and update to database tables. What happends if my program crashes in the middle? How to COMMIT this transactions to DB table, only after executing whole program?

example:

....

....

LOOP AT itab.

IF x = 100.

UPDATE zdbtable

SET date = sy-datum

userid = ''

WHERE sno = '100'.

ELSEIFx = 200.

UPDATE zdbtable

SET date = sy-datum

userid = ''

WHERE sno = '200'.

ELSEIF lv_days_pending = 300.

int_dbtable-sno = '300'.

int_dbtable-userid = ''.

INSERT into zdbtable values int_dbtable.

DELETE

FROM zdbtable

WHERE sno = '100'

ENDIF.

ENDLOOP.

I would like all this data base transactions to be executed or else if there is any crash in the middle no chages has to be made to the database tables.

Thanks,

2 REPLIES 2
Read only

Former Member
0 Likes
465

Hi,

Use the ROLLBACK WORK if the SQL fails...

UPDATE zdbtable

SET date = sy-datum

userid = ''

WHERE sno = '100'.

ELSEIFx = 200.

UPDATE zdbtable

SET date = sy-datum

userid = ''

WHERE sno = '200'.

<b>IF SY-SUBRC <> 0.

ROLLBACK WORK.

MESSAGE E208(00) WITH 'UPDATE FAILED'.

ENDIF.</b>

ELSEIF lv_days_pending = 300.

int_dbtable-sno = '300'.

int_dbtable-userid = ''.

INSERT into zdbtable values int_dbtable.

<b>IF SY-SUBRC <> 0.

ROLLBACK WORK.

MESSAGE E208(00) WITH 'INSERT FAILED'.

ENDIF.</b>

DELETE

FROM zdbtable

WHERE sno = '100'

ENDIF.

<b>IF SY-SUBRC <> 0.

ROLLBACK WORK.

MESSAGE E208(00) WITH 'DELETE FAILED'.

ENDIF.</b>

  • If everything is successful then commit.

<b>COMMIT WORK.</b>

Thanks,

Naren

Read only

Former Member
0 Likes
465

Hi

You can use PERFORM ON COMMIT or Update Function modules for this .

For creating Update Function modules you have to select the attribute Processing type as 'Update' . And you have to call the function in update task

Ex : Call ' FM ' in update task.

Cheers

Anand