77 Level Number


Info! Level number 77 has been set for removal from the COBOL language. It has been explained here so that you can better understand it if you encounter it in existing programs. Level number 77 is not supposed to be coded in new programs.

In some scenarios, the variables are neither allowed to be converted to group variables nor elementary variables, such as constants. They have no immediate relationship to any other variables. Those variables are called Individual variables.

Special purpose level number 77 is to declare individual variables. It's important to note that level number 77 is not part of any hierarchical structure and does not subordinate other variables.

Rules to Remember -

  • Individual variables declaration should begin in Area A.
  • These variables should not be coded under any group.
  • These variables can’t be divided into elementary variables.
  • These variables should not be coded in the FILE SECTION.
  • Independent variable names should be unique in the program.

Differences between 01 and 77 level numbers –

  • The variables declared with 01-level numbers have an extra byte allocated because there is a 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 specifies that the variable is individual. So, Level 77 reduces memory usage during runtime, with no extra byte being used.
  • With the latest enterprise COBOL versions, there are a few differences in how these levels work in storage and processing. However, in rare scenarios, untouched variables, such as TOTALS, COUNTS, LOOP-COUNTERS, etc., still need to be declared as individual variables.

Practical Example -


Scenario - Declaring a variable using 77-level number and its usage in PROCEDURE DIVISION.

Code -

----+----1----+----2----+----3----+----4----+----5----+----6
       ...
       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.
		   ...