Summary -
In this topic, we have explained about the below sections -
- A constant is a variable assigned with unique value and do not change throughout the program execution.
- COBOL does not have any predefined standards for constants except figurative constants.
- The programmer can define a variable with an initial value using the VALUE clause during the variable declaration.
- The values provided after the VALUE clause are literals, and the value doesn't change during the program's execution. The variable is considered as a constant variable, and the value is considered as a constant value.
Syntax -
level-number constant-variable
PIC data-type-character(constant-length)
VALUE constant-value.
For example - Declaring a variable of alphabetic type to store a value HELLO.
01 WS-PI PIC 9(2)V9(2) VALUE 3.14.
- level-number - Specifies the level number of the declaration from 01 to 49. In the above example, it is 01.
- constant-variable - Specifies the name of the constant. In the above example, it is WS-PI.
- data-type-character - Specifies the type of the variable. In the above example, it is 9.
- constant-length - Specifies the variable length to store the data. In the above example, it is 04.
- constant-value - Specifies the constant value. In the above example, it is 3.14.
Types -
Constants are three types, and those are –
- Numeric constants – Constants having only numeric values and do not require any quotes to declare them.
For example - 123, 657, 33443, 256478 etc,. - Alphanumeric constants/non-numeric constants – Constants having non-numeric, or alphabetic, or alphanumeric values. They require quotes while declaring them.
For example - "HELLO" "TRUE" "1" 'HI' '123' etc,. - Figurative Constants - Constants with values that are predefined in the COBOL language and used as replacements for standard values like spaces, zeroes, etc.
For example - ZERO, ZEROS, ZEROES, SPACE, SPACES, HIGH-VALUE, HIGH-VALUES etc,.
Let’s take the below example to understand better.
01 A PIC X(10) VALUE "MAINFRAMES".
01 B.
02 C PIC 9(3) VALUE 255.
02 FILLER PIC 9(3) VALUE ZEROES.
In the above example, MAINFRAMES is a non-numeric constant value, 255 is a numeric constant value, and ZEROES is a figurative constant value.
Figurative constants -
- Figurative constants are the constant names with predefined values in the COBOL language.
- These figurative constants are known to the COBOL language and replaces with predefined values to perform the task if specified.
List of Figurative Constants -
Below are the figurative constants in COBOL language -
Figurative constant | Description |
---|---|
ZERO, ZEROS, ZEROES | Specifies the numeric value ZERO(0) or one/more occurrences of the ZERO depending on the context. For example -
|
SPACE, SPACES | Represents one or more blanks or spaces. For example -
|
HIGH-VALUE, HIGH-VALUES | Represents one or more occurrences of the character with the highest position in the used assembling sequence. i.e., the value X'FF' is used. For example -
|
LOW-VALUE, LOW-VALUES | Represents one or more occurrences of the character with the lowest position in the used assembling sequence. i.e., the value X'00' is used. For example -
|
QUOTE, QUOTES | Represents one or more occurrences of -
For example -
|
ALL | Represents one or more occurrences of the figurative constant. ALL literal represents one or more occurrences of the figurative constant that compose the literal. The figurative constant should follow ALL. For example -
|
symbolic-character | Specifies one or more symbolic-characters defined in the SYMBOLIC CHARACTERS clause of the SPECIAL-NAMES paragraph. |
NULL, NULLS | Represents a value used while defining USAGE POINTER, USAGE PROCEDURE-POINTER, USAGE FUNCTION-POINTER, USAGE OBJECT REFERENCE, or the ADDRESS OF special register do not contain a valid address. For example -
|
Usage -
Figurative-constants used in many ways in the COBOL program. Those are specified below -
- Initialization in DATA DIVISION
For example -01 WS-VAR. 05 WS-VAR1 PIC 9(05) VALUE ZEROES. 05 WS-VAR2 PIC X(05) VALUE SPACES. 05 WS-VAR3 PIC X(10) VALUE HIGH-VALUES.
- Initialization in PROCEDURE DIVISION.
For example -MOVE ZEROES TO WS-VAR1. MOVE SPACES TO WS-VAR2. MOVE HIGH-VALUES TO WS-VAR3.
- Initializing entire variable (group variable)
For example -MOVE ALL ZEROES TO WS-VAR1. MOVE ALL SPACES TO WS-VAR2. MOVE ALL HIGH-VALUES TO WS-VAR3.
- Comparing the contents of the fields.
For example -IF WS-VAR1 EQUAL ZEROES ..... IF WS-VAR2 EQUAL SPACES ..... IF WS-VAR3 EQUAL HIGH-VALUES
Practical Example -
Scenario - The below example describes how the constants are used in COBOL programming.
Code -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7-
***************************** Top of Data ******************************
IDENTIFICATION DIVISION.
PROGRAM-ID. CONSTANT.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR.
05 WS-NUMCONST PIC 9(10) VALUE 256.
05 WS-NNUMCONST PIC X(05) VALUE "TRUE".
05 WS-FIGCONST PIC X(10) VALUE ZEROES.
05 WS-VAR1 PIC 9(10).
05 WS-VAR2 PIC X(20).
PROCEDURE DIVISION.
MOVE 256 TO WS-VAR1.
IF WS-VAR1 EQUAL WS-NUMCONST
DISPLAY "WS-VAR1 VALUE EQUAL TO NUMERIC CONSTANT"
ELSE
DISPLAY "WS-VAR1 VALUE NOT EQUAL TO NUMERIC CONSTANT"
END-IF.
MOVE "FALSE" TO WS-VAR2.
IF WS-VAR2 EQUAL WS-NNUMCONST
DISPLAY "WS-VAR2 VALUE EQUAL TO NON-NUMERIC CONSTANT"
ELSE
DISPLAY "WS-VAR2 VALUE NOT EQUAL TO NON-NUMERIC CONSTANT"
END-IF.
IF WS-FIGCONST EQUAL ZEROES
DISPLAY "WS-FIGCONST IS FILLED WITH ZEROES"
DISPLAY "FIGCONSTANT : " WS-FIGCONST
END-IF.
STOP RUN.
**************************** Bottom of Data ****************************
Output -

Explaining example -
In the above example, we have declared three constant variables. i.e., WS-NUMCONST is a numeric constant with a constant value of 256. WS-NNUMCONST is a non-numeric constant with a constant value "TRUE". Finally, WS-FIGCONST is a variable initialized with figurative constant ZEROES.
The COBOL program was written to explain the processing of constant variables. In the above example, hard-coded values are assigned to the variables for the reader's understanding. However, the values might be set in different ways like from other programs or communication areas, etc.