Host structures in COBOL
A COBOL host structure is a named set of host variables that are defined in your program's WORKING-STORAGE SECTION or LINKAGE SECTION.
- COBOL host structures can have a maximum of two levels, even though the host structure might occur within a structure with multiple levels. However, you can declare a varying-length character string, which must be level 49.
- A host structure name can be a group name whose subordinate levels name elementary data items.
- If you are using the Db2 precompiler,
do not declare host variables or host structures on any subordinate
levels after one of the following items:
- A COBOL item that begins in area A
- Any SQL statement (except SQL INCLUDE)
- Any SQL statement within an included member
When you write an SQL statement that contains a qualified
host variable name (perhaps to identify a field within a structure),
use the name of the structure followed by a period and the name of
the field. For example, for structure B that contains field C1, specify B.C1 rather
than C1 OF B or C1 IN B.
Host structures
The following diagram shows the syntax for declaring host structures.
- 1 level-1 indicates a COBOL level in the range 1–47.
- 2 level-2 indicates a COBOL level in the range 2–48.
- 3 For elements within a structure, use any level 02 through 48 (rather than 01 or 77), up to a maximum of two levels.
- 4 Using a FILLER or optional FILLER item within a host structure declaration can invalidate the whole structure.
Numeric usage items
The following diagram shows the syntax for numeric-usage items that are used within declarations of host structures.
Integer and decimal usage items
The following diagram shows the syntax for integer and decimal usage items that are used within declarations of host structures.
CHAR inner variables
The following diagram shows the syntax for CHAR inner variables that are used within declarations of host structures.
VARCHAR inner variables
The following diagrams show the syntax for VARCHAR inner variables that are used within declarations of host structures.
VARGRAPHIC inner variables
The following diagrams show the syntax for VARGRAPHIC inner variables that are used within declarations of host structures.
- 1 For fixed-length strings, the format of picture-string is G(m) or N(m) (or, m instances of GG...G or NN...N), where 1 <= m <= 127; for other strings, m cannot be greater than the maximum size of a varying-length graphic string.
- 2 Use USAGE NATIONAL for only Unicode UTF-16 data. In the picture-string for USAGE NATIONAL, you must use N in place of G.
- 3 You can use USAGE NATIONAL only if you are using the Db2 coprocessor.
LOB variables, locators, and file reference variables
The following diagram shows the syntax for LOB variables, locators, and file reference variables that are used within declarations of host structures.
LOB variables and file reference variables for XML data
The following diagram shows the syntax for LOB variables and file reference variables that are used within declarations of host structures for XML.
Example
01 A
02 B
03 C1 PICTURE ...
03 C2 PICTURE ...To reference the C1 field in an SQL
statement, specify B.C1.