DB2: How to Use Cursor WITH HOLD Correctly

Working with WITH HOLD argument is little tricky in DB2 Cursors. Positioning the Cursor is the real use when you give WITH HOLD in DB2, CICS, IMS DB and IMS DC.

Rules to Use WITH HOLD

  1. The Cursor WITH HOLD does not impact on IMS DC programs. In CICS, the WITH HOLD does maintains Cursor position till end of the unit of work
  2. In CICS or IMS, non message driven programs, you declared a cursor with WITH HOLD option, and you opened a  cursor, now in current unit of work, you issued ROLLBACK and you made no change to database, in this scenario, Cursor will not be closed. Since IMS or CICS will not communicate null unit of work to DB2.
  3. DB2 REXX applications does not support WITH ROWSET POSITIONING
  4. A Cursor which is declared in Calling program, should not be used in Called module(Subroutine)
  5. A row can be fetched multiple times, if it is declared as SCROLLABLE and with Not Deterministic
  6. In IMS DC, you should not declare cursors with WITH HOLD
  7. In CICS, you can give Cursor WITH HOLD, but see limitations here. In CICS, message driven programs, even you have given WITH HOLD, the Cursors will be closed after Sync point or ROLLBACK operation. So usually, you should not give WITH HOLD clause in CICS programs.

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.