CLOSE
The CLOSE statement closes a cursor. If a temporary copy of a result table was created when the cursor was opened, that table is destroyed.
Invocation
This statement can only be embedded in an application program. It is an executable statement that cannot be dynamically prepared. It must not be specified in Java.
Authorization
See DECLARE CURSOR for the authorization required to use a cursor.
Syntax
>>-CLOSE--cursor-name------------------------------------------><
Description
- cursor-name
- Identifies the cursor to be closed. The cursor name must identify a declared cursor as explained in DECLARE CURSOR. When the CLOSE statement is executed, the cursor must be in the open state.
Notes
Implicit cursor close: At the end of a unit of work, all open cursors declared without the WITH HOLD option that belong to an application process are implicitly closed.
Close cursors for performance: Explicitly closing cursors as soon as possible can improve performance.
Procedure considerations: Special rules apply to cursors within procedures that have not been closed before returning to the calling program. For more information, see CALL.
Allocated cursors: The cursor could have been allocated. See ALLOCATE CURSOR.
Example
EXEC SQL DECLARE C1 CURSOR FOR
SELECT DEPTNO, DEPTNAME, MGRNO
FROM DSN8A10.DEPT
WHERE ADMRDEPT = 'A00'
END-EXEC.
EXEC SQL OPEN C1 END-EXEC.
EXEC SQL FETCH C1 INTO :DNUM, :DNAME, :MNUM END-EXEC.
IF SQLCODE = 100
PERFORM DATA-NOT-FOUND
ELSE
PERFORM GET-REST-OF-DEPT
UNTIL SQLCODE IS NOT EQUAL TO ZERO.
EXEC SQL CLOSE C1 END-EXEC.
GET-REST-OF-DEPT.
EXEC SQL FETCH C1 INTO :DNUM, :DNAME, :MNUM END-EXEC.