COBOL data item classification

COBOL Level Number COBOL Data Types

Advertisements


The overall classification of COBOL data was three types based on its behavior.

The types are:


  1. Variables
  2. Literals/Constants
  3. Figurative/Predefined constants

Variables:


A variable or identifier or data-name is a name which is used to identify a memory location.

In other words, a variable is a name for the memory location which is allocated.

A Variable is a pointer to the starting memory bytes and up to the bytes declared in Declaration.


Rules:

A Variable name allows alphanumeric and hyphen (-).

A variable name not allows white spaces.


Example:

Let’s take the below example to understand better.


01 A		PIC X(10).
01 B.
	02 C  	PIC X(3).
	02 FILLER 	PIC X(3).

Let us assume that 10 bytes memory was allocated from 1000 to 1010 and 6 bytes memory is allocated from 1100 to 1106.

The below diagram representing memory bytes of above example.


Variable Diagram:



In the above example, A, B & C called as Variables.

A is declared as a variable to access the memory location from 1000 to 1010. So referring the data name A will simply access the 10 bytes data from memory location.

C is declared as a variable for to access the memory location from 1100 to 1103. So by referring the data name C will access the 3 bytes data from memory location.

But the memory allocated for FILLER can’t be accessed. Because FILLER is not a variable and there is no variable declared for it.

There was another possibility that B is declared as a group variable for the entire 6 bytes which includes C and FILLER declaration. So by referring data name C will access the 6 bytes data from memory.


Literals/Constants:


Literal is nothing but a data item which consists of data in it during the declaration itself.

Literal is nothing but a constant data item which had data already in it.

There are two types of Literals in COBOL.


  1. Numeric (ex: 255,1,34 etc..)
  2. Non-numeric (ex: ‘MAINFRAMES’, ‘COBOL’ etc..)

Let’s take the below example to understand better.


01 A		PIC X(10) VALUE ‘MAINFRAMES’.
01 B.
	02 C  		PIC X(3) VALUE ‘255’.
	02 FILLER 	PIC X(3) VALUE ‘456’.

Let us assume that 10 bytes memory was allocated from 1000 to 1010 and 6 bytes memory is allocated from 1100 to 1106.

The below diagram representing memory bytes of above example.


Diagram:



In the above example, A,C & FILLER are called as Constants.

A is declared as a constant to access the memory location from 1000 to 1010. So referring the data name A will simply access the 10 bytes data (MAINFRAMES) from memory location.

C is declared as a constant for to access the memory location from 1100 to 1103. So by referring the data name C will access the 3 bytes data (‘255’) from memory location.

B is declared as a group variable for the entire 6 bytes which includes C and FILLER declaration. So by referring data name C will access the 6 bytes data (‘255456’) from memory.


Figurative Constants:


Figurative constants are constants which are predefined in cobol.

Figurative constants are the like constants and those can be used to initialize the variables


Ex: SPACE, SPACES, ZERO, ZEROES, HIGH-VALUE, HIGH-VALUES, LOW-VALUE and LOW-VALUES.

Let’s take the below example to understand better.


01 A		PIC X(10) VALUE SPACES.
01 B.
	02 C  		PIC 9(3) VALUE ZEROES.
	02 FILLER 	PIC 9(3) VALUE LOW-VALUES.

After above code execution, the memory will be shown like below.


Diagram:



Variable A initialized with SPACES, B initialized with ZEROES and FILLER initialized with LOW-VALUES.


Practicle Example:


Code:



COBOL Level Number COBOL Data Types

Advertisements