Fixed-length Tables


A fixed-length table has a predefined size and can't extend or shrink during the program's execution.

Syntax -

level-number variable OCCURS integer-number TIMES
    [ASCENDING|DESCENDING KEY IS key-variable]
    [INDEXED BY index-name].

Parameters -

  • level-number - A number (01-49) defining the level of the variable.
  • Variable - Name given to the table.
  • integer-number - The fixed size of the table, i.e., the number of occurrences or entries the table will have.
  • ASCENDING KEY or DESCENDING KEY key-variable - Specifies the table is sorting order (Either ascending or descending).
  • INDEXED BY index-name - Optional. If used, it declares an index for the table, which can be used to traverse and access the table elements.

Examples -

Scenario1 - Declare a table to store 10 student information.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-CLASS.
   05 WS-STUDENT       OCCURS 10 TIMES.
      10 STUDENT-ID       PIC 9(5).
      10 STUDENT-NAME     PIC X(30).

Explaining Example -

In this example:

  • WS-CLASS is a table that has 10 occurrences of WS-STUDENT.
  • Each WS-STUDENT consists of a STUDENT-ID (numeric) and a STUDENT-NAME (alphanumeric).
  • The table is of fixed length, i.e., it always has space for 10 student's details. We can't add an 11th student without changing the program and recompiling.