Summary -
In this topic, we described about the Data Types with detailed example.
Data type describes the data items characteristics that are declared in the program. All data items get declared in DATA DIVISION.
There are mainly five data types in COBOL -
- Numeric
- Alphabetic
- Alphanumeric
- Sign
- Decimal point
The below is the table represents the data types, symbol and the allowed characters -
Data Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Numeric | Numeric data type allows to declare the data items to store the numeric decimal values. Numeric values are the combination of 0 to 9 numbers. Declaration Symbol - 9 Allowed Characters - 0 to 9. Example - 01 WS-NUM PIC 9(5). |
||||||||||||||||||||||||||||||||||||||||||||
Alphabet | Alphabetic data type allows to declare the data items to store the alphabetic strings. Alphabetic strings are the combination of A to Z or a to z characters. Declaration Symbol - A Allowed Characters -
01 WS-NUM PIC A(15). |
||||||||||||||||||||||||||||||||||||||||||||
Alpha-numeric | Alphanumeric data type allows to declare the data items to store the strings that are combination of alphabets and numbers. Alphanumeric strings are the combination of A to Z or a to z characters or 0 to 9 numbers. Declaration Symbol - X Allowed Characters -
01 WS-NUM PIC X(15). |
||||||||||||||||||||||||||||||||||||||||||||
Sign | Sign data type allows to declare the numeric data item with sign to capture the negative values. Sign can specify for numeric values. i.e. sign data types can come up with numeric data type. Declaration Symbol - S Allowed Characters - - (minus) or + (plus) Example - 01 WS-SIGNED-NUMBER PIC S9(5). |
||||||||||||||||||||||||||||||||||||||||||||
Decimal point | When a data comes as a decimal to the program, a data item should declare with decimal point to handle the decimal value. Declaration Symbol - P/V Allowed Characters - . (Dot) Example - 01 WS-TOTAL PIC 9(5)V9(2). 01 WS-SUM PIC 9(5)P. |