Characters

260 Views


In COBOL, the indivisible unit of data is the character. The letters of the alphabet, digits, and special characters that form the COBOL character set.

The Integrated Language Environment* (ILE*) COBOL * language is restricted to the defined character set. 

Character-Strings

You can use character-strings containing single-byte characters to form:

  • COBOL words with DBCS character
  • COBOL words
  • Literals
  • PICTURE character-strings
  • Comment-entry text

COBOL Words

COBOL wods must be character-strings from the set of letters, digits, the hyphen, and the underscore. (The hyphen and the underscore cannot appear as the first or last character, however.)

In the ILE COBOL language, each lowercase letter is generally equivalent to the corresponding uppercase letter.

The five types of COBOL words are:

  • User-defined words
  • System-names
  • Function-names

System-Names

A system-name is a character-string that is defined by IBM to have a specific meaning to the system.

There are four types of system-names:

  • computer-name
  • language-name
  • implementer-name (which includes environment-name and assignment-name)
  • locale-name

Function-Names

A function-name is a word that is one of a specified list of words used in COBOL source programs.

A function-name specifies the mechanism provided by ILE COBOL to determine the value of an intrinsic function.

Reserved Words

A reserved word is a character-string with a predefined meaning in a COBOL source program, and can be used only as specified in the language defined formats.

There are five types of reserved words:

  • Keywords
  • Optional words
  • Special character words
  • Figurative constants
  • Special registers

Keywords: Keywords are reserved words that are required within a given clause, entry, or statement.

Optional Words: Optional words are reserved words that may be included in the format of a clause, entry, or statement in order to improve readability.

They have no effect on the meaning or execution of the program.

Special Character Words: There are two types of special character words:

  • Arithmetic operators: + - / * **
  • Relational operators: < > = =

Figurative Constants: Figurative constants are reserved words that name and refer to specific constant values.

The reserved words for figurative constants and their meanings are:

ZERO/ZEROS/ZEROES Represents one of the following, depending on the context:

  • The numeric value zero (0)
  • One or more occurrences of the nonnumeric character zero (0)

SPACE/SPACES Represents one or more blanks or spaces;treated as a nonnumeric literal. SPACES represent one or more double-byte spaces when used with DBCS data items. SPACES represent one or more single-byte UCS-2 spaces when used with national data items.

HIGH-VALUE/HIGH-VALUES Represents one or more occurrences of the character that has the highest ordinal position in the collating sequence used. For the NATIVE and EBCDIC collating sequences, the character is X'FF'; for the STANDARD-1 and STANDARD-2 collating sequences, the character is X'07'; for other collating sequences, the actual character used depends on the collating sequence. HIGH-VALUE is treated as a nonnumeric literal.

LOW-VALUE/LOW-VALUES Represents one or more occurrences of the character that has the lowest ordinal position in the collating sequence used. For the NATIVE, EBCDIC, STANDARD-1, and STANDARD-2 collating sequences, the character is X'00'; for other collating sequences, the actual character used depends on the collating sequence. LOW-VALUE is treated as a nonnumeric literal.

QUOTE/QUOTES Represents one or more occurrences of the quotation mark character and must be nonnumeric. QUOTE, or QUOTES cannot be used in place of a quotation mark or an apostrophe to enclose a nonnumeric literal.

ALL literal Represents one or more occurrences of the string of characters comprising the literal. The literal must be a nonnumeric literal or a figurative constant other than the ALL literal.

NULL/NULLS Represents a value used to indicate that a data item defined with the USAGE IS POINTER clause, USAGE IS PROCEDURE-POINTER clause, ADDRESS OF phrase, or ADDRESS OF special register does not contain a valid address. NULL can be used only where explicitly allowed in the syntax format. In the ILE COBOL language, a value of NULL is undefined.

 

Literals

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” on page 9). There are five types of literals:

  • Boolean
  • DBCS
  • National hexadecimal
  • Nonnumeric
  • Numeric Boolean Literals

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.

DBCS literals have the following format:

G" or N" The opening delimiter for a DBCS literal. " The closing delimiter for a DBCS literal.

Nonnumeric Literals

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 (").

Hexadecimal Literals: 

You can use hexadecimal notation to form a hexadecimal nonnumeric literal.

X" The opening delimiter for hexadecimal notation of a nonnumeric literal. (If the compiler option *APOST or the PROCESS statement option APOST is specified, the opening delimiter is X'.)

" The closing delimiter for hexadecimal notation of a nonnumeric literal. (If the compiler option *APOST or the PROCESS statement option APOST is specified, the closing delimiter is '.)

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 compiler converts the hexadecimal literal into an ordinary nonnumeric literal. Hexadecimal nonnumeric literals can be used anywhere nonnumeric literals can appear.

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.

Numeric Literals 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 integerappearing in a format represents a numeric literal that contains no decimal point. 

Floating-Point Literals:

Numeric literals may be either fixed-point or floating-point numbers. The rules for floating-point literal values are:

  • A floating-point literal is written in the form:

  • The sign is optional before the mantissa and the exponent; if you omit the sign, the compiler assumes a positive number.
  • The mantissa can contain between 1 and 16 digits. A decimal point must be included in the mantissa. v The exponent is represented by an E followed by an optional sign and one, two, or three digits.
  • The magnitude of a floating-point literal value must fall between 2.225073858507201E-308 and 1.797693134862315E+308. For values outside of this range, an E-level diagnostic will be produced and the value will be replaced by either 0 or 1.797693134862315E+308, respectively.

 

PICTURE Character-Strings

A PICTURE character-string consists of symbols that are composed of the currency symbol and certain combinations of characters in the COBOL character set.

Any punctuation character that appears as part of the specification of a PICTURE character-string is not considered as a punctuation character, but rather as a symbol used in the specification of that PICTURE character-string.

Comment-Entry Text A comment is a character-string that can contain any combination of characters from the EBCDIC character set. It has no effect on the execution of the program.

Separators

A separator can be a single punctuation character or a string of punctuation characters.

The following is a list of the COBOL separator characters and their meaning.

Post Comments