SQL/MP Programming Manual for COBOL

HP NonStop SQL/MP Programming Manual for COBOL529758-003
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-3.
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.
Topics include:
Specifying a Declare Section
Coding Host Variable Names on page 2-2
Using Corresponding SQL and COBOL Data Types on page 2-2
Specifying Host Variables in SQL Statements on page 2-6
Using the COBOL PICTURE Clause on page 2-7
Using COBOL Data Description Clauses on page 2-9
Using Date-Time and INTERVAL Data Types on page 2-9
Using Indicator Variables for Null Values on page 2-11
Creating Host Variables Using the INVOKE Directive on page 2-14
Associating a Character Set With a Host Variable on page 2-25
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.