SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
4-1
4
Host Variables in COBOL Programs
Host variables are data items declared in a host application program and used in both
host language statements and embedded SQL statements. They provide
communication between SQL statements and the host language statements. An input
host variable transfers data from a host language program to an SQL/MX database,
and an output host variable transfers data from a database to the program.
This section describes:
•
Specifying a Declare Section on page 4-1
•
COBOL Host Variable Data Types on page 4-2
•
Using Corresponding SQL and COBOL Data Types on page 4-5
•
Specifying Host Variables in SQL Statements on page 4-9
•
Using Host Variables in a COBOL Program on page 4-10
•
Using COBOL Data Description Clauses on page 4-18
•
Using Indicator Variables in a COBOL Program on page 4-19
•
Creating COBOL Host Variables Using INVOKE on page 4-22
•
Character Set Examples on page 4-30
Specifying a Declare Section
You declare all host variables within an SQL Declare Section. When you specify a
Declare Section:
•
Use the BEGIN DECLARE SECTION statement to begin a Declare Section.
•
Use the END DECLARE SECTION statement to end a Declare Section.
•
The first item after BEGIN DECLARE SECTION must have level 01 or level 77.
•
For the best performance, declare the host variable as the same data type as the
column in the SELECT list. If you declare this way, you can use bulk moves to
input and output data.
•
You can specify more than one Declare Section in your source file, but do not nest
them.
•
Do not place a Declare Section within a COBOL record description.
•
Do not place any executable code within a Declare Section.
•
You can use SQL or host language comments in a Declare Section.
Example
This example uses host variable declarations in an SQL Declare Section:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 CUST-REC.
02 CUSTNUM PIC S9(4) COMP.
COBOL