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.
  • OCCURS 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 (fixed) 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).