---
title: "DB2: Cursor WITH HOLD, CLOSE, OPEN Ideas"
description: "A cursor in an application programming plays crucial role. With cursor you can get matching rows for the condition given in the WHERE clause. https://srinimf.com/2015/02/22/nested-cursor-db2/. Cursor..."
url: https://srinimf.com/2015/07/07/db2-with-hold-close-and-open-of-cursors-in-commit-or-rollback/
date: 2015-07-07
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2015/07/pexels-photo-6436744.jpeg?fit=1880%2C1255&ssl=1
categories: ["DB2"]
tags: ["DB2 Cursors", "Db2 Tips", "DB2 Tips and Solutions"]
type: post
lang: en
---

# DB2: Cursor WITH HOLD, CLOSE, OPEN Ideas

A [cursor in an application](http://srinimf.com/2015/02/24/5-new-things-on-db2-cursors/) programming plays crucial role. With cursor you can get matching rows for the condition given in the WHERE clause.

Related[Here’s All About Nested Cursor in DB2](https://srinimf.com/2015/02/22/nested-cursor-db2/)

## Cursor life cycle

**Declare => OPEN => Fetch => CLOSE**

**Declare-**It is nothing but declaration, like working storage variable [in COBOL program](https://srinimf.com/2017/06/30/handy-guide-cics-cobol/). But, it is not executable.

**OPEN**=> With open statement cursor execution will start. Then, FETCH and CLOSE follows.

**CLOSE**=> It closes all open cursors

- A cursor is declared with WITH HOLD option, will be closed, when ROLLBACK is happened.
- In the case of COMMIT, cursor will not be closed. So, you can continue process the table during next read.
- WITHOUT HOLD – By default there is WITHOUT HOLD. Until you specify, in the declaration with WITH HOLD.
- Even If you mention with WITH HOLD option, by default, after STOP RUN all the cursors will be released.
- CLOSE cursor anyway closes all cursors.

Advertisements

## When CURSOR WITH HOLD will not work

Let us see the details:

- The connection associated with the cursor is in the release pending status.
- The bind option DISCONNECT(AUTOMATIC) is in effect.
- The environment is one in which the option WITH HOLD is ignored.

**Why Cursor WITH HOLD does not work in CICS**

Cursors that are declared with WITH HOLD in CICS® ,message-driven programs, will be closed after Sync point or ROLLBACK operation. Each time you need to re-open the Cursors.

So, Cursor with WITH HOLD option we usually do not give in CICS.

IMS DC programs, does not support WITH HOLD clause.

Related[How to access “IMS DB” database using SQL Queries(1 of 2)](https://srinimf.com/2015/10/06/how-to-access-ims-db-database-using-sql-queries1-of-2/)

Recommended reading:

- [Advanced Programming with cursors](http://srinimf.com/2014/08/08/db2-programming-with-cursors-part-2-of-2/)

Keep Reading

Related[How to Resolve SQL Error -500 Quickly](https://srinimf.com/2015/12/05/sql-error-500-cursor-was-closed-when-the-connection-destroyed/)

- [DB2: How to Use Cursor WITH HOLD Correctly](https://srinimf.com/2015/10/23/five-facts-about-db2-cursors-that-will-blow-your-mind/)DateOctober 23, 2015
- [Quick Tutorial on DB2 Cursors](https://srinimf.com/2015/02/24/5-new-things-on-db2-cursors/)DateFebruary 24, 2015
- [Here’s All About Nested Cursor in DB2](https://srinimf.com/2015/02/22/nested-cursor-db2/)DateFebruary 22, 2015

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2015%2F07%2F07%2Fdb2-with-hold-close-and-open-of-cursors-in-commit-or-rollback%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2015%2F07%2Fpexels-photo-6436744.jpeg%3Ffit%3D1200%252C801%26ssl%3D1&description=DB2%3A%20Cursor%20WITH%20HOLD%2C%20CLOSE%2C%20OPEN%20Ideas)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2015/07/07/db2-with-hold-close-and-open-of-cursors-in-commit-or-rollback/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2015/07/07/db2-with-hold-close-and-open-of-cursors-in-commit-or-rollback/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2015/07/07/db2-with-hold-close-and-open-of-cursors-in-commit-or-rollback/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2015/07/07/db2-with-hold-close-and-open-of-cursors-in-commit-or-rollback/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20DB2%3A%20Cursor%20WITH%20HOLD%2C%20CLOSE%2C%20OPEN%20Ideas&body=https%3A%2F%2Fsrinimf.com%2F2015%2F07%2F07%2Fdb2-with-hold-close-and-open-of-cursors-in-commit-or-rollback%2F&share=email)
-

### Like this:

Like Loading…
