COBOL Data types

COBOL Data Classification COBOL Picture Clause

Advertisements


Data type describes the characteristics of the data items declared in the program.

All data items will be declared in DATA DIVISION. But based on the usage of the data items, declaring sections will change.

There are mainly five data types in COBOL.


  1. Numeric
  2. Alphabet
  3. Alpha-numeric
  4. Sign
  5. Assumed decimal point

The below is the table representation of data types and declaration.


Data TypeDeclarationData
Numeric90-9
AlphabetAA-Z/a-z
Alpha-numericXA-Z/a-z/0-9
SignS-/+
Assumed decimal pointP/V.(Dot)

Numeric:


Numeric data type name is self explanatory which will allow storing a combination of 0 to 9 numbers.

If any data item declared as Numeric, , then it will store the data which included 0-9 numbers that are used in the program.

Numeric data type uses 9 to declare the numeric data item.

The max length of numeric data type is 18. i.e. PIC 9(18).

NUMERIC data type declaration can be with a combination of other data types like V(Virtual decimal point),P(decimal point) and S(Sign).

All USAGE clauses are applicable for Numeric data type.

The Numeric topic explained in detail here


Alphabetic:


Alphabetic data type name is self explanatory which will allow storing a combination of A to Z characters.

If any data item declared as ALPHABETIC, then it will store the data which included A-Z characters that are used in the program.

Numeric data type uses A to declare the Alphabetic data item.

The max length of Alphabetic data type is 255

Alphabetic data type declaration will not come with a combination of any other data types.

DISPLAY USAGE clause is applicable for Alphabetic data type.

The Alphabetic topic explained in detail here


Alphanumeric:


Alphanumeric data type name is self explanatory which will allow storing a combination of 0 to 9 numbers and A to Z characters.

If any data item declared as Alphanumeric, then it will store the data which is a combination of 0 to 9 numbers and A to Z characters that are used in the program.

Alphanumeric data type uses X to declare the Alphanumeric data item.

The max length of Alphanumeric data type is 255

Alphanumeric data type declaration will not come with a combination of any other data types.

DISPLAY USAGE clause is applicable for Alphanumeric data type.

The Alphanumeric topic explained in detail here


Sign:


Sign data type is all about to declare the sign value for the numeric data type.

Sign data type uses S to declare the data item with sign.

The SIGN clause is used for only a signed numeric data item or data item entry whose usage is DISPLAY, or a group data item containing at least one such similar data description entry.

It states the position of the sign, whether leading or trailing, as well as whether the sign was formed by over punching in the first or last character of the data item or was formed separately.

Sign data type declaration will come with a combination of numeric data type only.

The Sign topic explained in detail here


Assumed decimal point:


Assumed decimal point allows to store period (.) for decimal values.

Assumed decimal point data type uses P/V to declare the data item which contains a decimal value.

Assumed decimal point data type declaration will come with a combination of numeric data type which is used to declare numeric data items.

DISPLAY USAGE clause is applicable for Assumed decimal point data type.

If the decimal point is in between the values, then V will be used in declaration.

The Assumed decimal point topic explained in detail here


COBOL Data Classification COBOL Picture Clause

Advertisements