Host Variables [ COBOL/HP-UX Language Reference for the Series 700 and 800 ] MPE/iX 5.0 Documentation
COBOL/HP-UX Language Reference for the Series 700 and 800
Host Variables
Host variables are data items defined in the COBOL program and used for
communicating values to and from the SQL system. They are defined using
ordinary COBOL syntax and can be in the File Section, the Working-Storage
Section, the Local-Storage Section or the Linkage Section. They can have
any level number from 1 to 48.
Within an EXEC SQL statement, host variables must be prefaced with a
colon (:) to identify them to the compiler.
The ANSI definition of SQL requires that the declaration of host
variables must be preceded by the statement:
EXEC SQL BEGIN DECLARE SECTION END-EXEC
and followed by:
EXEC SQL END DECLARE SECTION END-EXEC
Permissible data-types and their corresponding COBOL definitions are
described in the following sections.
Small Integer
A small integer (SMALLINT or int2) is a 2-byte binary item, which can be
represented in COBOL with USAGE BINARY, COMP, COMP-4, or COMP-5. If it
is defined as unsigned, a value larger than 32767 is treated as negative
by your database system.
Examples
Either
01 shortint1 pic s9(4) comp.
or
03 shortint2 pic s9(4) comp-5.
03 shortint3 pic x(2) comp-5.
03 shortint4 pic s9(4) comp-4.
Large Integer
A large integer (INTEGER or int4) is like a small integer except that it
is a 4-byte item. If it is defined as unsigned, a value larger than
2147483647 is treated as negative by your database system.
Examples
Either
01 longint1 pic s9(9) comp.
or
03 longint2 pic s9(9) comp-5.
03 longint3 pic x(4) comp-5.
Varying Length Character Strings
Varying length character strings (VARCHAR and LONG VARCHAR) are group
items containing just two elementary items, which must both have a level
number of 49. The first of these, which is a small integer, is used to
hold the effective length of the item. The second is PIC X(n), where n
is any integer up to 32700, and holds the actual data. The item is
classified as VARCHAR if n is less than or equal to 4000, and as LONG
VARCHAR otherwise.
Examples
01 varchar1.
49 varchar1-len pic 9(4) comp-5.
49 varchar1-data pic x(100).
03 longvarchar1.
49 longvarchar1-len pic 9(4) comp.
49 longvarchar1-data pic x(20000).
Fixed Length Character Strings
A fixed length character string (CHAR) is an alphanumeric item having a
maximum length of 254 characters.
Examples
Either
01 char-field1 pic x(3).
or
03 char-field2 pic x(254).
Decimal
The DECIMAL data type describes a packed-decimal item, with or without a
decimal point. In COBOL such items can be declared either as COMP-3 or
as PACKED-DECIMAL.
Examples
Either
01 packed1 pic s9(8)v99 usage comp-3.
or
48 packed2 pic s9(3) usage packed-decimal.
Float
The FLOAT data type describes a double-precision floating-point item. In
COBOL such items are declared as COMP-2.
Example
01 float2 usage comp-2.
MPE/iX 5.0 Documentation