Summary -

In this topic, we described about the below sections -

Level Number plays most important role in the declaration of the variables in the application programming of COBOL. The level number specifies the hierarchy or levels of data entries/items.

A level number must be followed by a space or a separator period. A level number begins a data description entry, a renamed or redefined item or a condition-name entry.

Syntax -

Level Numbers Syntax
level-number -

A level-number is a one or two-digit integer value.

For example -
 01 .....
 02 .....
 .
 .
 49 .....

A level number followed by either by a separator period or by a space followed by its associated data-name, FILLER or appropriate data description clause.

For example -
 01 WS-VAR .....
 01 FILLER .....
 01 WS-VAR1.

A level-numbers 01 or 77 must begin in Area A and followed by either by a separator period or by a space followed by its associated data-name, FILLER or appropriate data description clause.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       01 WS-VAR1 .....
       01 FILLER  .....
       77 WS-VAR2 .....

A level-numbers 02 through 49 can begin in either Area A or Area B and must be followed by a space or a separator period.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       02 WS-VAR1     .....
           02 WS-VAR1 .....  
		   .
		   .
       49 WS-VAR2     .....
           49 WS-VAR2 ..... 

A level-numbers 66 and 88 can begin in Areas A or B and must be followed by a space.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       66 WS-VAR1     .....
           66 WS-VAR1 .....  
       88 WS-VAR2     .....
           88 WS-VAR2 ..... 

Single-digit level-numbers 1 through 9 can be substituted for level-numbers 01 through 09.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       1 WS-VAR1  .....   
				same as 
       01 WS-VAR1 ..... 
	   .
	   .
	   .
       9 WS-VAR2  .....
				same as 
       09 WS-VAR2 ..... 

Indentation does not affect the magnitude of a level-number. The extent of indentation to the right is limited only by the width of Area B.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       02 WS-VAR1 .....   --Valid 
	   02 WS-VAR1  .....   --Valid
			02 WS-VAR1  .....   --Valid 
					02 WS-VAR1  .....   --Valid 
						02 WS-VAR1 .....   --Valid 	   
data-name-1 -

Identifies the data item/variable used in the program. Data-name-1 must be the first word following the level-number.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       01 WS-VAR1 .....
       01 WS-DATA-ITEM  .....

The data item can be changed during program execution. Data-name-1 must be specified for level-66 and level-88 items and optional for other level numbers.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       66 WS-VAR1 .....			--	Valid
       88 WS-VAR2 .....			--	Valid
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       66 FILLER .....			--	Invalid
       88 FILLER .....			--	Invalid
FILLER -

FILLER is a data item that is not explicitly referred in a program. The keyword FILLER is optional.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       01 FILLER .....			--	Valid
       01        .....			--	Valid

If FILLER specified, must be the first word following the level-number.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       01 FILLER .....			

FILLER cannot be used with a condition-name.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       88 FILLER .....				-- Wrong

In a MOVE CORRESPONDING statement or an ADD CORRESPONDING or SUBTRACT CORRESPONDING statement, FILLER items are ignored.

Types -

Level numbers are two types based on their usage.

  • General purpose level numbers
  • Special purpose level numbers

General purpose level numbers -

General purpose level numbers are the level number that has no specialization and used for regular data item/variable declaration.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       01 WS-VAR .....				
	   .
	   .
       49 WS-VAR .....				

In this, Level number hierarchy starts from 01 through 49. The level numbers hierarchy should be in ascending order from lower number to higher number.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       01 WS-VAR .....				
	      02 WS-VAR2 .....
	         .
			    .
				49 WS-VAR49 .....				

Special purpose level numbers -

These level numbers are used for special purpose like RENAMES, individual data items and conditional names. These special purpose level numbers (66 and 88) always come up with combination of other level numbers.

For example -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       01 WS-VAR1 .....				
	   66 WS-VAR66 RENAMES WS-VAR1.
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
       01 WS-GENER PIC X(01).				
	  88 WS-MALE    VALUE "M".
	  88 WS-FEMALE  VALUE "F".

The special purpose level number are -

Level NumbersDescription
66 level number Used for Renaming(RENAMES clause)
77 level number Used for Individual elementary variables/data items declaration
88 level number Used for Conditional names declaration