SQL/MX 2.x Reference Manual (H06.04+)

Embedded-Only SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
3-13
COBOL Examples of CLOSE
COBOL Examples of CLOSE
Declare and open a cursor, fetch a row of retrieved data, then close the cursor.
Note that in an actual program you would include processing the data in the host
variables hostvar1, hostvar2, and hostvar3, and looping back to fetch the
next row provided by the cursor.
...
EXEC SQL DECLARE cursor1 CURSOR FOR
SELECT COL1, COL2, COL3 FROM SALES.PARTS
WHERE COL1 >= :hostvar1
ORDER BY COL1
READ UNCOMMITTED ACCESS END-EXEC.
* Initialize value of hostvar1
...
EXEC SQL OPEN cursor1 END-EXEC.
...
EXEC SQL FETCH cursor1
INTO :hostvar1, :hostvar2, :hostvar3 END-EXEC.
...
EXEC SQL CLOSE cursor1 END-EXEC.
This example uses extended cursor and statement names in the PREPARE,
ALLOCATE CURSOR, OPEN, and CLOSE statements.
...
ACCEPT in-curspec.
...
EXEC SQL PREPARE :curspec FROM :in-curspec END-EXEC.
...
EXEC SQL ALLOCATE :extcur CURSOR FOR :curspec END-EXEC.
...
EXEC SQL OPEN :extcur END-EXEC.
* Process using the extended dynamic cursor.
...
EXEC SQL CLOSE :extcur END-EXEC.