How will you keep the CURSOR open after firing COMMIT in a COBOL-DB2 program?


Whenever we issue a COMMIT statement, all the open cursors will get closed. This is a very common case when we have to frequently use the commit statement after a UPDATE while working with a cursor. In this case we can use the “WITH HOLD” clause during the cursor declaration.

The “WITH HOLD” clause will keep the cursor open even after firing the COMMIT statement. We can give the “WITH HOLD” clause in the following way.

EXEC SQL
      DECLARE ORDER_CUR CURSOR WITH HOLD FOR
         SELECT ORDER_ID, TRANSACTION_ID FROM ORDERS
            WHERE ORDER_DATE = ‘2020-07-28’
END-EXEC

Updated on: 15-Sep-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements