SQL/MP Programming Manual for COBOL85
HP NonStop SQL/MP Programming Manual for COBOL85—429326-004
2-1
2 Host Variables
A host variable is a data item you can use in both COBOL and NonStop SQL/MP
statements to provide communication between these two types of statements. A host
variable appears as a COBOL name and can be any COBOL data item declared in a
Declare Section that has a corresponding SQL data type as shown in Table 2-1,
Corresponding SQL and COBOL Data Types, on page 2-2.
For static SQL operations, a host variable can be an input or output variable (or both in
some cases) in SQL statements. An input variable transfers data from the program to
the database, whereas an output variable transfers data from the database to the
program. (For dynamic SQL operations, input parameters and output variables fulfill
the same function as input and output host variables in static SQL statements.)
An indicator variable is a two-byte integer variable, also declared in the Declare
Section, that is associated with a host variable. An indicator variable indicates whether
a column contains, or can contain, a null value. A null value means that a value is
either unknown for the row or does not apply to the row. A program uses an indicator
variable to insert null values into a database or to test a column value for a null value
after retrieving the value from a database.
Specifying a Declare Section
You declare all host variables in a Declare Section. The BEGIN DECLARE SECTION
and END DECLARE SECTION directives designate a Declare Section. Follow these
guidelines when you specify a Declare Section:
•
Use the BEGIN DECLARE SECTION and END DECLARE SECTION directives
only in pairs. A period after the END-EXEC key words for either directive is
ignored.
•
Place a Declare Section in the Data Division. You can specify more than one
Declare Section in a program, if necessary, but you cannot nest Declare Sections.
•
Do not place a Declare Section within a COBOL record description.
•
The first item after the BEGIN DECLARE SECTION directive must have level 01.
•
The only directives you can specify in a Declare Section are the COBOL85
compiler SOURCE directive and the SQL INVOKE directive.
•
Use COBOL comment statements to document a Declare Section.
This example shows the declaration of host variables in a Declare Section:
DATA DIVISION.
..
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 CUSTNUM PIC S9(4) COMP.
01 CITY PIC X(14).
EXEC SQL INVOKE SALES.PARTS AS SALES-REC END-EXEC.
?SOURCE COBLIB(DECLARES)
..
EXEC SQL END DECLARE SECTION END-EXEC.