Purpose
Positions a cursor to the beginning of the next statement or to the results of a specified statement.
Invocation
Executable.
Embedded SQL only.
Syntax
POSITION cursor_name [ TO { NEXT | [STATEMENT] { statement_number | [:] numeric_variable } } ]
- cursor_name
- The name of an open cursor other than an Insertion cursor.
- statement_number
- An integer numeric for the statement number to which positioning is desired.
- numeric_variable
- A host variable conforming to type INTEGER that represents the statement number to which positioning is desired. Use of a colon character is optional.
ANSI Compliance
POSITION is ANSI/ISO SQL:2011-compliant.
Authorization
None.
Rules
The cursor is repositioned before the first result row (if any) of the statement specified and SQLSTATE, SQLCODE and other SQLCA values are set.
With POSITION TO NEXT, the cursor is positioned to the next statement.
With POSITION TO STATEMENT, the cursor is positioned to the specified statement.
- SQLCODE is set to -501
- SQLSTATE is set to ‘24501’
The cursor can be positioned either forward or backward from the current statement and can be repositioned to a given statement as many times as the application requires.
For COBOL programs with multiple compile units, the cursor can only be positioned backward if a REWIND or POSITION TO STATEMENT occurs in the same compile unit as the declaration and the opening of the cursor.
POSITION is valid with any cursor except an insertion cursor.
The statement set found by the cursor is not re-executed, but the cursor position in the spool file is adjusted accordingly.
You cannot execute POSITION as a dynamic SQL statement.
Related Topics
- POSITION being valid with any cursor except an insertion cursor, see DECLARE CURSOR, DECLARE CURSOR (Macro Form), DECLARE CURSOR (Request Form) and DECLARE CURSOR (Selection Form)
- POSITION, see REWIND.