Fixed length Tables Example


Scenario - Declare a table to store 05 student information.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. TBFIXLEN.
       AUTHOR. MTH.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-CLASS.
          03 WS-STUDENT  OCCURS 05 TIMES.
             05 WS-ROLL-NO      PIC 9(05) VALUE 1.
             05 WS-NAME         PIC X(30) VALUE 'STUDENT'.

       PROCEDURE DIVISION.
           DISPLAY "CLASS INFO: " WS-CLASS.
           STOP RUN.

Output -

CLASS INFO: 00001STUDENT                       00001STUDENT                       
00001STUDENT                       00001STUDENT                       00001STUDENT

Explaining Example -

In this example:

  • WS-CLASS is a table that has 05 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 05 student's details and it is fixed before program running. We can't add an 6th student without changing the program and recompiling.