COBOL Tutorial

Progress0 of 0 lessons

COBOL figurative constants

Figurative constants are reserved words that mean a fixed value: ZEROS, SPACES, HIGH-VALUE, LOW-VALUE, QUOTE, and ALL literal. When you use them with a data item, the compiler uses the right type and repeats the value to match the item’s length. They are handy for initializing, clearing, and comparing without hard‑coding lengths or character codes.

Common figurative constants

Figurative constants in COBOL
ConstantMeaning
ZERO, ZEROS, ZEROESNumeric zero or character zero(s); length from context
SPACE, SPACESSpace character(s); used to blank or clear alphanumeric fields
HIGH-VALUE, HIGH-VALUESHighest character in collating sequence (e.g. X'FF'); sentinels
LOW-VALUE, LOW-VALUESLowest character in collating sequence (e.g. X'00')
QUOTE, QUOTESQuotation mark character; e.g. to include quotes in a string
ALL literalRepeats the literal to fill the receiving item (e.g. ALL "-")

Singular and plural forms are equivalent: ZERO/ZEROS/ZEROES, SPACE/SPACES, HIGH-VALUE/HIGH-VALUES, LOW-VALUE/LOW-VALUES, QUOTE/QUOTES.

Using them in VALUE and MOVE

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
01 WS-NAME PIC X(30) VALUE SPACES. 01 WS-COUNT PIC 9(5) VALUE ZEROS. 01 WS-SENTINEL PIC X(10) VALUE HIGH-VALUE. *> Clear a field at runtime MOVE SPACES TO WS-NAME *> Initialize numeric to zero MOVE ZEROS TO WS-COUNT *> Compare to sentinel IF WS-KEY = HIGH-VALUE STOP RUN END-IF

VALUE SPACES gives WS-NAME 30 spaces. VALUE ZEROS gives WS-COUNT numeric zero. VALUE HIGH-VALUE fills WS-SENTINEL with the high-value character in each position. MOVE SPACES TO clears the receiving field to spaces regardless of its length.

QUOTE and ALL

QUOTE (or QUOTES) is the quotation-mark character. Use it when you need a quote inside a string delimited by quotes. ALL literal repeats the literal to fill the receiving item; e.g. MOVE ALL \"-\" TO WS-LINE fills WS-LINE with dashes. The literal can be one character or a short string; it is repeated until the receiving field is full.

Step-by-step: choosing a constant

  • Blanking or clearing text: use SPACES.
  • Numeric zero or zero-filled digits: use ZEROS.
  • Sentinel or “max” value that sorts last: use HIGH-VALUE.
  • Sentinel or “min” value: use LOW-VALUE.
  • Including a quote in a string: use QUOTE.
  • Filling with one repeated character/string: use ALL literal.

Explain like I'm five

Figurative constants are shortcut names for “all spaces,” “all zeros,” “the biggest character,” and so on. You say SPACES and the computer fills as many spaces as the box needs. You don’t have to count; the compiler does it.

Test Your Knowledge

1. Which figurative constant fills a field with blank characters?

  • ZEROS
  • SPACES
  • HIGH-VALUE
  • QUOTE

2. Are ZERO and ZEROS equivalent in COBOL?

  • No, ZERO is one character
  • Yes, they are the same figurative constant
  • Only in VALUE clause
  • Only for numeric fields

Related concepts

Related Pages