Summary -

In this topic, we described about the 77 Level Number with detailed example.

The data items are non-contiguous or that are not having any hierarchical relationship with other data items are called independent data items.

These data items are defined in the WORKING-STORAGE and LINKAGE SECTIONs. These independent data items declared with 77 level number.

For example -

77 WS-VAR1      PIC X(10).

The independent data items not subdivided as elementary item or grouped as a group item. They have no immediate relationship to any other data items.

For example - Valid Declaration

77 WS-VAR1      PIC X(10).

For example - Invalid Declaration

77 WS-VAR.
 02 WS-VAR1      PIC X(10).
 02 WS-VAR2      PIC X(10).
02 WS-VAR.
  77 WS-VAR1     PIC X(10).

Each name used for an independent variable must be unique because they can't be qualified.

For example - WS-VAR1 should be unique in the entire program.

77 WS-VAR1      PIC X(10).

Level-77 items must begin in Area-A.

For example -

       77 WS-VAR1         PIC X(02). 

Level 77 reduce usage of memory during runtime with no extra byte being used hence it has no chance to add elementary items.

For example - WS-VAR occupies exactly 10 bytes of memory and no buffer memory reserved.

 77 WS-VAR1         PIC X(10).  

Practical Example -

Scenario - Below example describes how level number 77 used in COBOL programming.

Code -

Level number 77 program Code
***************************** Top of Data ******************************
       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID. LEVEL77.                                             
       AUTHOR. MAINFRAMESTECHHELP.                                      
       DATA DIVISION.                                                   
       WORKING-STORAGE SECTION.                                         
       01 WS-VAR1       PIC X(10) VALUE "MAINFRAMES".                   
       77 WS-VAR2       PIC X(10) VALUE "MAINFRAMES".                   
       PROCEDURE DIVISION.                                              
           DISPLAY "WS-VAR1: " WS-VAR1.                                 
           DISPLAY "WS-VAR2: " WS-VAR2.                                 
           STOP RUN.                                                    
**************************** Bottom of Data ****************************

Explaining Example -

In the above example, WS-VAR1 is declared using level-01 and WS-VAR2 is declared with level-77.

WS-VAR2 can't be extended because it is individual data item. WS-VAR1 can be extended 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).