Closes an open cursor.
exec sql [at connection_name] close cursor_name end-exec
The name of the cursor to be closed; that is, the name that you assigned when declaring the cursor.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 LNAME PIC X(40).
01 FNAME PIC X(20).
01 PHONE PIC X(12).
EXEC SQL END DECLARE SECTION END-EXEC.
...
EXEC SQL DECLARE authorlist CURSOR FOR
SELECT au_lname, au_fname, phone
FROM authors END-EXEC.
EXEC SQL OPEN authorlist END-EXEC.
PERFORM FETCH-LOOP UNTIL SQLCODE = 100.
EXEC SQL CLOSE authorlist END-EXEC,
...
FETCH-LOOP.
EXEC SQL FETCH authorlist INTO
:LNAME, :FNAME, :PHONE END-EXEC.
DISPLAY LNAME, FNAME, PHONE.
The close statement closes an open cursor. Unfetched rows are canceled.
Reopening a closed cursor executes the associated query again, positioning the cursor pointer before the first row of the result set.
A cursor must be closed before it is reopened.
Attempting to close a cursor that is not open causes a runtime error.
The commit transaction, rollback transaction, commit work, and rollback work statements close a cursor automatically unless you set a precompiler option to disable the feature.
Closing and then reopening a cursor lets your program see any changes in the tables from which the cursor retrieves rows.
declare cursor, fetch, open, prepare