SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Host Variables in COBOL Programs
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
4-9
Specifying Host Variables in SQL Statements
Converting Numeric Types
Values of data types NUMERIC, DECIMAL, PICTURE 9’s, INTEGER, SMALLINT,
FLOAT, REAL, and DOUBLE PRECISION are numbers and are all mutually
comparable and mutually assignable.
NonStop SQL/MX converts data between signed and unsigned numeric types and
between numeric types with different precision.
If assignment would result in a loss of significant digits, NonStop SQL/MX returns a
data exception condition in SQLSTATE. See Table 13-1 on page 13-2.
Converting Character Types
Values of data types CHARACTER, PICTURE X’s, and CHARACTER VARYING are
character strings and are all mutually comparable and mutually assignable if both are
of the same character set. In addition, UCS2 host variables are mutually comparable
and assignable with ISO88591 nonhost variable objects.
For character strings of different lengths, NonStop SQL/MX pads the receiving string
variable on the right with blanks as necessary.
If the receiving string variable is too short, NonStop SQL/MX truncates the right part of
the string retrieved from the database and returns a data exception condition in
SQLSTATE. See Table 13-1 on page 13-2.
Specifying Host Variables in SQL Statements
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.
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 and 77 for the host variables. The
individual data items, and not the record name, are the host variables.
After you declare a host variable, to specify it within an embedded SQL statement, use:
variable-name
is the host variable name. It can be any valid host language identifier with a data
type that corresponds to an SQL data type. You must precede variable-name
with a colon (:) within an SQL statement.
:variable-name [{OF|IN} record-name]
[[INDICATOR] :indicator_variable [{OF | IN} record-name]]