Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Literals

A literal is a character-string whose value is determined by the characters of which it is composed; alternatively, the string may represent a reserved word which corresponds to a figurative constant. Each literal belongs to one of the following classes and categories: alphanumeric, national or numeric.

Alphanumeric and national literals consist of a character string which is enclosed within literal delimiters. Valid quotation symbols in literal delimiters are quotation marks ("...") or apostrophes (’...’). You should note, however, that a literal should close with the same quotation symbol that was used to open it. Both types of quotation marks may be used in a source unit to form literals.

A hexadecimal literal consists of hexadecimal digits. These are the digits 0 .. 9 together with the letters A .. F and a .. f. The members of pairs of uppercase/lowercase letters (e.g. a, A) are considered to be equivalent.

1. Non-numeric literals

Alphanumeric literals are of the class and category alphanumeric.

Format 1 (alphanumeric)


{"character-1..." | 'character-1...'}


Syntax rules

  1. An alphanumeric literal must contain at least one and at most 180 characters (excluding the literal delimiters).
    When an alphanumeric literal is used in conjunction with national data items, it may contain at most 90 characters.

  2. If character-1 is the same as the quotation symbol of the literal delimiter then character1 must be specified twice if it is to be represented as a (single) character in the literal. The duplicated quotation symbol counts as one character for the purposes of the length of the literal.

General rule

  1. An alphanumeric literal can contain all characters from the EBCDIC character set. The value of the alphanumeric literal is the string of the individual characters itself without literal delimiters.

Example 2-2

'CHARACTER'
"153.78"
"ADAM ""BDAM"" CDAM"

Format 2 (hexadecimal-alphanumeric)


{X | x} {"hexadecimal digit..." | 'hexadecimal digit...'}


Syntax rules

  1. A hexadecimal-alphanumeric literal must contain at least 2 hexadecimal digits and at most 360 hexadecimal digits (excluding the literal delimiters).
    When a hexadecimal alphanumeric literal is used in conjunction with national data items, it may contain at most 180 hexadecimal digits.

  2. There must be an even number of hexadecimal digits.

General rule

  1. The value of the hexadecimal literal is the bit pattern that corresponds to the string of hexadecimal digits.

Example 2-3

X"12ab"

2. Numeric literals

Numeric literals are of the class and category numeric. There are two types of numeric literals: fixed-point literals and floating-point literals.

  • Numeric fixed-point literals

    A fixed-point numeric literal is a string of characters chosen from the following set: the digits 0-9, the plus sign, the minus sign, and the decimal point.

    Fixed-point numeric literals must be formed according to the following rules:

    1. The literal may contain 1 to 31 digits.

    2. The literal may contain only one sign character. If a sign is used, it must be the leftmost character of the literal. An unsigned literal is assumed to be positive.

    3. The literal may contain only one decimal point. The decimal point may appear anywhere in the literal, except as the rightmost character. A decimal point designates an assumed decimal point location. (The assumed decimal point in any numeric literal or data item is the position where the compiler and the generated program assume the decimal point to be, though no internal memory position is reserved for a separate decimal point character.) A literal with no decimal point is an integer.

    The term integer is used to describe a numeric literal which is unsigned and greater than zero and which has no character positions to the right of the assumed decimal point.

    Example 2-4

    (Here, the assumed decimal point is represented by the character V.)

    Literal

    Location of assumed point

    Internal sign

    No. of digit positions assigned

    +123

    3.765

    -45.7

    123V

    3V765

    45V7

    +

    +

    -

    3

    4

    3

  • Numeric floating-point literals

    A numeric floating-point literal must have the following format:

    mantissa     exponent

    The mantissa consists of an optional sign followed by 1 to 16 digits with a decimal point. The decimal point may be specified anywhere in the mantissa.

    The exponent consists of the symbol E, followed by an optional sign and then by one or more digits (the exponent 0 can be written as 0 or 00).

    The literal must not contain blanks. The exponent must be specified immediately to the right of the mantissa.

    The sign is the only optional character in the format. An unsigned mantissa or an unsigned exponent is interpreted as positive.

    The value of the literal is the product of the mantissa and the power of 10 given by the exponent.

    The absolute value of a number represented by a floating-point literal must not exceed 7.2*10 .

Example 2-5

+1.5E-2=1.5*10-2

3. National Literals

National literals are of the class and category national.

Format 1 (national)


{N | n} {"character-1..." | 'character-1...'}


Syntax rules

  1. A national literal must contain at least one and at most 90 characters (excluding the literal delimiters).

  2. If character-1 is the same as the quotation symbol of the literal delimiter then character-1 must be specified twice if it is to be represented as a (single) character in the literal. The duplicated quotation symbol counts as one character for the purposes of the length of the literal.

  3. character-1 must be an EBCDIC character which has a UTF-16 equivalent.

General rule

  1. The value of the national literal is the string of national characters (without literal delimiters) which results from the conversion of the individual characters to UTF-16 representation.

Example 2-6

N’TSV’
n"1860"

Format 2 (hexadecimal-national)


{N | n} {X | x} {"hexadecimal digit..." | 'hexadecimal digit...'}


Syntax rules

  1. A hexadecimal-national literal must contain at least 4 hexadecimal digits and at most 360 hexadecimal digits (excluding the literal delimiters).

  2. The count of all hexadecimal digits must be a multiple of 4.

General rule

  1. The value of the hexadecimal literal is the bit pattern that corresponds to the string of hexadecimal digits.

Example 2-7

NX"005400530056"
nx’0031003800360030’

The same literals are consequently represented in "Example 2-6" above.

4. Figurative constants

The values of figurative constants are produced by the compiler and are indicated by the reserved words listed in table 6.

Syntax rules:

  1. The singular and plural forms of a figurative constant are equivalent and may be used optionally.

  2. Except in the figurative constant ALL, literal, the word ALL has no function; it is used only to improve readability.

  3. A figurative constant can be used wherever literal occurs in a format, with the following restrictions:

    • When literal is restricted to numeric literals, the only legal figurative constant is ZERO (ZEROS, ZEROES) without ALL specified.

    • When a syntax rule forbids the specification of figurative constants.

  4. Literal must be an alphanumeric or national literal, but not a figurative constant.

  5. Symbolic-character must be specified in the SYMBOLIC-CHARACTERS clause of the SPECIAL-NAMES paragraph.

General rules:

  1. If one of the figurative constants ZERO, SPACE, HIGH-VALUE, LOW-VALUE or QUOTE is used in a context which requires national characters, the figurative constant represents a national value. In all other cases where the figurative constant represents a character value, the figurative constant stands for an alphanumeric value.

  2. If a figurative constant represents a string of one or more characters, the compiler determines the length of the string according to the following rules (in this order):

    • If a figurative constant is specified in a VALUE clause or associated with another data item (e.g. moved to or compared with another data item), it is first duplicated to the right until the resultant string has at least as many character positions as the other data item.
      If this character-string has more character positions than the other data item following the duplication operation, the extra positions will be truncated from the right.
      If the data item has a length of zero, it is truncated to 1 character. Extension or truncation of the character-string of figurative constants takes place prior to and independently of any application of the JUSTIFIED clause to the other data item.

    • The character-string always has a length of 1 whenever the figurative constants is not ALL literal, particularly whenever the figurative constants occur in a DISPLAY, STOP, STRING or UNSTRING statement.

    • The length of the character-string is equal to the length of literal.

  3. If the figurative constants HIGH-VALUE[S] or LOW-VALUE[S] are used in a compilation unit (except for the ALPHABET clause), the character currently associated with this constant is dependent on the collating sequence defined for the program and belonging to the character set (see "OBJECT-COMPUTER paragraph", and "SPECIAL-NAMES paragraph").

  4. The figurative constant [ALL] symbolic-character stands for one or more of the characters specified as the value of symbolic-character in the SYMBOLIC-CHARACTERS clause of the SPECIAL-NAMES paragraph.

  5. The figurative constant ZERO represents the numeric value 0 or one or more "0" characters depending on the context in which it is used.

Table 6 lists the figurative constants and indicates the values they represent.

Figurative constant

Corresponding value

Example 1

[ALL] ZERO or


[ALL] ZEROS or


[ALL] ZEROES

One or more occurrences of the character 0

(X' F0' or X‘0030‘) or binary zero

(X' 00' ), depending on the description of the data item.

Statement:
MOVE ZEROS TO FIELD.


Contents of FIELD:

  • If FIELD is a binary item: X' 00000000'

  • If FIELD is an external decimal item: X' F0F0F0F0' (= C' 0000' )

  • If FIELD is an internal decimal item: X' 0000000F' .

[ALL] SPACE or


[ALL] SPACES

One or more occurrences of the character space (X' 40' or X‘0020‘).

Statement:
MOVE SPACE TO FIELD.
Contents of FIELD:
X‘40404040‘(= C‘'BLANK''BLANK' 'BLANK' 'BLANK' 'BLANK' ‘)

[ALL] HIGH-VALUE


or


[ALL] HIGH-VALUES

With COLLATING SEQUENCE unspecified:
One or more occurrences of the character that has the highest value in the EBCDIC or UTF-16 collating sequence (X'FF' or X' FFFF').

Statement:
MOVE HIGH-VALUE TO FIELD.


Contents of FIELD:
X‘FFFFFFFF‘(=C‘~~~~‘)

With COLLATING SEQUENCE specified:
The character with the highest position in the program collating sequence.

Entry in SPECIAL-NAMES paragraph: ALPHABET ALPHATAB IS 193 THRU 1, 255 THRU 194.
The highest position belongs to the character at the 194th position of the EBCDIC character set, i.e. the character A. A is assigned to HIGH-VALUE.

[ALL] LOW-VALUE


or


[ALL] LOW-VALUES

With COLLATING SEQUENCE unspecified:
One or more occurrences of the character that has the lowest value in the EBCDIC or UTF-16 collating sequence (X'00' or X' 0000').

Statement:
MOVE LOW-VALUE TO FIELD.


Contents of FIELD:
X' 00000000'

With COLLATING SEQUENCE specified:
The character with the lowest position in the program collating sequence.

Entry in SPECIAL-NAMES paragraph: ALPHABET ALPHATAB IS "0" "1" "2".
The lowest position belongs to the character 0.
0 is assigned to LOW-VALUE.

[ALL] QUOTE or


[ALL] QUOTES

One or more occurrences of the quotation mark.
Note:
The word QUOTE (or QUOTES) cannot be used in place of a quotation mark to enclose a non-numeric literal.

Statement:
MOVE QUOTE TO FIELD.


Contents of FIELD:
X’7F7F7F7F’ 2

ALL literal

One or more occurrences of the string of characters composing the literal. The literal must be non-numeric.

Statement:
MOVE ALL "A" TO ALPHA.
Contents of ALPHA: C' AAAA'


Statement:
MOVE ALL "12" TO ALPHA.
Contents of ALPHA: C' 1212'


Statement:
MOVE ALL "ABC" TO ALPHA.
Contents of ALPHA: C' ABCA'

[ALL]
symbolic-character

One or more repetitions of the character specified as the value of symbolic-character in the SYMBOLIC-CHARACTER clause of the SPECIAL-NAMES paragraph.

Description:
SYMBOLIC C0 IS 193


Statement:
MOVE ALL C0 TO ALPHA.


Contents of ALPHA: X‘C0C0C0C0‘


Table 6: COBOL figurative constants and values

1 In these examples it is assumed that, unless otherwise specified, ALPHA and FIELD are defined as PIC X(4).

2 Can be changed by option to X’7D’ (see "COBOL2000 User Guide" [1]).