Tables of data are common components of business data processing problems. You define tables of data items in COBOL by including the OCCURS clause in their data description entries. This clause specifies that the item is to be repeated as many times as stated. The item is considered to be a table element, and its name and description apply to each repetition or occurrence. Because each occurrence of a table element does not have a unique data name assigned to it, you can refer to a desired occurrence only by specifying the data-name of a table element, along with the occurrence number of the desired element. The occurrence number is known as a subscript.
The number of occurrences of a table element may be specified to be fixed or variable. Although the number of occurrences of a table may be variable, the physical size of the table in computer memory is always fixed.
To define a one-dimensional table, use an OCCURS clause as part of the data description of the table element. The OCCURS clause must not appear in the description of group items which contain the table element. The following example shows a one-dimensional table defined by the item TABLE-ELEMENT.
01 TABLE-1. 03 TABLE-ELEMENT OCCURS 20 TIMES. 05 SUB-ELEMENT-1 ... 05 SUB-ELEMENT-2 ...
In the preceding example, the complete set of occurrences of TABLE-ELEMENT has been assigned the name TABLE-1. However, you need not give a group name to a table unless you want to refer to the complete table as a unit. In the preceding example, TABLE-ELEMENT, SUB-ELEMENT-1, and SUB-ELEMENT-2 are all repeated data items and require subscripts.
Defining a one-dimensional table within each occurrence of an element of another one-dimensional table gives rise to a two-dimensional table. For example:
01 TABLE-2. 03 BAKER OCCURS 20 TIMES. 05 CHARLIE ... 05 DOG OCCURS 5 TIMES ...
In the preceding example, DOG is a two-dimensional table; BAKER and CHARLIE are both one-dimensional.
Repeat this pattern to form multi-dimensional tables. Tables may have no more than 15 dimensions.