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
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.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
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
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.There must be an even number of hexadecimal digits.
General rule
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:
The literal may contain 1 to 31 digits.
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.
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
A national literal must contain at least one and at most 90 characters (excluding the literal delimiters).
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.
character-1 must be an EBCDIC character which has a UTF-16 equivalent.
General rule
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
A hexadecimal-national literal must contain at least 4 hexadecimal digits and at most 360 hexadecimal digits (excluding the literal delimiters).
The count of all hexadecimal digits must be a multiple of 4.
General rule
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:
The singular and plural forms of a figurative constant are equivalent and may be used optionally.
Except in the figurative constant ALL, literal, the word ALL has no function; it is used only to improve readability.
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.
Literal must be an alphanumeric or national literal, but not a figurative constant.
Symbolic-character must be specified in the SYMBOLIC-CHARACTERS clause of the SPECIAL-NAMES paragraph.
General rules:
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.
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.
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").
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.
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: Contents of FIELD:
|
[ALL] SPACE or [ALL] SPACES | One or more occurrences of the character space (X' 40' or X‘0020‘). | Statement: |
[ALL] HIGH-VALUE or [ALL] HIGH-VALUES | With COLLATING SEQUENCE unspecified: | Statement: Contents of FIELD: |
With COLLATING SEQUENCE specified: | Entry in SPECIAL-NAMES paragraph: ALPHABET ALPHATAB IS 193 THRU 1, 255 THRU 194. | |
[ALL] LOW-VALUE or [ALL] LOW-VALUES | With COLLATING SEQUENCE unspecified: | Statement: Contents of FIELD: |
With COLLATING SEQUENCE specified: | Entry in SPECIAL-NAMES paragraph: ALPHABET ALPHATAB IS "0" "1" "2". | |
[ALL] QUOTE or [ALL] QUOTES | One or more occurrences of the quotation mark. | Statement: Contents of FIELD: |
ALL literal | One or more occurrences of the string of characters composing the literal. The literal must be non-numeric. | Statement: Statement: Statement: |
[ALL] | 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: Statement: 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]).