Cobol

Figurative constants use in COBOL Programs

Figurative constants are reserved words that name and refer to specific constant values. These can be easily used by writing the word itself instead of the value.

The figurative constants supported by COBOL are:

 ZERO, ZEROS, ZEROES
 SPACE, SPACES
 HIGH-VALUE, HIGH-VALUES
 LOW-VALUE, LOW-VALUES
 QUOTE, QUOTES
 ALL literal - which means fill the field with ALL "M" etc.

Figurative constants Rules

Figurative constants are not allowed as function arguments except in an arithmetic expression, where the expression is an argument to a function. The length of a figurative constant depends on the context of its use. When a figurative constant represents a string of one or more characters, the length of the string is determined by your COBOL system from context by applying the following rules in order:

  1. When a figurative constant is specified in a concatenation expression, the length of the string is one character.
  2. When a figurative constant is either specified in a VALUE clause, or associated with another data item, (for example, when the figurative constant is moved to or compared with another data item), the string of characters specified is repeated character by character on the right until the size of the resultant string is greater than or equal to the number of character positions in the associated data item. This resultant string is then truncated from the right until the number of character positions remaining is equal either to 1 or to the number of character positions in the associated data item, whichever is greater. This is done prior to and independent of the application of any JUSTIFIED clause that can be associated with the data item.
  3. When a figurative constant is other than ALL literal, the length of the string is one character.
  4. The length of the string is the length of the literal. Use of figurative constants in Format 3 DISPLAY statements has specific effects, described in the General Rules for that statement.

ZERO or ZEROS or ZEROES: Represents the value ZERO – “0″, or one or more of the character ZERO – “0” depending on the context. 

  • When the context requires an alphanumeric character, an alphanumeric character zero is used.
  • When the context requires a national character zero, a national character zero is used (value NX’0030′).
  • When the context cannot be determined, an alphanumeric character zero is used.

e.g. VAR01 thru VAR03 represents a zero value; the VAR04 thru VAR06 represents five 0 characters.

       01 WS-VARIABLES
              05 WS-VAR01        PIC 9(5) VALUE ZERO.
              05 WS-VAR02        PIC 9(5) VALUE ZEROS.
              05 WS-VAR03        PIC 9(5) VALUE ZEROES.
              05 WS-VAR04        PIC X(5) VALUE ZERO.
              05 WS-VAR05        PIC X(5) VALUE ZEROS.
              05 WS-VAR06        PIC X(5) VALUE ZEROES.

COBOL input field editing

IF field-name IS [NOT] POSITIVE.
                        NEGATIVE.
                        ZERO.

Note: This test should be done on a numeric field. 

 IF AMT POSITIVE. Could be written as:  IF AMT > 0.
 IF AMT NEGATIVE.                       IF AMT < 0. 
 IF AMT ZERO.                           IF AMT = 0.
 

 IF field-name IS [NOT] NUMERIC.
                        ALPHABETIC.

Note: This test should be done on an alphanumeric field. 

Examples:

 IF FLD-IN NUMERIC.
 IF FLD-IN ALPHABETIC.
 
      INITIALIZE field-name1
                 ALPHABETIC
                 ALPHANUMERIC
      [REPLACING NUMERIC               DATA BY field-name2 ]             
            ALPHANUMERIC-EDITED           literal-1        
        NUMERIC-EDITED

SPACE or SPACES: Represents one or more of the character space or blank. SPACE is treated as an alphanumeric literal when used in a context that requires an alphanumeric character. This can be used to handle the blank spaces in the string variables. This can help in initializing the string with empty spaces, or moving spaces for modifying their value. It can also be used to overwrite the value of the string.

e.g. MOVE SPACES TO WS-VAR04

HIGH-VALUE or HIGH-VALUES: Represents one or more of the character that has the highest ordinal position in the program collating sequence. (Hexadecimal Value – X’FF’). HIGH-VALUE is treated as an alphanumeric literal in a context that requires an alphanumeric character. These are used to specify the highest possible value to some variables in a particular program.  In this the bit stream is actually in ‘ON’ state. All bits are set to high.

e.g. MOVE HIGH-VALUE TO WS-VAR04.

LOW-VALUE or LOW-VALUES: Represents one or more of the character that has the lowest ordinal position in the program collating sequence. (x”00″ for the ASCII character set). LOW-VALUE is treated as an alphanumeric literal in a context that requires an alphanumeric character. These are used to specify the lowest possible value or spaces to some variables in a particular program.  In this the bit stream is actually in ‘OFF’ state. All bits are set to low or ‘00000000’.

e.g. MOVE LOW-VALUE TO WS-VAR04.

QUOTE or QUOTES: Represents one or more of the character “””. The word QUOTE or QUOTES cannot be used in place of a quotation mark in a source program to bound a nonnumeric literal. Thus QUOTE ABD QUOTE is incorrect as a way of stating “ABD”. QUOTE or QUOTES represents an alphanumeric character when used in a context that requires an alphanumeric character and must be non-numeric. These cannot be used in place of a quotation mark or an apostrophe to enclose a non-numeric literal.  

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

ALL literal: Represents one or more characters of the string of characters comprising the literal. The literal must be either a nonnumeric literal or a national literal or a figurative constant other than ALL literal. This nonnumeric literal and this national literal may be concatenation expressions. When a figurative constant is used, the word ALL is redundant and is used for readability only. The figurative constant ALL literal must not be used with the CALL, INSPECT, INVOKE, STOP, or STRING statements.

NULL or NULLS: Represents one or more unset pointer or procedure-pointer values. A data item with USAGE POINTER or PROCEDURE-POINTER and with a value of NULL is guaranteed not to represent the address of any data item or procedure. The NULL value varies between environments and is generally consistent with the equivalent value used in non-COBOL languages for each environment.

e.g. MOVE SPACE        TO  WS-VAR01      
     MOVE SPACES       TO  WS-VAR01
     MOVE ALL SPACES   TO  WS-VAR01

COBOL Blog: Click Here IBM Reference:Click Here

Admin

Share
Published by
Admin

Recent Posts

Increase Transparency and Collaboration Product Backlog

A well-maintained product backlog is crucial for successful product development. It serves as a single…

2 months ago

Product Backlog – Incremental value to the customer

Incremental value to the customer refers to the gradual delivery of small, functional parts of…

2 months ago

Product Market, Customer’s Desire, Need, and Challenges

A Product Market refers to the group of potential customers who might be interested in…

2 months ago

PAL-EBM Professional Agile Leadership – EBM Certification

The Professional Agile Leadership - Evidence-Based Management (PAL-EBM) certification offered by Scrum.org is designed for…

5 months ago

PAL I Professional Agile Leadership Certification

The Professional Agile Leadership (PAL I) certification, offered by Scrum.org, is designed to equip leaders…

5 months ago

Scrum Master Certification: CSM, PSM, SSM

Choosing the right Scrum Master Certification depends on your current experience and career goals. If…

7 months ago