COBOL - Data Types
As we know, Data types are used to define the type of variables used in a program.
In COBOL, data division defines the variables used in the program. Let's see the following terms. These terms are used to describe data in the COBOL.
A level number defines in which position or level, we can define a data in the record.
Elementary items are the indivisible items. An elementary item contains a level number, picture clause, data name, and value clause (optional).
It is a set of one or more elementary items. A group item contains a level number, data name, and value clause (optional). The level number for group items is always 01.
In the data division section, data names must be specified before they are used in the procedure division.
Data names must have a name specified by the user; the reserved words cannot be used. Data names refer to the memory locations where the actual data is stored. There can be elementary items or group items.
Picture Clause defines the following items:
Data Type: It may be of any type like numeric, alphanumeric, or alphabetic.
Sign: With numeric data, this can be used. It can either be - or +.
Decimal Point Position: With numerical data, this can be used. The assumed decimal point enables the decimal values to store the period or dot (.).
Length: Length is used to describe the amount of bytes that the data item will use.
Let's see one example to show the PIC Clause:
The value clause is an optional clause for initializing data objects. The values may be numeric literal, figurative constant, or alphanumeric literal. The value clause can be used with elementary items as well as group items.
Let's see the example for VALUE Clause: