COBOL - Group home

Unbounded tables and groups

  

To define variable length tables in COBOL, we usually specify the OCCURS ... DEPENDING ON clause in the data description entry for an item contained within a group structure. While this defines an item with a variable number of occurrences at run time, in earlier versions before Enterprise COBOL V5.1, we also need to specify a maximum number of occurrences in the syntax, and hence a maximum size for the table and the containing group, which causes usability problems in some contexts.

 

In particular, this problem occurs when defining COBOL group structures that correspond to XML documents, where the XML document structure is defined by a general XML schema. For example, in an XML schema, unbounded constructs such as:

<xsd:element name="A" type="xsd:int" maxOccurs="unbounded" />

can be mapped to the following COBOL syntax:

05 A PIC S9(9) COMP-5 OCCURS 1 TO integer-2 DEPENDING ON data-name-1

 

But an artificial maximum occurrence limit integer-2 must be chosen. With an XML schema containing multiple such unbounded constructs, which may be nested, it is problematic to choose a mapping to COBOL while ensuring that the containing group does not exceed COBOL or system maximum limits.

 

To address this issue, in Enterprise COBOL V5.1, a new keyword UNBOUNDED is included in the syntax. See the new syntax below:

 



For certain syntax and semantic rules about unbounded tables, see "Variable-length tables" in the COBOL for z/OS knowledge center.

 

To work with unbounded tables and groups, you can take the following steps:
1. Use the OCCURS clause to code an unbounded table, according to the syntax shown above. For example:

02 utbl OCCURS 1 TO UNBOUNDED DEPENDING ON obj.
2. Code a group to contain the unbounded table defined, which makes the group unbounded:
01 ugrp.
02 utbl OCCURS 1 TO UNBOUNDED DEPENDING ON obj.
3. Define the OCCURS DEPENDING ON objects in the WORKING-STORAGE SECTION or LOCAL-STORAGE SECTION.
4. Process unbounded groups in the PROCEDURE DIVISION.

 

There are several restrictions that you need to be aware of when working with unbounded tables and groups. For more information, see "Working with unbounded tables and groups”.

 

In all, support for unbounded tables and groups improved usability in defining variable length tables and groups. Consider using unbounded tables when parsing an XML document with an unknown number of repetitive elements.