SQL/MP Programming Manual for COBOL85
Explicit Program Compilation
HP NonStop SQL/MP Programming Manual for COBOL85—429326-004
6-42
Dynamic SQL Statements
This example varies the wait time for cursors that access the PARTS table. The default
wait time (60 seconds) applies only to the first cursor (CURSOR1):
PROCEDURE DIVISION.
...
200-DEFAULT-WAIT.
EXEC SQL
DECLARE CURSOR CURSOR1 FOR SELECT PARTNUM, PARTDESC, PRICE
FROM SALES.PARTS
WHERE (PARTNUM > :MIN-PARTNUM AND PARTNUM < :MAX-PARTNUM)
ORDER BY PARTNUM END-EXEC.
...
...
500-SHORT-WAIT.
EXEC SQL
CONTROL TABLE SALES.PARTS TIMEOUT .1 SECOND END-EXEC.
EXEC SQL
DECLARE CURSOR CURSOR2 FOR SELECT PARTNUM, PARTDESC, PRICE
FROM SALES.PARTS
WHERE (PARTNUM > :MIN-PARTNUM AND PARTNUM < :MAX-PARTNUM)
ORDER BY PARTNUM END-EXEC.
800-INFINITE-WAIT.
EXEC SQL
CONTROL TABLE SALES.PARTS TIMEOUT -1 SECOND END-EXEC.
EXEC SQL
DECLARE CURSOR CURSOR3 FOR SELECT PARTNUM, PARTDESC, PRICE
FROM SALES.PARTS
WHERE (PARTNUM > :MIN-PARTNUM AND PARTNUM < :MAX-PARTNUM)
ORDER BY PARTNUM END-EXEC.
...
Dynamic SQL Statements
A static CONTROL TABLE directive does not affect dynamic SQL statements. To use a
CONTROL TABLE directive with dynamic SQL statements, specify a dynamic
CONTROL TABLE directive using the PREPARE and EXECUTE (or EXECUTE
IMMEDIATE) statements. Additional considerations for using a CONTROL directive
with dynamic SQL statements follow:
•
To affect a cursor, you must code the CONTROL directive before the DECLARE
CURSOR statement. The CONTROL directive must also be in the same RTDU as
the DECLARE CURSOR statement. (An RTDU is a region of the program file that
contains both SQL source statements and object code.)










