Handling tables

About this task

A table is a collection of data items that have the same description, such as account totals or monthly averages. A table consists of a table name and subordinate items called table elements. A table is the COBOL equivalent of an array.

This image shows a one-dimensional table and associated storage layout. Link to detail.

In the example above, SAMPLE-TABLE-ONE is the group item that contains the table. TABLE-COLUMN names the table element of a one-dimensional table that occurs three times.

Rather than defining repetitious items as separate, consecutive entries in the DATA DIVISION, you use the OCCURS clause in the DATA DIVISION entry to define a table. This practice has these advantages:

  • The code clearly shows the unity of the items (the table elements).
  • You can use subscripts and indexes to refer to the table elements.
  • You can easily repeat data items.

Tables are important for increasing the speed of a program, especially a program that looks up records.

Related concepts  
Complex OCCURS DEPENDING ON