Summary -

In this topic, we described about the Figurative Constants with detailed example.

Figurative constants are the constant values that are predefined in the COBOL language. These figurative constants are known to the COBOL language and perform the specific task if specified.

Below are the figurative constants in COBOL language -

  • ZERO, ZEROS, ZEROES
  • SPACE, SPACES
  • HIGH-VALUE, HIGH-VALUES
  • LOW-VALUE, LOW-VALUES
  • QUOTE, QUOTES
  • ALL
  • symbolic-character

ZERO, ZEROS, ZEROES -

ZERO specifies the numeric value ZERO(0), or ZEROES specifies two/more ZERO occurrences depending on context. The figurative constant is - ZERO, ZEROS, or ZEROES. These figurative constants are used to initialize numeric or alphanumeric variables with ZEROES. When cannot be determined the context, an alphanumeric character zero is used.

For example -

Initializing variable during declaration -

01 WS-FIGCONSTZ         PIC 9(10) VALUE ZEROES.

WS-FIGCONSTZ initializes with ZEROES.

Initializing variable in procedure division -

MOVE ZEROES TO WS-FIGCONSTZ.

Using for comparison -

IF WS-FIGCONSTZ EQUAL ZEROES
	......
END-IF.

SPACE, SPACES -

SPACE specifies one blank or space, and SPACES represent two or more blanks or spaces. SPACE is treated as an alphanumeric literal and requires an alphanumeric declaration.

For example -

Initializing variable during declaration -

01 WS-FIGCONSTS         PIC X(10) VALUE SPACES.

WS-FIGCONSTS initializes with SPACES.

Initializing variable in procedure division -

MOVE SPACES TO WS-FIGCONSTS.

Using for comparison -

IF WS-FIGCONSTS EQUAL SPACES
	......
END-IF.

HIGH-VALUE, HIGH-VALUES -

Represents one or more occurrences of the character that has the highest position in the assembling sequence used. HIGH-VALUE is treated as an alphanumeric literal in a context that requires an alphanumeric character. When the context is not determined, an alphanumeric context is assumed, and the value is X'FF' used.

For example -

Initializing variable during declaration -

01 WS-FIGCONSTH         PIC X(10) VALUE HIGH-VALUES.

WS-FIGCONSTS initializes with HIGH-VALUES.

Initializing variable in procedure division -

MOVE HIGH-VALUES TO WS-FIGCONSTH.

Using for comparison -

IF WS-FIGCONSTH EQUAL HIGH-VALUES
	......
END-IF.

LOW-VALUE, LOW-VALUES -

Represents one or more occurrences of the character that has the lowest position in the assembling sequence used. For example, LOW-VALUE is treated as an alphanumeric literal in a context that requires an alphanumeric declaration. When the context is not determined, an alphanumeric context is assumed, and the value X'00' is used.

For example -

Initializing variable during declaration -

01 WS-FIGCONSTL         PIC X(10) VALUE LOW-VALUES.

WS-FIGCONSTS initializes with LOW-VALUES.

Initializing variable in procedure division -

MOVE LOW-VALUES TO WS-FIGCONSTL.

Using for comparison -

IF WS-FIGCONSTL EQUAL LOW-VALUES
	......
END-IF.

QUOTE, QUOTES -

Represents one or more occurrences of -

  • The quotation mark character ("), if the QUOTE compiler option is in effect.
  • The apostrophe character ('), if the APOST compiler option is in effect.

QUOTE or QUOTES treats as an alphanumeric character in a context that requires an alphanumeric declaration. QUOTE and QUOTES can't replace a quotation mark or an apostrophe when they are enclosed to an alphanumeric literal.

For example -

Initializing variable during declaration -

01 WS-FIGCONSTQ         PIC X(10) VALUE QUOTES.

WS-FIGCONSTQ initializes with QUOTES.

Initializing variable in procedure division -

MOVE QUOTES TO WS-FIGCONSTQ.

Using for comparison -

IF WS-FIGCONSTQ EQUAL QUOTES
	......
END-IF.

ALL -

Literal ALL represents one or more occurrences of the characters string comprising the literal. ALL literal represents one or more occurrences of the characters string that compose the literal.

Using literal ALL has no meaning when the literal is a figurative constant and used only to increase the readability . The figurative constant ALL should not be used with the CALL, INSPECT, INVOKE, STOP or STRING statements.

For example -

Initializing variable during declaration -

01 WS-FIGCONSTS         PIC X(10).

Initializing variable in procedure division -

MOVE ALL SPACES TO WS-FIGCONSTS.

Using with INSPECT -

INSPECT WS-FIGCONSTS TALLYING WS-COUNT FOR ALL " ".

symbolic-character -

Symbolic-character represents one or more characters specified as a value of the symbolic-character in the SYMBOLIC CHARACTERS clause of the SPECIAL-NAMES paragraph. Symbolic-character always represents an alphanumeric character.

For example -

     ENVIRONMENT DIVISION.
     CONFIGURATION SECTION.
     SPECIAL-NAMES.
         SW0 IS SORT-SWITCH ON STATUS IS SORT-ON.

     PROCEDURE DIVISION.
           :
         IF SORT-ON
            CALL "SORTER"
         END-IF.

Example -

Let’s take the below example to understand better -

01 A		PIC X(10) VALUE SPACES.
01 B.
   02 C		PIC 9(3) VALUE ZEROES.
   02 FILLER	PIC 9(3) VALUE LOW-VALUES.

Once the above code is executed, A is initialized with SPACES, B is initialized with ZEROES, and FILLER initialized with LOW-VALUES.


Practical Example -

Scenario - Below example describes how the figurative constants used in COBOL programming.

Code -

Figurative constant program Code
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
       IDENTIFICATION DIVISION.                                         
       PROGRAM-ID. FIGCONST.                                            
       AUTHOR. MTH.                                                     
       DATA DIVISION.                                                   
       WORKING-STORAGE SECTION.                                         
       01  WS-VAR.                                                      
           05 WS-FIGCONSTH     PIC X(10) VALUE HIGH-VALUES.             
           05 WS-FIGCONSTL     PIC X(10).                               
           05 WS-FIGCONSTS     PIC X(10) VALUE SPACES.                  
           05 WS-FIGCONSTZ     PIC 9(10) VALUE ZEROES.                  
           05 WS-FIGCONSTQ     PIC X(10) VALUE QUOTES.                  
       PROCEDURE DIVISION.                                              
           DISPLAY "*****FIGURATIVE CONSTANT DISPLAY*****".             
           DISPLAY "HIGH-VALUES : " WS-FIGCONSTH.                       
                                                                        
           MOVE LOW-VALUES      TO  WS-FIGCONSTL.                       
           DISPLAY "LOW-VALUES  : " WS-FIGCONSTL.                       
                                                                        
           IF WS-FIGCONSTS EQUAL SPACES                                 
              DISPLAY "WS-FIGCONSTS INITIALIZED WITH SPACES"            
           END-IF.                                                      
           DISPLAY "SPACES      : " WS-FIGCONSTS.                       
                                                                        
           DISPLAY "ZEROES      : " WS-FIGCONSTZ.                       
                                                                        
           DISPLAY "QUOTES      : " WS-FIGCONSTQ.                       
           STOP RUN.                                                    
**************************** Bottom of Data ****************************

Output -

Figurative constant program Output

Explaining Example -

In the above example, we have shown how figurative constants are used in the COBOL program. We have initialized some figurative constant variables in WORKING-STORAGE SECTION, some in PROCEDURE DIVISION.

And it is also shown how the figurative constant is used in the IF condition for validation. Finally, the corresponding variables are displayed to see how the values are assigned.

Note! HIGH-VALUES, LOW-VALUES, and SPACES are not shown directly in general DISPLAY computation. Instead, we need to use the HEX ON option for validation to see their hexadecimal values.

Figurative constants display and their hexadecimal representation shown below -

Figurative constant program Output