Previous Topic: DescriptionNext Topic: Example1


Cursor Usage

A DECLARE CURSOR statement must have corresponding OPEN, FETCH and CLOSE statements in the same source program for the execution of the OPEN to proceed without error.

Cursors must be declared in the source:

  1. Before any reference to the cursor, and
  2. After all host variables used in the definition have been defined.

If an exception declaration (WHENEVER statement) is not provided, the recommended practice is for your program to include code to check the returned value of the SQLCODE immediately after each executable SQL statement. If you do not use a WHENEVER statement, however, be aware of the following:

Cursor definitions are declarations, not operational (procedural) statements, and as such are used for Preprocessor input only. Because no call is sent to the Multi-User Facility, checking the SQLCODE after a DECLARE CURSOR statement always shows the SQLCODE received by whatever statement immediately preceeded the DECLARE CURSOR statement.

In COBOL, cursor declarations can be made in the: