SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Static SQL Cursors
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
6-11
Close the Cursor
01 SQLSTATE-OK PIC X(5) VALUE "00000".
...
EXEC SQL OPEN get_by_partnum END-EXEC.
...
EXEC SQL FETCH get_by_partnum ... END-EXEC.
PERFORM UNTIL SQLSTATE = SQLSTATE-NODATA
* Test the value(s) in the current row
IF ...
EXEC SQL DELETE FROM sales.parts
WHERE CURRENT OF get_by_partnum
END-EXEC.
END-IF
* Get the next row
EXEC SQL FETCH get_by_partnum ... END-EXEC.
END-PERFORM.
...
EXEC SQL CLOSE get_by_partnum END-EXEC.
Close the Cursor
Use the CLOSE statement to close the cursor and release the result table established
by the OPEN statement. After the CLOSE statement executes, the result table no
longer exists. To use the same cursor again, you must reopen it by using an OPEN
statement.
Use this general syntax:
For complete syntax, see the CLOSE statement in the SQL/MX Reference Manual.
A CLOSE statement must execute within the scope of all other SQL statements that
refer to the cursor, including the DECLARE CURSOR, OPEN, FETCH, INSERT, and
DELETE statements.
Example
This C example closes the list_by_partnum cursor:
EXEC SQL CLOSE list_by_partnum;
The COMMIT WORK and ROLLBACK WORK statements also close all open
associated cursors.
To ensure that a sequence of statements that changes the database either executes
successfully or not at all, define one transaction consisting of these statements by
enclosing the sequence within the BEGIN WORK and COMMIT WORK statements.
The CLOSE statement does not save changes. COMMIT WORK saves all changes
made in the table. For further information, see Section 14, Transaction Management.
Note. Ensure that AUTOCOMMIT is off. If AUTOCOMMIT is on, the transaction started by the
executor implicitly is committed when the statement is finished.
CLOSE cursor-name