SQL/MP Programming Manual for COBOL

Introduction
HP NonStop SQL/MP Programming Manual for COBOL529758-003
1-2
Development of a COBOL Program
Development of a COBOL Program
You can embed static or dynamic SQL statements in a COBOL source file. You embed
a static SQL statement as an actual SQL statement and run the SQL compiler to
explicitly compile the statement before you run the program. To embed a dynamic SQL
statement, code a placeholder variable for the statement, and then construct, SQL
compile, and execute the statement at run time.
Host Variables
A host variable provides communication between COBOL statements and SQL
statements. A host variable is a COBOL data item with a data type that corresponds to
an SQL data type. You use host variables in SQL statements to receive data from a
database or to insert data into a database.
You declare host variables in a Declare Section in the Data Division. A Declare Section
is delimited by the BEGIN DECLARE SECTION and END DECLARE SECTION
directives. In this example, FILENUMBER and MESSAGE are host variables:
DATA DIVISION.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 FILENUMBER PIC 9(6) DISPLAY.
01 MESSAGE PIC X(200).
...
EXEC SQL END DECLARE SECTION END-EXEC.
The HP COBOL compiler accepts the CHARACTER SET clause in a host variable
declaration to associate a single-byte or double-byte character set, such as Kanji,
KSC5601, and ISO 8859/n with a host variable.
When you specify a host variable in an SQL statement, precede the host variable
name with a colon (:). In COBOL statements, you do not need the colon as shown:
EXEC SQL
SELECT COLUMN1 INTO :HOST-VARIABLE1 FROM =TABLEA
WHERE COLUMN1 > :HOST-VARIABLE2
END-EXEC.
MOVE HOST-VARIABLE1 TO NEW-NAME.
...
For more information, see Section 2, Host Variables
.
SQL/MP Statements and Directives
Table 1-1 on page 1-3 lists the SQL/MP statements and directives you can embed in a
COBOL program.