SQL/MP Programming Manual for COBOL

Explicit Program Compilation
HP NonStop SQL/MP Programming Manual for COBOL529758-003
6-45
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 by using the PREPARE and EXECUTE (or EXECUTE
IMMEDIATE) statements. A dynamic CONTROL directive affects only dynamic SQL
statements prepared after the CONTROL directive in execution order, except as noted.
Note. A dynamic CONTROL TABLE directive with the TIMEOUT option affects all static and
dynamic SQL statements that follow in execution order (as opposed to listing order) until
another dynamic CONTROL TABLE directive resets the TIMEOUT option or until the program
encounters the end of the run-time data unit (RTDU) that contains the CONTROL TABLE
directive.