77 Level Number


Info! Level number 77 has been set for deletion from the COBOL language. It has been explained here to understand better if you encounter it in an existing program. Level number 77 is not supposed to code in new programs.

In some scenarios, the variables are neither allowed to convert as group variables nor as elementary variables, for example - constants. They have no immediate relationship to any other variables. Those variables are called Individual variables.

The special purpose level number 77 is used to declare the individual variables. It's not part of any hierarchical structure and doesn't subordinate other variables.

Rules -

  • Individual variables declaration should begin in Area-A.
  • These variables should not be coded under any group variable.
  • These variables can’t be subdivided into elementary variables.
  • These variables should not be coded in the FILE SECTION.
  • Each name used for an independent variable should be unique in the program.

Differences between 01 and 77 level numbers –

  • The variables declared with 01 level numbers have an extra byte because of the chance that the variable can be grouped in the future and can use the extra byte as a pointer to the elementary items.
  • However, the variables declared with 77 level numbers do not have any extra byte allocated as the declaration itself specifies that the variable is individual. So, Level 77 reduces memory usage during runtime with no extra byte being used.
  • With latest enterprise COBOL versions, there are a few differences in how these levels work in terms of storage and processing. But still, in some rare scenarios, some untouched variables, like TOTALS, COUNTS, LOOP-COUNTERS, etc., are declared as individual variables.

Practical Example -


Scenario - Variable declaration using 77-level number and the variable usage in PROCEDURE DIVISION.

Code -

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

       DATA DIVISION.
       WORKING-STORAGE SECTION.

       01 WS-VAR1       PIC X(10) VALUE "MAINFRAMES".
      * Declaring individual variable	   
       77 WS-VAR2       PIC X(10) VALUE "MAINFRAMES". 

       PROCEDURE DIVISION.
 
           DISPLAY "WS-VAR1: " WS-VAR1.
           DISPLAY "WS-VAR2: " WS-VAR2.

           STOP RUN. 

Explaining Example -

In the above example:

  • WS-VAR1 is declared using level-01, and WS-VAR2 is declared with level-77.
  • We can't extend WS-VAR2 because it is an individual variable. We can extend WS-VAR1 if required, like below -
    01 WS-VAR1.
       05 WS-VAR11      PIC X(10).
       05 WS-VAR12      PIC X(10).
       05 WS-VAR13      PIC X(10).
       ...
       ...
       ...