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:
  1. In the LINKAGE SECTION, define an unbounded table (with the syntax of OCCURS n TO UNBOUNDED), which will be part of an unbounded group.
  2. In the WORKING-STORAGE SECTION or LOCAL-STORAGE SECTION, define the OCCURS DEPENDING ON objects.
  3. In the PROCEDURE DIVISION, do these steps to process unbounded groups:
    1. Set the OCCURS DEPENDING ON objects.
    2. Use the LENGTH special register or the LENGTH intrinsic function to compute the total size of the group.
    3. Use the CALL statement to call a storage allocation service, such as the Language Environment® service CEEGTST. Allocate enough memory for the total length of the group. You will need a pointer to this memory (the CEEGTST service returns a pointer).
    4. Use the SET statement to establish addressability. For example, SET ADDRESS OF group TO pointer.
  4. 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 a CALL 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.

related references  
Example: Using unbounded tables for parsing XML documentsStart of change  
Example: ALLOCATE and FREE storage for UNBOUNDED tables (Enterprise COBOL for z/OS® Language Reference)End of change
  
Variable-length tables (Enterprise COBOL for z/OS Language Reference)  
OCCURS DEPENDING ON clause
(Enterprise COBOL for z/OS Language Reference)