DECLARE CURSOR
The DECLARE CURSOR statement defines a cursor.
Invocation
This statement can be embedded only in a COBOL application program. It is not an executable statement.Syntax
Description
The following keyword parameters are defined for the DECLARE CURSOR statement:- cursor-name
- Names the cursor. The name must not identify a cursor that has already been declared in the source program.
- statement-name
- Identifies the prepared select-statement that specifies the result table of the cursor whenever the cursor is opened. The statement-name must not be identical to a statement name specified in another DECLARE CURSOR statement of the source program. For an explanation of prepared SELECT statements, see PREPARE.
Notes
Cursors in COBOL programs: In COBOL source programs, the DECLARE CURSOR statement must precede all statements that explicitly refer to the cursor by name.
Examples
This example declares a cursor named C1 for statement named DYSQL.
EXEC SQLIMS
DECLARE C1 CURSOR FOR DYSQL
END-EXEC.
EXEC SQLIMS
PREPARE DYSQL FROM :SELECT-STATEMENT
END-EXEC
EXEC SQLIMS OPEN C1 END-EXEC.
EXEC SQLIMS
FETCH C1 INTO :HOSPCODE, :HOSPNAME, :WARDNAME, :PATNAME
END-EXEC.
IF SQLIMSCODE = 100
PERFORM DATA-NOT-FOUND
ELSE
PERFORM GET-REST-OF-HOSP
UNTIL SQLIMSCODE IS NOT EQUAL TO ZERO.
EXEC SQLIMS CLOSE C1 END-EXEC.