Friday, 26 July 2013

Simple Guidance For You In COBOL Data Types, Figurative Constant, Picture Clause.

In today's tutorial, I will discuss COBOL datatype. Data-type is quite important in every programming language and it is the first step towards learning a new programming language. I will discuss COBOL Data Types, Figurative Constant, Picture Clause with examples. 

Let's start with the tutorial. 

mainframe Forum
COBOL Datatype

COBOL is a simple and robust programming language. To keep your code simple and consistent it offers three types of COBOL data types: alphanumeric, numeric, and numeric edited. In the figure above, though, you can see that there are two other data types: alphabetic and alphanumeric edited.

Alphabetic data types can contain only alphabetic characters and spaces. Because this is limiting, you normally use alphanumeric instead of alphabetic data types.

    • Numeric - used for digits 0, 1, 2, 3.
    • Alphabetic - used only for upper and lower case letters.
    • Alphanumeric - used for both numeric and alphanumeric.
    • Edited Numeric - used for digits and special characters.
    • Edited Alphanumeric - used letters, digits, special characters.


In COBOL, term literal is a variable whose value does not change in a program. It is also known as constant. There is three types of constants in COBOL.
    • Numeric Literal.
    • Non-Numeric Literal.
    • Figurative Constant.

Numeric Literal.

A numeric literal is formed using only digits. The following are the rules to be followed while forming a numeric literal. May include a sign, which must be the extreme left character. There should not be any blank in between the sign and first Digit. May include a decimal point, which must not be the rightmost Character and Can have at most 18 digits.

Example - 42, +15.8, -0.98

Alphanumeric Literal.

An alphanumeric literal is used to display heading and labels. It is a string of characters from the COBOL characters set enclosed in double quotation marks and can be up to 160 characters longs.

Example - ‘ABCD123’, ‘$1234’

Figurative Constant.

The figurative constant is reserved words that refer to a specific constant value. The following are figurative constant and their meaning.


Represent the numeric value ZERO (0), or one or more occurrence of the non-numeric character zero (0), depending on the context. When content cannot be determined then non-numeric zero is used.


Represent one or more blank or spaces. Spaces are treated as non-numeric literal.


Represent one or more occurrences of the characters that have the highest ordinal position in the collating sequence used. High value is treated as non-numeric literal.


Represent one or more occurrence of the characters that has the lowest ordinal position in the collating sequence used. Low-Value is treated as non-numeric literal.


Represent one or more occurrences of the quotation mark character (“). Quotes or Quote cannot be used in place or quotation marks to enclose a numeric literal.

Picture Clause

The Picture clause specifies the data type and the amount of storage required for a data item. It is denoted by PICTURE (PIC). A PICTURE clause specifies only for elementary data items and consists of picture characters.

    • A   for alphabetic.
    • X   for alphanumeric.
    • 9   for numeric.
    • S   for a sign.
    • V   for an implied decimal point.

Value Clause

The value clause is an optional clause that is used to specify the initial value for the data item. The initial value can be a numeric literal, non-numeric literal or figurative constant. This initial value can be changed in the PROCEDURE DIVISION based on the requirement.


  01  EMP-REC.
      05 NAME      PIC X(20)     VALUE ‘SPACES’.
      05 AGE       PIC 9(02)     VALUES ZEROE.

No comments:

Post a comment