A literal is a character-string whose value is specified either by the characters of which it is composed, or by the use of a figurative constant (See page Figurative Constants). There are five types of literals:
+-------------------------------IBM Extension--------------------------------+
+----------------------------End of IBM Extension----------------------------+
+-------------------------------IBM Extension--------------------------------+
A Boolean literal is a character-string delimited on the left by the separator B" and on the right by the quotation mark separator. The character-string consists only of the character 0 or 1. The value of a Boolean literal is the character itself, excluding the delimiting separators.
+----------------------------End of IBM Extension----------------------------+
+-------------------------------IBM Extension--------------------------------+
DBCS literals have the following format:
Format >>-G"--DBCS-literal--"-----------------------------------------><
Format >>-N"--DBCS-literal--"-----------------------------------------><
In general, the rules for forming a nonnumeric literal also apply to DBCS literals. The maximum length of DBCS literals, however, is 28 double-byte characters, and they cannot be continued across lines.
DBCS literals can be specified in the Data Division:
DBCS literals can be specified in the Procedure Division:
DBCS literals can be specified wherever nonnumeric literals are allowed, except as a literal in the following:
+----------------------------End of IBM Extension----------------------------+
+-------------------------------IBM Extension--------------------------------+
National hexadecimal literals have the following format:
Format >>-NX"--hexadecimal-character-sequence--"----------------------><
The hexadecimal character sequence consists of groups of four hexadecimal digits that map to a Universal Character Set Version 2 (UCS-2) or Unicode character.
The maximum length of national hexadecimal literals is 512 national characters.
National hexadecimal literals can be specified in the following places:
The figurative constant SPACE/SPACES, ALL SPACE/SPACES, or ALL followed by a national hexadecimal literal can be a national hexadecimal literal. SPACE is single byte UCS-2 space (NX"0020").
+----------------------------End of IBM Extension----------------------------+
A nonnumeric literal is a character-string enclosed in quotation marks ("), and can contain any allowable character from the EBCDIC character set. The maximum length of a nonnumeric literal is 256 characters.
A nonnumeric literal must be enclosed in quotation marks (").
If the *APOST compiler option is in effect, the nonnumeric literal must be enclosed by apostrophes (').
The enclosing quotation marks (or apostrophes) are excluded from the literal when the program is compiled. An embedded quotation mark must be represented by a pair of quotation marks ("").
For example,
"THIS ISN""T WRONG"
+-------------------------------IBM Extension--------------------------------+
In an apostrophe literal, a double apostrophe ('') is reduced to a single apostrophe when the double apostrophe is also a delimiter.
For example,
'THIS ISN''T WRONG'
represents
THIS ISN'T WRONG
+----------------------------End of IBM Extension----------------------------+
Any punctuation characters included within a nonnumeric literal are part of the value of the literal.
Every nonnumeric literal is in the alphanumeric data category. (Data categories are described in Classes and Categories of Data.)
+-------------------------------IBM Extension--------------------------------+
You can use hexadecimal notation to form a hexadecimal nonnumeric literal.
Format >>-X"--hexadecimal-digits--"-----------------------------------><
Hexadecimal digits are characters that range from 0 to 9, a to f, and A to F, inclusive. Two hexadecimal digits represent a single character, so an even number of hexadecimal digits must be specified in each case.
The maximum length of a hexadecimal nonnumeric literal is 512 hexadecimal digits.
The continuation rules are the same as those for nonnumeric literals.
The compiler converts the hexadecimal literal into an ordinary nonnumeric literal. Hexadecimal nonnumeric literals can be used anywhere nonnumeric literals can appear.
+----------------------------End of IBM Extension----------------------------+
+-------------------------------IBM Extension--------------------------------+
Mixed literals are nonnumeric literals that combine single-byte and double-byte characters. Each string of double-byte characters must be delimited by an opening "shift-out" control character (hexadecimal 0E) and a closing "shift-in" control character (hexadecimal 0F), to distinguish it from single-byte data. The control characters are included in the length of the mixed literal. A double-byte character string may consist solely of the two control characters.
COBOL statements process mixed literals without sensitivity to the machine representation. Those statements that operate on a byte-to-byte basis (for example, STRING and UNSTRING) may produce character strings that are not valid mixtures of single-byte and double-byte characters. It is the user's responsibility to be certain that the statements are used correctly.
A mixed literal will only be recognized as such if the program is compiled using the GRAPHIC option of the PROCESS statement; otherwise, it will be treated as a simple non-numeric literal.
+----------------------------End of IBM Extension----------------------------+
+-------------------------------IBM Extension--------------------------------+
Nonnumeric literals can be null-terminated, with the following format:
Format
>>-Z"--+------------------------+--"---------------------------><
+-single-byte characters-+
+-DBCS characters--------+
'-mixed characters-------'
If a quotation mark is used in the opening delimiter, it must be used as the closing delimiter. Similarly, if an apostrophe is used in the opening delimiter, it must be used as the closing delimiter.
The content of the literal can include single-byte and/or double-byte characters, except that you cannot specify the single-byte character with the value X'00'. X'00' is the null character automatically appended to the end of the literal. The content of the literal is otherwise subject to the same rules and restrictions as a mixed literal.
The length of the string of single-byte and/or double-byte characters in the literal content can be 0 to 255 bytes. The actual length of the literal includes the terminating null character, giving a maximum length of 256 bytes.
A null-terminated nonnumeric literal has data class and category alphanumeric. It can be used anywhere a nonnumeric literal can be specified except that null-terminated literals are not supported in ALL literal figurative constants.
Avoid using a null-terminated literal to specify the external or internal object's name (such as program name, locale name, library name, procedure name, etc.) in a COBOL program; otherwise, compiler will replace the terminating null character by character "0", and a severity 20 error message will be issued to inform the user of this replacement.
The LENGTH intrinsic function, when applied to a null-terminated literal, returns the number of bytes in the literal prior to but not including the terminating null. (The LENGTH special register does not support literal operands.)
+----------------------------End of IBM Extension----------------------------+
A numeric literal is a character-string whose characters are selected from the digits 0 through 9, a sign character (+ or -), and the decimal point. If the literal contains no decimal point, it is an integer. (In this manual, the word integer appearing in a format represents a numeric literal that contains no decimal point. In some contexts, this literal is not permitted to have a negative value, or is not permitted to be zero. These restrictions, and any others that might be applicable, are included with the description of the format). The following rules apply:
+-------------------------------IBM Extension--------------------------------+
+----------------------------End of IBM Extension----------------------------+
+-------------------------------IBM Extension--------------------------------+
+----------------------------End of IBM Extension----------------------------+
The value of a numeric literal is the algebraic quantity expressed by the characters in the literal. The size of a numeric literal in standard data format characters is equal to the number of digits specified by the user.
Every numeric literal is in the numeric data category. (Data categories are described under Classes and Categories of Data.)
+-------------------------------IBM Extension--------------------------------+
Numeric literals may be either fixed-point or floating-point numbers. The rules for floating-point literal values are:
Format >>-+-----+--mantissa E--+-----+--exponent---------------------->< +- + -+ +- + -+ '- - -' '- - -'
A floating-point literal is of class numeric and category internal floating-point. In general, a floating-point literal can be used wherever a numeric decimal literal is allowed.
+----------------------------End of IBM Extension----------------------------+
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.