How can you revert all the DB2 table changes done in a COBOL-DB2 program?

DB2DatabaseBig Data Analytics

We can revert all the changes done on a COBOL-DB2 program using the ROLLBACK statement. However, ROLLBACK is only applicable until COMMIT has not been issued. If we have used a COMMIT statement, then ROLLBACK will revert all the changes made in DB2 tables after the last COMMIT point.

For example, after the commit statement, we execute an UPDATE statement to modify the ORDER_PAID column of ORDERS table. After that if we fire ROLLBACK then the UPDATE on the ORDERS table will be reverted.

Example

EXEC SQL
COMMIT
END-EXEC

EXEC SQL
UPDATE ORDERS
   SET ORDERS_PAID = ‘YES’
WHERE ORDER_DATE = :WS-CURRENT-DATE
END-EXEC

EXEC SQL
ROLLBACK
END-EXEC

In this case, after firing the ROLLBACK statement, all the changes made by UPDATE statement will be reverted.

raja
Published on 30-Nov-2020 08:58:05
Advertisements