SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Static SQL Cursors
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
6-3
Steps for Using a Static SQL Cursor
Figure 6-2 shows the steps presented within the complete COBOL program. These 
steps are executed in the sample program Example C-1 on page C-1.
For more information:
1. Declare Required Host Variables on page 6-4
2. Declare the Cursor on page 6-4
3. Initialize the Host Variables on page 6-5
4. Open the Cursor on page 6-5
5. Retrieve the Values on page 6-6
6. Process the Retrieved Values on page 6-7
7. Fetch the Next Row on page 6-10
8. Close the Cursor on page 6-11
Figure 6-2. Using a Static SQL Cursor in a COBOL Program
 ...
 EXEC SQL BEGIN DECLARE SECTION END-EXEC. 
 01 HOSTVAR 9(4) COMP. 
 ...
 EXEC SQL END DECLARE SECTION END-EXEC.
 ...
 EXEC SQL DECLARE sql_cursor CURSOR FOR
 SELECT column_1, column_2, ..., column_n 
 FROM catalog.schema.table
 WHERE column_1 = :HOSTVAR 
 END-EXEC. 
 ...
 MOVE INITIAL-VALUE TO HOSTVAR. 
 ...
 EXEC SQL OPEN sql_cursor END-EXEC.
 ...
 EXEC SQL FETCH sql_cursor 
 INTO :HOSTVAR-1, :HOSTVAR-2, ..., :HOSTVAR-N 
 END-EXEC. 
 ...
* Process values in the host variable(s).
 ... 
* If last row has not been processed, 
* branch back to fetch another row.
 ...
 EXEC SQL CLOSE sql_cursor END-EXEC.
 ...
COBOL
1
2
3
4
5
6
7
8










