Working with unbounded tables and groups
You can process an unbounded group as the input parameter to a called program. The memory for the unbounded group is provided by the calling program. Alternatively, you can define, initialize, and process unbounded groups in a single program.
To work with unbounded tables and groups in a single
program,
do these steps:
- In the
LINKAGE SECTION
, define an unbounded table (with the syntax ofOCCURS n TO UNBOUNDED
), which will be part of an unbounded group. - In the
WORKING-STORAGE SECTION
orLOCAL-STORAGE SECTION
, define theOCCURS DEPENDING ON
objects. - In the
PROCEDURE DIVISION
, do these steps to process unbounded groups:- Set the
OCCURS DEPENDING ON
objects. - Use the
LENGTH
special register or theLENGTH
intrinsic function to compute the total size of the group. - Use the
CALL
statement to call a storage allocation service, such as the Language Environment® serviceCEEGTST
. Allocate enough memory for the total length of the group. You will need a pointer to this memory (theCEEGTST
service returns a pointer). - Use the
SET
statement to establish addressability. For example,SET ADDRESS OF group TO pointer
.
- Set the
- Use the unbounded table and its containing
unbounded
group according to the following rules:
- You can reference unbounded tables in COBOL syntax anywhere a table can be referenced.
- You can reference unbounded groups
in COBOL syntax anywhere an
alphanumeric or national group can be referenced, with the following
exceptions:
- You cannot specify unbounded groups as a
BY CONTENT
argument in aCALL
statement. - You cannot specify unbounded
groups as data-name-2 on
the
PROCEDURE DIVISION RETURNING
phrase. - You
cannot specify unbounded groups as arguments to intrinsic
functions, except as an argument to the
LENGTH
intrinsic function.
- You cannot specify unbounded groups as a
related references
Example: Using unbounded tables for parsing XML documents
Example: ALLOCATE and FREE storage for UNBOUNDED tables (Enterprise COBOL for z/OS® Language Reference)
Variable-length tables (Enterprise COBOL for z/OS Language Reference)
OCCURS DEPENDING ON clause
(Enterprise COBOL for z/OS Language Reference)
Example: Using unbounded tables for parsing XML documents
Example: ALLOCATE and FREE storage for UNBOUNDED tables (Enterprise COBOL for z/OS® Language Reference)
Variable-length tables (Enterprise COBOL for z/OS Language Reference)
OCCURS DEPENDING ON clause
(Enterprise COBOL for z/OS Language Reference)