Javatpoint Logo
Javatpoint Logo

COBOL - Data Types

In programming languages, a data type or simply a type is an attribute of data which is used to explain the compiler or interpreter how the programmer intends to use the data. Every programming language must have data types. So, data types are used to define the type of variables used in a program.

In COBOL program, data division defines the variables used in the program. You must understand the following terms to describe data in the COBOL. Let's see the following terms:

  • Data Name
  • Level Number
  • Picture Clause
  • Value Clause
COBOL Data Types

Level Number

A level number defines in which position or level, we can define a data in the record.

Level Number Description
01 Record description Entry
02 to 49 Group and Elementary Items
66 Rename Clause Items
77 Items which cannot be sub-divided
88 Condition name entry

Elementary Items

Elementary items are the indivisible items. An elementary item contains a level number, picture clause, data name, and value clause (optional).

Group Items

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.

Example:

Data Name

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.

Example:

Picture Clause

Picture Clause defines the following items:

Data Type: It may be of any type like numeric, alphanumeric, or alphabetic.

Data Type Description
Numeric 0 to 9
Alphabetic A to Z/a-z
Alpha-numeric A-Z/a-z/0-9

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.

Symbol Description
9 Numeric.
Maximum Length of Numeric data type is 18.
A Alphabetic.
The maximum length of the alphabetic data type is 255.
X Alphanumeric
The maximum length of the Alphanumeric data type is 255.
S Sign
P Assumed Decimal

Example:

Let's see one example to show the PIC Clause:

Output:

COBOL Data Types

Value 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.

Example:

Let's see the example for VALUE Clause:

Output:

COBOL Data Types

Data type definitions for COBOL

In the following table, we are explaining the data type definitions and their descriptions for COBOL:

Data type Description COBOL
INT2 It is used to specify a 2-byte signed integer. PIC S9(4) USAGE IS BINARY
INT4 It is used to specify a 4-byte signed integer. PIC S9(9) USAGE IS BINARY
FLOAT4 It is used to specify a 4-byte single-precision floating-point number. COMP-1
FLOAT8 It is used to specify an 8-byte double-precision floating-point number. COMP-2
FLOAT16 It is used to specify a 16-byte extended-precision floating-point number. Not available
COMPLEX8 It is used to specify a short floating-point complex hex number: an 8-byte complex number, whose real and imaginary parts are each 4-byte single-precision floating-point numbers. Not available
COMPLEX16 It is used to specify a long floating-point complex hex number: a 16-byte complex number, whose real and imaginary parts are each 8-byte double-precision floating-point numbers. Not available
COMPLEX32 It is used to specify an extended floating-point hex number: a 32-byte complex number, whose real and imaginary parts are each 16-byte extended-precision floating-point numbers. Not available
POINTER It is used to specify a platform-dependent address pointer. USAGE IS POINTER
CHARn It is used to specify a string (character array) of length n. PIC X(n)

Next TopicCOBOL Verbs





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA