SQL/MP Programming Manual for COBOL

Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for COBOL529758-003
10-37
Sample Dynamic SQL Program
Sample Dynamic SQL Program
Example 10-4 shows an HP COBOL program that constructs a set of SELECT
statements, prepares them, and retrieves the associated data.
Example 10-4. Sample Dynamic SQL Program (page 1 of 2)
?SQL
?INSPECT
?SYMBOLS
IDENTIFICATION DIVISION.
PROGRAM-ID.
COBEXT.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. TANDEM/16.
OBJECT-COMPUTER. TANDEM/16.
*
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CURSORS.
02 CURSOR-NAME PIC X(2) OCCURS 3 TIMES.
01 STATEMENTS.
02 STMT-NAME PIC X(2) OCCURS 3 TIMES.
01 STMT-TEXT.
02 TEXT-STRING PIC X(80) VALUE SPACES OCCURS 3 TIMES.
01 IDX PIC S9(4) COMP.
01 DISPLAY-VALUE PIC Z(5)9.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 ANSWER PIC 9(6) COMP.
* Note: the following three host variables are declared here
* because COBOL does not allow an OCCURS clause in a host
* variable. Table entries from outside the Declare Section
* are therefore moved into these host variables one by one,
* and the SQL operations are performed on the host variables.
01 TEMP-CURSOR-NAME PIC X(2).
01 TEMP-STMT-NAME PIC X(2).
01 TEMP-STMT-TEXT PIC X(80) VALUE SPACES.
EXEC SQL END DECLARE SECTION END-EXEC.
* Include SQLCA for error checking:
EXEC SQL INCLUDE SQLCA END-EXEC.
* Declare Extended Storage Section for SQLIN structures:
?NOLIST
EXTENDED-STORAGE SECTION.
?LIST