SQL/MP Programming Manual for COBOL

Host Variables
HP NonStop SQL/MP Programming Manual for COBOL529758-003
2-2
Coding Host Variable Names
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 COBOL 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.
Coding Host Variable Names
Use COBOL naming conventions for host variable names. A COBOL name can
contain from 1 to 30 alphanumeric characters, including letters, digits, and hyphens (-).
The first or last letter cannot be a hyphen. Letters can be uppercase, lowercase, or a
combination of both. HP COBOL names must contain at least one letter or hyphen.
You must also avoid using names that conflict with these SQL structures:
SQLINALL internal structure
SQLCA, SQLSA, and SQLDA structures
To use a COBOL record description as a host variable, specify the record name as a
level 01 entry and use level numbers 01 to 49, 66, 77, and 88 for the host variables.
The individual data items, and not the record name, are the host variables. You must
use declarations compatible with the SQL data types as shown in Table 2-1
on
page 2-3. You must also observe certain restrictions for the PICTURE clause. For more
information, see Using the COBOL PICTURE Clause
on page 2-7.
Using Corresponding SQL and COBOL Data
Types
Table 2-1 on page 2-3 lists the corresponding SQL and COBOL data types. You can
specify a COBOL data item as a host variable, if the COBOL data item has a
corresponding SQL data type.