Concepts of the COBOL Language

This chapter explains the concepts of the COBOL language.

Character Set

The most basic and indivisible unit of the language is the character. The set of characters used to form COBOL character-strings and separators includes the letters of the alphabet, digits and special characters, and is defined below:

Character Meaning
0 to 9 Digits
A to Z Upper-case letters
ANS85a to z Lower-case letters
  Space
+ Plus sign
- Minus sign or hyphen
* Asterisk
/ Oblique stroke/slash
= Equal sign
$ Dollar sign
. Period or decimal point
, Comma or decimal point
; Semicolon
" Quotation mark
ISO2002OSVSVSC2MF' Apostrophe
( Left parenthesis
) Right parenthesis
> Greater than symbol
< Less than symbol
ANS85: Colon
MFXOPEN& Ampersand
ISO2002_ Underscore

ANS85Lower-case letters can be used in character strings and text words; except when used in nonnumeric literals and except for some picture symbols, each lower-case letter is equivalent to the corresponding upper-case letter.

This COBOL implementation is restricted to the above character set, but the content of nonnumeric literals, comment lines, comment entries and data can include any of the characters available under the character encoding scheme used for the COBOL compilation group. (See the topic Character Sets and Collating Sequences.)

Language Structure

The individual characters of the language are concatenated to form character-strings and separators. A separator can be concatenated with another separator or with a character-string. A character-string can be concatenated only with a separator. The concatenation of character-strings and separators forms your source text.

Separators

A separator is a string of one or more punctuation characters. The rules for formation of separators are:

  1. The punctuation character space is a separator. Wherever a space is used as a separator or as part of a separator, more than one space can be used. All spaces immediately following the separators comma, semicolon, or period are considered part of that separator and are not considered to be the separator space.
  2. Except when the comma is used in a PICTURE character-string, the punctuation characters comma and semicolon, immediately followed by a space, are separators that can be used anywhere the separator space is used.
  3. The punctuation character period, when followed by a space, is a separator. It must be used only to indicate the end of a sentence, or as shown in formats.
  4. The punctuation characters right and left parenthesis are separators. Except in pseudo-text, parentheses can appear only in balanced pairs of left and right parentheses delimiting subscripts,

    ANS85a list of function arguments, reference modifiers,

    arithmetic expressions, or conditions.

  5. The opening delimiters and closing delimiters of literals are separators.

    ISO2002OSVSVSC2MFEither an apostrophe or a quotation mark may be used as the quotation symbol character in opening and closing delimiters.

    The opening delimiters of literals are:

    The closing delimiters of literals are:

    The opening delimiter must be immediately preceded by a space, left parenthesis or opening pseudo-text delimiter. The closing delimiter must be immediately followed by one of the separators space, comma, semicolon, period, right parenthesis or closing pseudo-text delimiter. Separators immediately preceding the opening delimiter are not part of the opening delimiter. Separators immediately following the closing delimiter are not part of the closing delimiter.

  6. Pseudo-text delimiters are separators. An opening pseudo-text delimiter must be immediately preceded by a space; a closing pseudo-text delimiter must be immediately followed by one of the separators space, comma, semicolon, or period.

    MFThe space immediately preceding the opening pseudo-text delimiter can be omitted.

    Pseudo-text delimiters can appear only in balanced pairs delimiting pseudo-text

    MFand verb-signatures

    . (See the topic Source Text Manipulation and the topic Method Interface Definition.)

  7. The COBOL character colon, except as part of the invocation operator, is a separator and is required when shown in the general formats.
  8. The separator space can immediately precede all separators except the following:
    1. As specified by reference format (see the section Reference Format in the chapter Language Fundamentals).
    2. The separator closing quotation mark. In this case, a preceding space is considered as part of the nonnumeric literal and not as a separator.
    3. The opening pseudo-text delimiter, where the preceding space is required.
  9. The separator space can optionally immediately follow any separator except the opening quotation mark. In this case, a following space is considered as part of the nonnumeric literal and not as a separator.

Any punctuation character which appears as part of the specification of a PICTURE character-string (see the topic The PICTURE Clause) or numeric literal is not considered to be a punctuation character, but rather a symbol. PICTURE character-strings are delimited only by the separators space, comma, semicolon, or period.

The rules established for the formation of separators do not apply to the characters which comprise the contents of nonnumeric literals, comment-entries, or comment lines.

Character-strings

A character-string is a character or a sequence of contiguous characters forming a COBOL word, a literal, a PICTURE character-string, or a comment-entry. A character-string is delimited by separators.

COBOL Words

ANS85A COBOL word is a character-string of not more than 30 characters which forms a compiler-directive word, a context-sensitive word, user-defined word, a system-name, a reserved word, or an intrinsic-function-name. Each character of a COBOL word that is not a special character word is selected from the set of letters, digits, the hyphen

ISO2002and the underscore
.

The hyphen

ISO2002or the underscore

may not appear as the first or last character in such words. Each lower-case letter is considered to be equivalent to its corresponding upper-case letter.

ISO2002The character-string may contain 31 characters.

ANS85Within a source element the following apply:

  1. For all COBOL words excluding the words LENGTH, RANDOM, and SUM:
    1. Reserved words form disjoint sets with user-defined words, system-names and intrinsic-function-names.
    2. User-defined words, system-names and intrinsic-function-names form intersecting sets. The same COBOL word may be used as a user-defined word, a system-name and an intrinsic-function-name. The classification of a specific occurrence of such COBOL words is determined by the context of the clause or phrase in which it occurs.
  2. For the COBOL words LENGTH, RANDOM, and SUM:
    1. The reserved words LENGTH, RANDOM and SUM form an identical set with the intrinsic-function-names LENGTH, RANDOM and SUM. The same COBOL word LENGTH, RANDOM, or SUM may be used as an intrinsic-function-name and as a reserved word. The classification of a specific occurrence of such COBOL words is determined by the context in which it occurs.
    2. The COBOL words LENGTH, RANDOM, and SUM form disjoint sets with user-defined words and system-names. They may not be used as a system-name or user-defined word regardless of context.

User-Defined Words: A user-defined word is a COBOL word that must be supplied by the user to satisfy the format of a clause or statement.

The types of user-defined words are:

Within a given source element the following user-defined words are grouped into the following disjoint sets:

All user-defined words, except segment-numbers and level-numbers, can belong to one and only one of these disjoint sets. Furthermore, all user-defined words within a given disjoint set must be unique, except as specified in the section Uniqueness Of Reference.

With the exception of paragraph-name, section-name, level-number and segment-number, all user-defined words must contain at least one alphabetic character

MFor one occurrence of the hyphen character
.

Segment-numbers and level-numbers need not be unique; a given specification of a segment-number or level-number can be identical to any other segment-number or level-number and can even be identical to a paragraph-name or section-name.

The following user-defined words are externalized to the operating environment:

  1. Program-names of programs that are not contained in other programs,

    ISO2002MFclass-names,

    ISO2002function-prototype-names, interface-names,

    ISO2002MFmethod-names,

    ISO2002program-prototype-names, user-function-names
    .

  2. ANS85Data-names, file-names, and record-names of items described with the EXTERNAL attribute.

If a literal is specified in place of or in addition to one of these names, the content of the literal is the name that is externalized to the operating environment in a case-sensitive manner. If no literal is specified, the externalized name is created by folding the name to upper case. The Compiler directive FOLD-CALL-NAME can be used to control the case of externalized class-names, interface-names and program-names. The F and U options of the Compiler directive OOCTRL can be used to control the case of externalized method-names. +F and -U cause method-names to be folded to lower case, which is the default.

Condition-name: A condition-name is a name which is assigned to a specific value, set of values, or range of values, within a complete set of values that a data item can assume. The data item itself is called a conditional variable. Condition-names can be defined in the Data Division or in the Special-Names paragraph within the Environment Division where a condition-name must be assigned to one or both of the ON STATUS or OFF STATUS of the run-time switches.

A condition-name is used only as follows:

  1. In the RERUN clause.
  2. In conditions as an abbreviation for a relation condition. This relation condition posits that the associated conditional variable is equal to one of the set of values to which that condition-name is assigned.
  3. In a SET statement indicating that the associated value is to be moved to the conditional variable.
MF Constant-name: A constant-name is a name which is assigned as the name of a fixed value.
Mnemonic-name: A mnemonic-name assigns a user-defined word to an implementor-name. These associations are established in the Special-Names paragraph of the Environment Division. (See the topic The Special-Names Paragraph .)
Paragraph-name: A paragraph-name is a word that names a paragraph in the Procedure Division. Paragraph-names are equivalent if, and only if, they are composed of the same sequence of the same number of characters.
Section-name: A section-name is a word that names a section in the Procedure Division. Section-names are equivalent if, and only if, they are composed of the same sequence of the same number of characters.
Other user-defined words: See the Glossary for definitions of all other types of user-defined words.

System-names: A system-name is a COBOL word that is used to communicate with the operating environment.

System-names must contain at least one alphabetic character

MFor one occurrence of the hyphen character
.

There are three types of system-names:

Within a given implementation these three types of system-names form disjoint sets; a given system-name can belong to one and only one of them.

The system-names listed above are individually defined in the Glossary.

ANS85 Intrinsic-function-names: An intrinsic-function-name is a word that is one of a specified list of words which can be used in COBOL source elements. The same word, with the exception of LENGTH, RANDOM and SUM, in a different context, can appear in a source element as a user-defined word or a system-name. (See the topic Definitions of Functions.)

Reserved words: A reserved word is a COBOL word that is one of a specified list of words which can be used in COBOL compilation groups, but which must not appear in the compilation groups as user-defined words or system-names. Reserved words can be used only as specified in the general formats. (See the topic Reserved Words.)

The types of reserved words are:

Key words: A key word is a word whose presence is required when the format in which it appears is used in a compilation group. Within each format, such words are upper-case and underlined.

Key words are of three types:

  1. Verbs such as ADD, READ, and ENTER
  2. Required words, which appear in statement and entry formats
  3. Words which have a specific functional meaning, such as NEGATIVE, SECTION, and so on.
Optional words: Within each format, upper-case words that are not underlined are called optional words and can appear at the user's discretion. The presence or absence of an optional word does not alter the semantics of the COBOL source element in which it appears.
Special registers: Certain words are used to name and reference special registers: special registers are certain storage areas created by your COBOL system, whose primary use is to store information produced in conjunction with the use of specific COBOL features. They are specified in the section Special Registers.
Figurative constants: Certain reserved words are used to name and reference specific constant values. These reserved words are specified in the section Figurative Constant Values.
Special character words: The arithmetic operators and relation characters are reserved words.
ISO2002MF Predefined object identifiers: Certain reserved words are used as predefined object identifiers. The predefined object identifiers are:
  • SELF
  • SUPER
  • MFSELFCLASS

ISO2002 Context-sensitive Words: A context-sensitive word is a COBOL word that is reserved only in the general formats in which it is specified. The same word may also be used as an intrinsic-function-name, a user-defined word or a system-name. Context-sensitive words and the contexts in which they are reserved are specified in the section Context-sensitive Words Table in the appendix Reserved Words.

ANS85 Scope of Names

When source elements are directly or indirectly contained within other source elements, each source element can use identical user-defined words to name items independent of the use of these user-defined words by other elements. (See the discussion of user-defined words in the section COBOL Words.) When identically named items exist, a source elements's reference to such a name, even when it is a different type of user-defined word, is to the item which that source element describes rather than to the item possessing the same name, described in another source element.

The following types of user-defined words can be referenced only by statements and entries in the source element in which the user-defined word is declared:

The following types of user-defined words can be referenced throughout a compilation group:

The following types of names, when declared in a Configuration Section, can be referenced only by statements and entries either in the source element that contains that Configuration Section or in any source element contained within that source element:

Specific conventions, for declarations and references, apply to the following types of user-defined words when the conditions listed above do not apply:

ANS85 Conventions for Program-names

The program-name of a program is declared in the Program-ID paragraph of the program's Identification Division. A program-name can be referenced only by the CALL statement,

MFthe CHAIN statement,

the CANCEL statement,

MFthe SET statement

and the END PROGRAM header. If two programs in a run unit are identically named, at least one of those two programs must be directly or indirectly contained within a separate program which does not contain the other of those two programs.

The following rules regulate the scope of a program-name:

  1. If the program-name is that of a program which does not possess the common attribute and which is directly contained within another program, that program-name can be referenced only by statements included in that containing program

    ISO2002MFOS390or, if the program possesses the recursive attribute, in the program itself
    .

  2. If the program-name is that of a program which does possess the common attribute and which is directly contained within another program, that program-name can be referenced only by statements included in that containing program and any programs directly or indirectly contained within that containing program

    ISO2002MFOS390, except that the program possessing the common attribute and any programs contained within it may reference the program-name only if the program possesses the recursive attribute.

  3. If the program-name is that of a program that is not contained in another program, it can be referenced by statements included in any source element in the run unit.

For example, suppose that ProgA contains ProgB and ProgC, ProgC contains ProgD and ProgF, and ProgD contains ProgE (see Figure 1

Example of Scope of Program-Names

Figure 1: Example of Scope of Program-Names

If ProgD does not possess the COMMON attribute, then ProgD can only be referenced by the program that directly contains ProgD, that is, ProgC.

If ProgD does possess the COMMON attribute, then ProgD can be referenced by ProgC since it contains ProgD and by any programs contained in ProgC except for programs contained in ProgD, that is, by ProgF but not by ProgE. Also it cannot be referenced by ProgA or ProgB.

ANS85 Conventions for Condition-names, Data-names, File-names, Record-names, Report-names and MFTypedef-names

When condition-names, data-names, file-names, record-names and report-names

MFand typedef-names

are declared in a source element, they can be referenced only by that source element unless one or more of the names is global and the source element contains other source elements.

The requirements governing the uniqueness of the names declared by a single source element to be condition-names, data-names, file-names, record-names and report-names

MFand typedef-names

are explained in the discussion of user-defined words in the section COBOL Words.

A source element cannot reference any condition-name, data-name, file-name, record-name or report-name

MFor typedef-name

declared in any source element it contains.

A global name can be referenced in the source element in which it is declared or in any source elements which are directly or indirectly contained within that source element.

When a source element, source element B, is directly contained within another source element, source element A, both source elements can define a condition-name, a data-name, a file-name, a record-name or a report-name

MFor a typedef-name

using the same user-defined word. When such a duplicate-name is referenced in source element B, the following rules are used to determine the referenced item:

  1. The set of names to be used for determination of a referenced item consists of all names that are defined in source element B and all global names that are defined in source element A and in any source elements which directly or indirectly contain source element A. Using this set of names, the normal rules for qualification and any other rules for uniqueness of reference are applied until one or more item is identified.
  2. If only one item is identified, it is the referenced item.
  3. If more than one item is identified, no more than one of them can have a name local to source element B. If zero or one of the items has a name local to source element B, the following rules apply:
    1. If the name is declared in source element B, the item in source element B is the referenced item.
    2. Otherwise, if source element A is contained within another source, the referenced item is:
      1. The item in source element A if the name is declared in source element A.
      2. The item in the containing source element if the name is not declared in source element A and is declared in the source element containing source element A. This rule is applied to further containing source elements until a single valid name has been found.

ANS85 Conventions for Index-names

If a data item possessing the global attribute includes a table described with an index-name, that index-name also possesses the global attribute. Therefore, the scope of an index-name is identical to that of the data-name which names the table whose index is named by that index-name and the scope of name rules for data-names apply.

Index-names cannot be qualified.

OSVSIndex-names can be qualified.

ISO2002MF Conventions for Class-names (for Object Orientation) and Interface-names

The class-name of a class referenced within a source element must be either the name of the containing class definition or declared in the Repository paragraph

MFor the Class-Control paragraph

of that or a containing source element.

Within a compilation group, there must be at most one class definition for a given class-name.

The interface-name of an interface referenced within a source element must be either the name of the containing interface definition or declared in the Repository paragraph of that or a containing source element.

Within a compilation group, there must be at most one interface definition for a given interface-name.

A class-name or interface-name declared in the Repository paragraph of a source element may be used in that source element and any nested source element.

MFA class-name or interface-name declared in the Class-Control paragraph of a source element may be used in that source element and any nested source element.

ISO2002MF Conventions for Method-names

A method-name of a method is declared in the Method-ID paragraph. A method-name must be referenced only by the INVOKE statement, an inline method invocation and the end method header.

The methods declared in a class definition must have unique method-names within that class definition. The methods declared in a child class may have the same name as a method in the parent class, subject to the conditions for the Method-ID paragraph.

The methods declared in an interface definition must have unique method-names within that interface definition. The methods declared in an inheriting interface can have the same name as a method in the inherited interface, subject to the conditions stated for the Method-ID paragraph.

ISO2002MF Conventions for Function-prototype-names

Function-prototype-names referenced within a source element must be either the name of the containing function definition or declared in the Repository paragraph of that or a containing source element.

If a function prototype is specified in a Repository paragraph and the function prototype declaring the same function-prototype-name is also specified within the same compilation group, the function prototype specification is used and the information in the external repository for this prototype is ignored.

ISO2002MF Conventions for Program-prototype-names

Program-prototype-names referenced within a source element must be either the program-name of a containing program definition or a program-prototype-name declared in the Repository paragraph

If a program prototype is specified in a Repository paragraph and the program prototype declaring the same program-prototype-name is also specified within the same compilation group, the program prototype specification is used and the information in the external repository for this prototype is ignored.

Literals

A literal is any of:

Every literal belongs to one of three types; nonnumeric, numeric and national.

Nonnumeric Literals

A nonnumeric literal is a character-string delimited at both ends by quotation marks

ISO2002OSVSVSC2MFor apostrophes

and consisting of any allowable character in the computer's character set. Nonnumeric literals may be of 1 to 160 characters in length. Whether quotation marks

ISO2002OSVSVSC2MFor apostrophes

are used as delimiters, the presence of that delimiter within a nonnumeric literal can be represented by two contiguous occurrences. The presence of the character that is not serving as the delimiter is represented by a single occurrence. The value of a nonnumeric literal in the run-time element is the string of characters itself, except:

All other punctuation characters are part of the value of the nonnumeric literal rather than separators; all nonnumeric literals are category alphanumeric. (See the topic The PICTURE Clause.)

VSC2MFIn addition, hexadecimal binary values can be attributed to nonnumeric literals by expressing literals as: X"nn", where each n is a hexadecimal digit in the set 0 through 9, A through F; nn can be repeated up to 160 times, but the number of hexadecimal digits must be even.

MFThe number of hexadecimal digits may be odd.

Numeric Literals

Numeric literals can be either fixed-point or floating-point numbers.

Fixed-Point Numeric Literals

A numeric literal is a character-string whose characters are selected from the digits 0 through 9, the plus sign, the minus sign, and the decimal point. This implementation allows for numeric literals of 1 to 18 digits in length. The rules for the formation of numeric literals are as follows:

If a literal conforms to the rules for the formation of numeric literals, but is enclosed in quotation marks, it is a nonnumeric literal and is treated as such by your COBOL system.

The size of a numeric literal in standard data format characters is equal to the number of digits specified by the user.

MFIn addition, hexadecimal binary values can be attributed to numeric literals by expressing literals as: H"nn", where each n is a hexadecimal digit in the set 0-9 A-F; nn can be repeated up to 8 times, but the number of hexadecimal digits must be even.

Floating-Point Numeric Literals

OSVSVSC2MF

A floating-point literal is written in the form:

If you omit a sign, the system assumes a positive number.

The significand can contain between 1 and 16 digits. A decimal point must be included in the significand.

The exponent is represented by an E followed by an optional sign and one or two digits.

The magnitude of a floating-point literal value must fall between 0.54E-78 and 0.72E+76. For values outside this range, an error message is produced and the value is replaced by 0 or 0.72E+76 respectively. You must not use a floating-point literal when an integer literal is required.

ISO2002MF National Literals

A national literal is a string of national characters represented in the storage of the computer as characters of a uniform size. See your COBOL system documentation on national data (Unicode) for further information.

General Formats
Format 1

Format 2

Syntax Rules
    All Formats
  1. The length of a national literal, excluding the separators that delimit the literal, nust be greater than zero and less than or equal to 160 national character positions.
  2. Character 1 can be any character in the alphanumeric coded character set such that a correspondence exists between that alphanumeric character and a national character.
  3. Format 1
  4. Two contiguous quotation symbol characters matching the quotation symbol used in the opening delimiter represent a single occurrence of that quotation symbol character in the content of the literal. The two contiguous quotation symbol characters must be in the same coded character set representation as the opening quotation symbol.
  5. Format 2
  6. Each hex-character-sequence-1 must consist of four hexadecimal digits (two bytes) coded with the high-order byte first
General Rules
    All Formats
  1. The separators that delimit the national literal are not included in the value of the national literal.
  2. National literals are of the class and category national.
  3. Format 1
  4. The value of the literal at compile time is the string of occurrences of character-1 represented in the computer’s compile-time coded character set.

    The value of the literal at runtime is the string of national characters that results from converting the compile-time value of the literal to its runtime equivalent.

  5. Format 2
  6. The value of the literal at runtime is a string of national characters, each of which has the bit configuration specified by one occurrence of hex-character-sequence-1.
Figurative Constant Values

Figurative constant values are generated by your COBOL system and referenced through the use of the reserved words given below. These words must not be bounded by quotation marks when used as figurative constants. The singular and plural forms of figurative constants are equivalent and can be used interchangeably.

The figurative constant values and the reserved words used to reference them are shown in Table 1.

Constant Representation
ZERO ZEROS ZEROES Represents the value "0", or one or more of the character "0" depending on the context.
SPACE SPACES Represents one or more of the character space from the computer's character set.
HIGH-VALUE HIGH-VALUES Represents one or more of the character that has the highest ordinal position in the program collating sequence. (x"FF" for the extended ASCII character set.)
LOW-VALUE LOW-VALUES Represents one or more of the character that has the lowest ordinal position in the program collating sequence. (x"00" for the ASCII character set.)
QUOTE QUOTES Represents one or more of the character """. The word QUOTE or QUOTES cannot be used in place of a quotation mark in a source program to bound a nonnumeric literal. Thus QUOTE ABD QUOTE is incorrect as a way of stating "ABD".
ALL literal Represents one or more characters of the string of characters comprising the literal. The literal must be either a nonnumeric literal or

ISO2002MFa national literal or

a figurative constant other than ALL literal.

ISO2002MFXOPENThis nonnumeric literal and this national literal may be concatenation expressions.

When a figurative constant is used, the word ALL is redundant and is used for readability only.
VSC2MFNULL NULLS

Represents one or more unset pointer

MFCOB370or procedure-pointer

values. A data item with USAGE POINTER

MFCOB370or PROCEDURE-POINTER

and with a value of NULL is guaranteed not to represent the address of any data item

MFCOB370or procedure
.

The NULL value varies between environments and is generally consistent with the equivalent value used in non-COBOL languages for each environment.

Table 1: Figurative Constants and Their Reserved Words

When a figurative constant represents a string of one or more characters, the length of the string is determined by your COBOL system from context by applying the following rules in order:

  1. ISO2002MFXOPENWhen a figurative constant is specified in a concatenation expression, the length of the string is one character.
  2. When a figurative constant is either specified in a VALUE clause, or associated with another data item, (for example, when the figurative constant is moved to or compared with another data item), the string of characters specified is repeated character by character on the right until the size of the resultant string is greater than or equal to the number of character positions in the associated data item. This resultant string is then truncated from the right until the number of character positions remaining is equal either to 1 or to the number of character positions in the associated data item, whichever is greater. This is done prior to and independent of the application of any JUSTIFIED clause that can be associated with the data item.
  3. When a figurative constant is other than ALL literal, the length of the string is one character.
  4. The length of the string is the length of the literal.

    MFUse of figurative constants in Format 3 DISPLAY statements has specific effects, described in the General Rules for that statement.

A figurative constant can be used wherever a literal appears in a format, except that whenever the literal is restricted to having only numeric characters in it, the only figurative constant permitted is ZERO (ZEROS, ZEROES).

When the figurative constants HIGH-VALUE(S) or LOW-VALUE(S) are used , the actual character associated with each figurative constant depends upon the program collating sequence specified. (See the topics The Object-Computer Paragraph and the The Special-Names Paragraph.)

Each reserved word that is used to reference a figurative constant value is a distinct character-string, with the exception of the construction "ALL literal" which is composed of two distinct character-strings.

OSVSVSC2MF The value associated with the QUOTE/QUOTES figurative constant is sensitive to the APOST and QUOTE directives.

ANS85The figurative constant ALL literal, when associated with a numeric or numeric edited item, and when its length is greater than one, is classed as an obsolete element in the ANSI'85 standard and is scheduled to be deleted from the next full revision of the ANSI Standard.

MFAll dialects within this COBOL implementation fully support this obsolete ALL literal syntax. The FLAGSTD directive can be used to detect all occurrences of this syntax.

XOPENAlthough this obsolete ALL literal syntax is a part of the standard COBOL definition, this syntax is explicitly excluded from the X/Open COBOL language definitions and should not be used in a conforming X/Open COBOL source program.

MF Constant-names

Constant-names are user-defined words described in the Data Division in level-78 data description entries. A constant-name may be used wherever a literal appears in a format. Its effect is as if the literal in the VALUE clause of its data description had been written instead. A constant-name with an integer value can also be used wherever a format requires an integer; for example, as a level number or segment number, or in a PICTURE character-string.

A constant-name can only be used after it has been described; that is, it cannot be the object of a forward reference.

ISO2002MFXOPEN Concatenation Expressions

A concatenation expression consists of two operands separated by the concatenation operator.

General Format

Syntax Rules
  1. Both operands must be of the same class, except that a figurative constant may be specified as one or both operands. Neither operand must be numeric. Neither literal-1 nor literal-2 must be a figurative constant that begins with the word ALL.
  2. ISO2002The length of the value resulting from concatenation must be less than or equal to 160 character positions.
General Rules
  1. The class of the concatenation expression resulting from the concatenation operation must be:
    1. When one of the operands is a figurative constant, the class of the literal or concatenation expression that constitutes the other operand, or
    2. When both of the operands are figurative constants, the class alphanumeric, or
    3. The same class as the operands.
  2. The value of a concatenation expression must be the concatenation of values of the literals, figurative constants and concatenation expressions of which it is composed.
  3. A concatenation expression must be equivalent to a literal of the same class and value, and may be used anywhere a literal of that class may be used.

Special Registers

Special registers are data items or transient values generated by your COBOL system and referenced through the use of their associated names or expressions (see Table 2). These special registers are subject to special rules of reference and have implicit data descriptions (PICTUREs), as individually described.

Special Register Name or Expression Implicit Data Description Picture Usage
VSC2MFADDRESS OF data-name-1 USAGE IS POINTER The expression generates a pointer value representing the address of data-name-1. The expression is explicitly shown in the general format for statements in which it can be used. Data-name-1 must be a data item declared in the Linkage Section with a level number or 01 or 77

MFor must be declared anywhere in the Data Division and with any level number
.

OSVSCURRENT-DATE 1 X(8) The CURRENT-DATE special register contains the value of the current date (as supplied by the COBOL execution environment), in the form: MM/DD/YY where MM is the month number, DD is the day of the month, and YY is the year number (from 1900). CURRENT-DATE is valid only as the sending area of a MOVE statement.
DEBUG-ITEM A group item of variable size The DEBUG-ITEM special register provides information about the conditions that caused the execution of a Debugging Section. For further information see the section Debug Module.
VSC2MFLENGTH OF data-name-2 2 9(9) The expression generates a value representing the current number of bytes of storage used by data-name-2. The expression can be used wherever a numeric data item can be used except as a subscript or a reference modifier.

MFIt can also be used to set the value of a level 78 item.

LINAGE-COUNTER   The LINAGE-COUNTER special register is generated by the presence of a LINAGE clause in a file description entry for a record sequential file. The implicit description is that of an unsigned integer whose size is equal to the size of integer-1 or the data item referenced by data-name-1 in the LINAGE clause.
OSVSVSC2MFRETURN-CODE 3 S9(4) COMP

XOPENS9(9) COMP

The RETURN-CODE special register can:
  • be set by a program, prior to the execution of a STOP RUN, EXIT PROGRAM or GOBACK statement, to pass a value to the calling run-time element (or the execution environment)
  • be read, subsequent to a CALL to another COBOL program, to obtain the value of the RETURN-CODE special register set by that CALLed program.

A program's RETURN-CODE special register is set to zero when that program is first entered. RETURN-CODE is valid as a data-name in a Procedure Division statement wherever an elementary data item can be referenced.

VSC2SHIFT-IN X(1) Used to switch the character representation from double-byte characters (DBCS) back to single-byte characters (SBCS) in environments where this is applicable.
VSC2SHIFT-OUT X(1) Used to switch the character representation from single-byte characters (SBCS) to double-byte characters (DBCS) in environments where this is applicable.
VSC2SORT-CONTROL X(8)

Used only during sort and merge operations. You can reference it in the Procedure Division but it will contain spaces.
OSVSVSC2 SORT-CORE-SIZE S9(8) COMP Used only during sort and merge operations. You can reference it in the Procedure Division but it will contain zeros.
OSVSVSC2 SORT-FILE-SIZE S9(8) COMP Used only during sort and merge operations. You can reference it in the Procedure Division but it will contain zeros.
OSVSVSC2 SORT-MESSAGE X(8) Used only during sort and merge operations. You can reference it in the Procedure Division but it will contain spaces.
OSVSVSC2 SORT-MODE-SIZE S9(5) COMP Used only during sort and merge operations. You can reference it in the Procedure Division but it will contain zeros.
OSVSVSC2MFSORT-RETURN S9(4) COMP SORT-RETURN can be used to cause an abnormal termination of a SORT procedure. If a value of 16 is moved into this field, the SORT operation is terminated after the next RELEASE or RETURN.
OSVSVSC2TALLY 9(5) COMP The TALLY special register contains information produced by the EXAMINE...TALLYING statement. It is valid as a data-name in a Procedure Division statement wherever an elementary data item can be referenced.
OSVSTIME-OF-DAY 9(6) DISPLAY The TIME-OF-DAY special register contains the value of the current time of day (24-hour clock) (as supplied by the COBOL execution environment), in the form: hhmmss where hh =hour, mm=minutes, and ss=seconds. TIME-OF-DAY is valid only as the sending area of a MOVE statement.
OSVSWHEN-COMPILED X(20) The WHEN-COMPILED special register contains the time and date that the COBOL compilation group was submitted to your COBOL system, in the form: hh.mm.ssMMM DD, YYYY where hh=hours (24-hour clock), mm=minutes, ss=seconds, MMM=month name (first 3 characters), DD=day of month, and YYYY=year.

WHEN-COMPILED is valid only as the sending area of a MOVE statement.

VSC2WHEN-COMPILED X(20) The WHEN-COMPILED special register contains the time and date that the COBOL compilation group was submitted to your COBOL system, in the form: MM/DD/YYhh.mm.ss where DD, hh, mm and ss are as above. YY=year in century and MM=month in year.

WHEN-COMPILED is valid only as the sending area of a MOVE statement.

ENTMFXML-CODE 4 S9(9) COMP The XML-CODE special register is used to communicate status between the XML parser and the processing procedure identified in the XML PARSE statement. The XML parser sets XML-CODE for each event and at parser termination. You can reset XML-CODE in the processing procedure to -1 after a normal event, to indicate that the parser is to terminate with a user-initiated exception, which is not an EXCEPTION XML event, indicated by the returned XML-CODE value of -1.
ENTMFXML-EVENT 5 X(30) The XML-EVENT special register is used to communicate event information from the XML parser to the processing procedure that was identified in the XML PARSE statement. Before passing control to the processing procedure, the XML parser sets the XML-EVENT special register to the name of the XML event. XML-EVENT cannot be used as a receiving data item.
ENTMFXML-NTEXT5   The XML-NTEXT special register is defined during XML parsing to contain document fragments that are USAGE NATIONAL. XML-NTEXT is an elementary national data item of the length of the contained XML document fragment. The length of XML-NTEXT varies dynamically at run time.

When the operand of the XML PARSE statement is a national data item, and for the ATTRIBUTE-NATIONAL-CHARACTER and CONTENT-NATIONAL-CHARACTER events, the XML parser sets XML-NTEXT to the document fragment associated with an event before transferring control to the processing procedure.

When XML-NTEXT is set, the XML-TEXT special register has a length of zero. At any given time, only one of the two special registers XML-NTEXT and XML-TEXT has a non-zero length.

Use the LENGTH function to determine the number of national characters that XML-NTEXT contains.

XML-NTEXT cannot be used as a receiving item.

ENTMFXML-TEXT5   The XML-TEXT special register is defined during XML parsing to contain document fragments that are of class alphanumeric. XML-TEXT is an elementary alphanumeric data item of the length of the contained XML document fragment. The length of XML-TEXT varies dynamically at run time.

When the operand of the XML PARSE statement is an alphanumeric data item, except for the ATTRIBUTE-NATIONAL-CHARACTER event and the CONTENT-NATIONAL-CHARACTER event, the parser sets XML-TEXT to the document fragment associated with an event before transferring control to the processing procedure.

When XML-TEXT is set, the XML-NTEXT special register has a length of zero. At any given time, only one of the two special registers XML-NTEXT and XML-TEXT has a non-zero length.

Use the LENGTH function or the LENGTH OF special register for XML-TEXT to determine the number of bytes that XML-TEXT contains.

XML-TEXT cannot be used as a receiving item.

Table 2: Special Registers

Footnotes:

1.

The format of the contents of the CURRENT-DATE special register is sensitive to the CURRENT-DATE directive.

2.

The LENGTH OF special register may be followed by an alphanumeric literal when using the Micro Focus dialect.

3.

The size of the RETURN-CODE special register is sensitive to the XOPEN and RTNCODE-SIZE directives.

4.

For a list of supported exception codes, see the topic XML-CODE Exception Codes.

5.

The contents of XML-TEXT and XML-NTEXT vary depending on the contents of XML-EVENT. See Table 3 for additional information.

ENTMF

Contents of XML-EVENT Contents of XML-TEXT or XML-NTEXT
ATTRIBUTE-CHARACTER The single character corresponding with the predefined entity reference in the attribute value.
ATTRIBUTE-CHARACTERS The value within quotes or apostrophes. This can be a sub-string of the attribute value if the value includes an entity reference.
ATTRIBUTE-NAME The attribute name, the string to the left of =.
ATTRIBUTE-NATIONAL-CHARACTER Regardless of the type of the XML document specified by identifier-1 in the XML PARSE statement, XML-TEXT is empty and XML-NTEXT contains the single national character corresponding with the (numeric) character reference.
COMMENT The text of the comment between the opening character sequence "<!--" and the closing character sequence "-->".
CONTENT-CHARACTER The single character corresponding to the predefined entity reference in the element content.
CONTENT-CHARACTERS The element content between start and end tags. This can be a substring of the element content if the content contains an entity reference to another element.
CONTENT-NATIONAL-CHARACTER Regardless of the type of the XML dcument specified by identifier-1 in the XML PARSE statement, XML-TEXT is empty and XML-NTEXT contains the single national character corresponding with the (numeric) character reference.6
DOCUMENT-TYPE-DECLARATION The entire document type declaration including the opening and closing character sequences, "<!DOCTYPE" and ">".
ENCODING-DECLARATION The value, between quotes or apostrophes, of the encoding declaration in the XML declaration.
END-OF-CDATA-SECTION Always contains the string "]]>".
END-OF-DOCUMENT Null, zero-length.
END-OF-ELEMENT The name of the end element tag or empty element tag.
EXCEPTION The part of the document successfully scanned, up to and including the point at which the exception was detected. 7 Special register XML-CODE contains the unique error code identifying the exception.8
PROCESSING-INSTRUCTION-DATA The rest of the processing instruction, not including the chlosing sequence, "?>", but including trailing, and not leading, white space characters.
PROCESSING-INSTRUCTION-TARGET The processing instruction target name, which occurs immediately after the processing instruction opening sequence, "<?".
STANDALONE-DECLARATION The value, between quotes or apostrophes, of the standalone declaration in the XML declaration.
START-OF-CDATA-SECTION Always contains the string "<![CDATA[".
START-OF-DOCUMENT The entire document.
START-OF-ELEMENT The name of the start element tag or empty element tag, also know as the element type.
UNKNOWN-REFERENCE-IN-CONTENT The entity reference name, not including the "&" and ";" delimiters.
UNKNOWN-REFERENCE-IN-ATTRIBUTE The entity reference name, not including the "&" and ";" delimeters.
VERSION-INFORMATION The value, between quotes or apostrophes, of the version declaration in the XML declaration. This is always "1.0".
ENTMFTable 3: Contents of XML-EVENT and XML-NTEXT or XML-TEXT Special Registers

Footnotes:

6.

National characters with scalar values larger than 65,535 (NX"FFFF") are represented using two encoding units (a surrogate pair). You should ensure that operations on the content of XML-NTEXT do not split the pair of encoding units that together form a graphic character, thereby forming invalid data.

7.

Exceptions for encoding conflicts are signaled before parsing begins. For these exceptions, XML-TEXT is either zero in length or contains just the encoding delcaration value from the document.

8.

See the IBM Enterprise COBOL Programming Guide for information on XML exception codes. Any exception not documented in the IBM Enterprise COBOL Programming Guide is returned with a value of 201.

ISO2002MF Predefined Object Identifiers

The predefined object identifiers are:

Predefined Object Identifier Usage
SELF References the object on which the current method is executing. May be used in the Procedure Division of a method. References the object that was used to invoke the method in which SELF appears. If SELF is specified for a method invocation, the search for the method includes all methods declared for the object.
MFSELFCLASS References the object that is the class object of the current object (SELF). If SELF is itself a class object, SELFCLASS is the system class BEHAVIOR. The class object BEHAVIOR terminates this self-reference. (i.e., If SELF is the BEHAVIOR of class, so is SELFCLASS.)
SUPER References the object on which the current method is executing. May be used in the Procedure Division of a method. May be the object used to invoke a method with the INVOKE statement or inline invocation. References the object that was used to invoke the method in which SELF appears. If SUPER is specified for a method invocation, the search for the method ignores all the methods defined in the same class as the executing method.
NULL References the null object reference value, which is a unique value that is guaranteed to never reference an object. NULL is implicitly described as class object and category object reference, and is not a universal object reference. NULL must not be specified as a receiving operand.

PICTURE Character-Strings

A PICTURE character-string consists of certain combinations of characters in the COBOL character set, used as symbols. See the topic The PICTURE Clause for the PICTURE character-string and for the rules that govern its use.

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

Comment-entries

A comment-entry is an entry in the Identification Division that can be any combination of characters from the computer's character set. A comment-entry is for documentary purposes only, may extend over more than one line and is terminated upon encountering a division, section or paragraph name that is a reserved word

OSVSor encountering any character

in area A of a line. The continuation of a comment-entry by the use of the hyphen in the indicator area is not permitted.

Formats and Rules

General Format

A general format is the specific arrangement of the elements of a clause or a statement. Throughout this document a format is shown adjacent to information defining the clause or statement. When more than one specific arrangement is permitted, the general format is separated into numbered formats. Clauses must be written in the sequence given in the general formats. (Clauses that are optional must appear in the sequence shown if they are used.) In certain cases, stated explicitly in the rules associated with a given format, the clauses can appear in sequences other than that shown. Applications, requirements or restrictions are shown as rules.

Syntax Rules

Syntax rules are those rules that define or clarify the order in which words or elements are arranged to form larger elements, such as phrases, clauses, or statements. Syntax rules also impose restrictions on individual words or elements.

These rules are used to define or clarify how the statement must be written; that is, the order of the elements of the statement and restrictions on what each element may represent.

General Rules

General rules are those rules that define or clarify the meaning or relationship of meanings of an element or set of elements. They are used to define or clarify the semantics of the statement and the effect that it has on either execution or on the way intermediate code is produced.

Elements

Elements which make up a clause or a statement consist of upper-case words, lower-case words, level-numbers, brackets, braces, connectives and special characters.

Concept of Computer-independent Data Description

To make data as computer-independent as possible, the characteristics or properties of the data are described in relation to a standard data format rather than to an equipment-oriented format. This standard data format is oriented to general data processing applications and uses the decimal system to represent numbers (regardless of the radix used by the computer) and the remaining characters in the COBOL character set to describe nonnumeric data items.

Concept of Levels

A level concept or hierarchy is inherent in the structure of a logical data record. This concept arises from the need to specify subdivisions of a record for the purpose of data reference. Once a subdivision has been specified, it can be further subdivided to permit more detailed data referral.

The most basic subdivisions of a record, that is, those not further subdivided, are called elementary items; consequently, a record is said to consist of a sequence of elementary items, or the record itself can be an elementary item.

In order to refer to a set of elementary items, the elementary items are combined into groups. Each group consists of a named sequence of one or more elementary items. Groups, in turn, can be combined into groups of two or more groups, and so on. Thus, an elementary item can belong to more than one group.

Level-Numbers

A system of level-numbers shows the organization of elementary items and group items. Since records are the most inclusive data items, level-numbers for records start at 01. Less inclusive data items are assigned higher (not necessarily successive) level-numbers not greater in value than 49. A maximum of 49 levels in a record is allowed. There are special level-numbers, 66, 77

MF, 78

and 88 which are exceptions to this rule (see below). Separate entries are written for each level-number used.

A group includes all group and elementary items following it until a level-number less than or equal to the level-number of that group is encountered. All items which are immediately subordinate to a given group item should be described using identical level-numbers greater than the level-number used to describe that group item

OSVSVSC2; this rule is not insisted upon
.

Example

Correct OSVSVSC2MFIncorrect but Permitted
01 A.
  05 C-1.
    10 D PICTURE X.
    10 E PICTURE X.
  05 C-2.
OSVSVSC2MF01  A.
  05 C-1.
    10 D PICTURE X.
    10 E PICTURE X.
 04 C-2.

Four types of entries exist for which there is no true concept of level. These are:

  1. Entries that specify elementary items or groups introduced by a RENAMES clause.
  2. Entries that specify noncontiguous working storage and linkage data items.
  3. Entries that specify condition-names.
  4. MF Entries that specify constant-names.

Entries describing items by means of RENAMES clauses for the purpose of regrouping data items have been assigned the special level-number 66.

Entries that specify noncontiguous data items, which are not subdivisions of other items, and are not themselves subdivided, have been assigned the special level-number 77.

Entries that specify condition-names, to be associated with particular values of a conditional variable, have been assigned the special level-number 88.

MF Entries that specify constant-names, to be associated with the value of a particular literal, have been assigned the special level-number 78.

Example of Level-numbers Representing a Data Hierarchy

Figure 2: Example of Level-numbers Representing a Data Hierarchy

Note that indentation of COBOL source code is a readability convention only and is not part of the language.

Elementary items are by definition those items without any subordinate entries (entries without numerically greater level-numbers) following, and must have a storage definition associated with them (see the topics The PICTURE Clause and the The USAGE Clause).

Note that only elementary items (marked with an asterisk, "*", above) and FILLER items (marked with a "#" sign above) have storage explicitly reserved for them (in accordance with the associated PICTURE clause); non-elementary items have implicit storage associated with them of size determined by their subordinate items plus any FILLER bytes needed for synchronization (see the topic The SYNCHRONIZED Clause).

Level-numbers need not be consecutively ascending or descending as shown above for clarity; thus, the next subordinate level after 01 could be 05, and the next level 10, and so on.

The above data descriptions would produce storage allocation in the following manner:

Data Record Storage Allocation

Figure 3: Data Record Storage Allocation

where:

R-E-I is Record-Entry-Item
M-G-I is Major-Group-Item
R-G-I is Regular-Group-Item
S-G is Sub-Group
EI is Elementary-Item
NEI is Noncontiguous Elementary-Item

Class and Category of Data

Every elementary data item, every literal, and every function has a class and a category. The class and category of a data item are defined by its picture character string, by the BLANK WHEN ZERO clause, or by its usage; the class and category of a literal are defined in the section Literals

ANS85and the class and category of an intrinsic function are specified by the definition of that intrinsic function (see the topic Intrinsic Functions)
.

The category of a group item is alphanumeric.

The following table depicts the relationship of categories to classes of data for elementary items.

Class Category
Alphabetic
  • Alphabetic
Alphanumeric
  • Numeric edited
  • Alphanumeric edited
  • Alphanumeric
  • VSC2MF DBCS
Index
  • Index
National
  • National
Numeric
  • Numeric
  • OSVSVSC2MF Internal floating-point
  • OSVSVSC2MF External floating-point
Object
  • ISO2002MFObject-reference
Pointer
  • ISO2002VSC2MFPointer
  • MFCOB370 Procedure-pointer
Table 3: Category and class relationships for elementary items

Algebraic Signs

Algebraic signs fall into two categories:

  1. Operational signs, which are associated with signed numeric data items and signed numeric literals to indicate their algebraic properties.
  2. Editing signs, which appear on edited reports to identify the sign of the item.

The SIGN clause permits you to state explicitly the location of the operational sign. The clause is optional; if it is not used, operational signs are represented as described in the section Selection Of Character Representation And Radix.

Editing signs are inserted into a data item through the use of the sign control symbols of the PICTURE clause.

Standard Alignment Rules

The standard rules for positioning data within an elementary item depend on the category of the receiving item. These rules are:

  1. If the receiving data item is described as numeric:
    1. The data is aligned by decimal point and is moved to the receiving character positions with zero fill or truncation on either end as required
    2. When an assumed decimal point is not explicitly specified, the data item is treated as if it had an assumed decimal point immediately following its rightmost character and is aligned as in paragraph a. above.
  2. If the receiving data item is a numeric edited data item, the data moved to the edited item is aligned by decimal point with zero fill or truncation at either end as required within the receiving character positions of the data item, except where editing requirements cause replacement of the leading zeros.
  3. If the receiving data item is alphanumeric (other than a numeric edited data item), alphanumeric edited or alphabetic, the sending data is moved to the receiving character position and aligned at the leftmost character position in the data item with space fill or truncation to the right, as required.
  4. OSVSVSC2MFIf the receiving data item is external floating-point, the leftmost non-zero digit, if one exists, is aligned on the leftmost digit position: the exponent is adjusted accordingly.

If the JUSTIFIED clause is specified for the receiving item, these standard rules are modified as described in the section The JUSTIFIED Clause in the chapter Data Division - File and Data Description.

Item Alignment for Increased Object-code Efficiency

Some computer memories are organized so that natural addressing boundaries exist in the computer memory (for example, word boundaries, half-word boundaries, byte boundaries). The way in which data is stored need not respect these natural boundaries.

However, certain uses of data (for example, in arithmetic operations or in subscripting) can be facilitated if the data is stored so as to be aligned on these boundaries. Specifically, additional machine operations in the run-time element can be repeated for the accessing and storage of data if portions of two or more data items appear between adjacent natural boundaries, or if certain natural boundaries divide a single data item.

Data items which are aligned on these natural boundaries in such a way as to avoid additional machine operations are defined to be synchronized. A synchronized item is assumed to be introduced and carried in that form; conversion to synchronized form occurs only during the execution of a statement (other than READ or WRITE) which stores data in the item.

Synchronization can be accomplished in two ways:

  1. By use of the SYNCHRONIZED clause
  2. By organizing the data suitably on the appropriate natural boundaries without the use of the SYNCHRONIZED clause.

By use of the SYNCHRONIZED clause, the use of special types of alignment within a group can affect the results of statements in which the group is used as an operand. The effect of the implicit FILLER and the semantics of any statement referencing these groups is described later in this chapter.

Selection of Character Representation and Radix

The value of a numeric item (defined as numeric by its PICTURE, see the topic The PICTURE Clause) can be represented in the computer's storage in either binary or decimal form depending on the USAGE clause of the declaration (see the topic The USAGE Clause). These numeric formats are:

ANS85An alphanumeric function is always represented in the standard data format. Its size is determined by the definition of the function.

The representation of integer and numeric functions is as follows:

Integer and numeric functions can be used only in arithmetic expressions, and represent the value resulting from the evaluation of the function without the restriction on composite of operands and/or receiving data items.

When a computer provides more than one means of representing data, the standard data format must be used for data items

ANS85other than integer and numeric functions,

if not otherwise specified by the data description.

DISPLAY Format

The COBOL digit characters from 0 through 9 that represent the number value are held in radix 10, one digit character per byte of computer storage. This is the standard data format of the COBOL language. If the data item is signed and the sign is not specified as SEPARATE (see the topic The SIGN Clause and the rules for the NUMERIC SIGN clause in the topic The Special-Names Paragraph) the numeric sign is incorporated into either the leading or trailing digit, according to the LEADING or TRAILING phrase in the SIGN clause. Signed data is incorporated into the requisite digit as shown in Table 4 below. (Effectively, bit 6 (hexadecimal value "40" ) of the character is set from 0 to 1 if the number has a negative value.) If the data item is signed and the sign is specified as SEPARATE, then the sign is held as a separate single COBOL character, additional to the digits, either plus (+) or minus (-) as necessary. If the data item is signed and no SIGN clause applies, the numeric sign is incorporated into the trailing digit, unless the NUMERIC SIGN clause is specified in the Special-Names paragraph. If the SIGN clause is specified in a data description entry, the NUMERIC SIGN clause, if specified, is ignored for that entry.

In the following table, the numbers in brackets represent the hexadecimal encoding for the COBOL character. On some systems, the encoding can be varied by the CHARSET and SIGN Compiler directives.

Leading or trailing value digit before sign incorporation Sign Digit Character for:
Positively-signed values Negatively-signed values
Charset (ASCII) Charset (EBCDIC) Charset (ASCII) Charset (EBCDIC)
Sign (ASCII) Sign (EBCDIC) Sign (EBCDIC) Sign (ASCII) Sign (EBCDIC) Sign (EBCDIC)
0 0(30) {(7B) {(C0) p(70) }(7D) }(D0)
1 1(31) A(41) A(C1) q(71) J(4A) J(D1)
2 2(32) B(42) B(C2) r(72) K(4B) K(D2)
3 3(33) C(43) C(C3) s(73) L(4C) L(D3)
4 4(34) D(44) D(C4) t(74) M(4D) M(D4)
5 5(35) E(45) E(C5) u(75) N(4E) N(D5)
6 6(36) F(46) F(C6) v(76) O(4F) O(D6)
7 7(37) G(47) G(C7) w(77) P(50) P(D7)
8 8(38) H(48) H(C8) x(78) Q(51) Q(D8)
9 9(39) I(49) I(C9) y(79) R(52) R(D9)
Table 4: DISPLAY Non-SEPARATE Sign-Digit Characters

Storage character position requirements for DISPLAY data items are thus equal to the number of "9"s in the PICTURE clause plus one if the sign is specified as SEPARATE. The SYNCHRONIZED clause has no effect on DISPLAY format data declarations.

COMPUTATIONAL, ANS85BINARY,
or OSVSVSC2MFCOMPUTATIONAL-4
Format

This format holds numeric data items in computer storage in pure binary two's complement representation. In this format, number values are held in radix of 2 where each computer bit in the representation starting from the right (least-significant) end represents the presence or absence of an increasingly significant power of 2 in that value. Negative numbers are represented by complementing (inverting all the bit values of) their positive counterpart, and then adding one to the whole. Storage requirements depend on the number of "9"s in the PICTURE clause, and whether the numeric data item is signed or unsigned (see the topics The PICTURE Clause, The SIGN Clause and The USAGE Clause); also your COBOL system assigns storage for COMPUTATIONAL items in one of two modes; byte-storage and word-storage. Byte-storage is the default storage-assignment mode for this COBOL implementation.

Computer Memory Natural Boundaries

The fundamental natural boundaries of a modern computer's memory are usually based on an eight-bit character, known as a byte. Within this fundamental framework, machines fall into two broad categories; those with no other natural boundaries, called here byte-storage computers, and those with other natural boundaries based upon multiples of the fundamental boundary of the byte, called here word-storage computers.

In byte-storage mode, COBOL assigns numeric storage so that each numeric item occupies the minimum number of bytes (see the section Selection Of Character Representation And Radix); the SYNCHRONIZED clause has no meaning in the context and hence has no effect.

Within word-storage computers, natural boundaries can occur at 2-byte, 4-byte and/or 8-byte boundaries. The COBOL language can provide such data item storage-assignment and synchronization when the COMPUTATIONAL clause and possibly the SYNCHRONIZED clause are used. This word-storage assignment of COMPUTATIONAL format data is controlled by the Compiler directive IBMCOMP.

Number of Digits (9s) in PICTURE Representation Number of Characters (Bytes) of Storage Assigned
Signed Unsigned Byte-Storage Mode Word-Storage Mode
1-2 1-2 1 2
3-4 3-4 2 2
5-6 5-7 3 4
7-9 8-9 4 4
10-11 10-12 5 8
12-14 13-14 6 8
15-16 15-16 7 8
17-18 17-19 8 8
19-21 20-21 9 16
22-23 22-24 10 16
24-26 25-26 11 16
27-28 27-28 12 16
29-31 29-31 13 16
32-33 23-33 14 16
34-35 34-36 15 16
36-38 37-38 16 16
Table 5: COMP(UTATIONAL) Format Data Item Character-Position (Byte) Storage Assignment
Synchronization

If a data item description contains the SYNCHRONIZED clause, and word-storage mode is enabled, the position of that item within the computer storage is aligned so that the right-hand (least-significant) end is on a natural boundary of the computer's storage. Extra character positions (bytes) of computer storage are reserved adjacent to synchronized items to achieve this alignment; these bytes, known as padding bytes or implicit FILLER bytes, are normally inaccessible to the computer program except as part of a group item.

Each elementary data item that is described as SYNCHRONIZED is aligned to the natural storage boundary that corresponds to its data item storage assignment (according to Table 5 above). Thus, in word-storage mode, a numeric data item with a PICTURE description of S9(5) would be assigned 4 bytes of storage (being 1 padding byte and 3 data bytes). If SYNCHRONIZED was specified, it would be aligned to the next nearest 4-byte boundary (that is, with the total (4-byte) storage assignment aligned such that the number of bytes from the beginning of the record containing that item to the left-hand (most-significant) end of that item was a multiple of four). If the previous item does not end on a 4-byte boundary, implicit FILLER assignments are necessary to achieve this.

Other such implicit FILLER bytes can be generated by the use of SYNCHRONIZED items in non-elementary data descriptions containing an OCCURS clause (see the topic The OCCURS Clause). This is because further bytes may need to be reserved for each group item occurrence in order that the second or subsequent occurrences have the same alignment to the natural boundaries of the computer storage as did the first occurrence.

Implicit Synchronization

With word-storage mode enabled, all record-level data descriptions are automatically synchronized to a full 8-byte boundary.

MF Where automatic alignment is enabled, it is sensitive to the ALIGN directive.

Example of Implicit FILLER Assignments

The following COBOL data description produces the computer storage allocation shown in Figure 4. An explanation of the symbols used is given below the figure.

01 UNSYNCHRONIZED-RECORD.
    02 UNSYNCHRONIZED-DATA-1        PIC 9(3) DISPLAY.
    02 UNSYNCHRONIZED-DATA-2        PIC X(2).
01 COMPOUND-REPEATED-RECORD.
    02 ELEMENTARY-ITEM-1            PIC X(2).
    02 GROUP-ITEM OCCURS 3 TIMES.
 03 ELEMENTARY-ITEM-2        PIC X.
 03 ELEMENTARY-ITEM-3        PIC S9(2) COMP SYNC.
 03 ELEMENTARY-ITEM-4        PIC S9(4)V9(2) COMP SYNC.
 03 ELEMENTARY-ITEM-5        PIC X(5).

Sample Computer Storage Allocation

Figure 4: Sample Computer Storage Allocation

where:

@ indicates implicit FILLER bytes allocated due to automatic synchronization of a record (01-level) description.
# indicates implicit FILLER bytes allocated when following data item is explicitly synchronized.
$ indicates implicit FILLER bytes allocated when a non-elementary item is subject to an OCCURS clause.
9 indicates bytes allocated for a numeric DISPLAY character.
A indicates bytes allocated for an alphanumeric DISPLAY character.
C indicates bytes allocated for a COMPUTATIONAL data storage.
Truncation

In data items of USAGE COMP, data is held in binary format as described in the previous sections. The storage allocated for an item can have space for larger numbers than specified by the PICTURE clause. For example, an item described as PIC 99 COMP is normally assigned one byte, which can hold numbers up to 255.

To conform with the rules of ANSI COBOL, numbers behave as decimal numbers, regardless of their format. If, in an arithmetic statement, the result is bigger than the PICTURE clause of a receiving item allows, a size error occurs, and if the ON SIZE ERROR phrase is specified the result is not stored in the receiving item. In a non-arithmetic statement, if this situation occurs, the decimal value is truncated on the left, to the number of digits specified in the PICTURE clause.

OSVSVSC2MF However, data in USAGE COMP items can be forced to behave as binary data, that is, truncation occurs only if it is necessary in order for the data to fit the space allocated. The behavior of USAGE COMP items is controlled by the setting of the COBOL Compiler directive TRUNC. This directive selects whether the decimal value is truncated to the picture size, or the binary value is truncated to the space available. It distinguishes between results of arithmetic statements, and data being moved by non-arithmetic statements.

Regardless of the setting of any directive, an arithmetic statement gives the size error condition if the result has more decimal digits than specified in the PICTURE clause of a receiving item.

OSVSVSC2MFExample of Truncation

The TRUNC Compiler directive can change the results of some operations, as demonstrated in the following examples in which item A is described as PIC 99 COMP.

Operation Result
TRUNC NOTRUNC TRUNC"ANSI"
MOVE 163 TO A 63 163 63
MOVE 263 TO A 63 7 63
MOVE 13 TO A, ADD 150 TO A 63 163 undefined results
MOVE 13 TO A, ADD 250 TO A 63 undefined results undefined results

OSVSVSC2MFNotes:

  1. This directive has no effect on the truncation of low-order digits in non-integer data. This always conforms with the behavior specified in ANSI COBOL.
  2. If the IBMCOMP Compiler directive is set, extra upper bytes may be allocated to a COMP item. These are counted in the space allocated. When IBMCOMP is on, padding bytes may be generated before a COMP item with a SYNC clause; these are not part of the item, and are never affected by data stored in the item.
  3. When a value being stored into a signed item is limited to the number of digits by the PICTURE clause, it can never be big enough to overwrite the sign bit. When the NOTRUNC directive is set this is not true, and the value, if large enough, overwrites the sign bit.

OSVSVSC2MFCOMPUTATIONAL-1, COMPUTATIONAL-2,
ISO2002FLOAT-SHORT and FLOAT-LONG
Formats

These formats are used for internal floating-point data items. Such data items can be used in all syntax where a numeric data item can be used and where the syntax is a part of the ANSI'74, ANSI'85, ISO2000, OSVS, or VSC2 COBOL language definition. Such data items cannot be used where integer data items are required unless explicitly allowed by the rules for a specific COBOL verb. An internal floating-point data item cannot be used in other syntax unless a specific rule allows it.

The internal storage format can differ from operating system to operating system. In all storage formats, four pieces of information are encoded:

  1. The exponent - the power of 10 to which the specific numeric value is multiplied.
  2. The exponent sign - an indication of whether the specific numeric value (significand) is multiplied by a "whole" number in the series, 1, 10, 100, and so on, or by a fractional number in the series 1/10, 1/100, 1/1000, and so on.
  3. The significand - the specific value, which when multiplied by a power of 10 provides the numeric value of the data item.
  4. The significand sign - an indication of whether the resultant value of the data item is negative or positive.

ISO2002USAGE FLOAT-SHORT is equivalent to USAGE COMPUTATIONAL-1. USAGE FLOAT-LONG is equivalent to USAGE COMPUTATIONAL-2.

Items that are USAGE COMPUTATIONAL-1 (COMP-1) are usually referred to as single precision floating-point items while items that are USAGE COMPUTATIONAL-2 (COMP-2) are usually referred to as double precision floating-point items. Depending on the operating system or mathematical support libraries available to this COBOL system, different constraints can exist for single and double precision floating-point items. There can be constraints on the maximum exponent sizes, on the maximum significand sizes, or both. See your operating system or mathematical library floating-point support documentation for additional information.

COMPUTATIONAL-1 and COMPUTATIONAL-2 are equivalent to Single Format and Double Format, respectively, for operating systems that conform to ANSI/IEEE Std 754-1985, IEEE Standard for Binary Floating-Point Arithmetic.

It is important to understand that internal floating-point representation is not a continuous numeric spectrum. Internal floating-point representations are not standard from operating system to operating system. For example, in one representation of internal floating-point values, the following shows internal to decimal equivalence:

Internal (Hexadecimal) Storage Decimal Value (Scientific Notation)
x"AD17E148" -0.12345673E-23
x"AD17E149" -0.12345810E-23

Therefore, any application which tested for or expected an internal floating-point item with an exact decimal value of -0.12345678E-23, would never find it, while in some other system of internal floating-point storage, that value might be found while the values listed above would never exist. Therefore, any application which tests for exact equivalence between internal floating-point items and other numeric values (including external floating-point items and floating-point literals) cannot be portable and may result in different logic flow even when using the same input data.

For internal floating-point items, the size of the item in storage is determined by its USAGE clause. USAGE COMPUTATIONAL-1 reserves 4 bytes of storage for the item; USAGE COMPUTATIONAL-2 reserves 8 bytes of storage.

When the IBMCOMP Compiler directive is on, padding bytes can be generated before an internal floating-point item with a SYNC clause; these bytes are not part of the item, and are never affected by data stored in the item.

Within the COBOL system, COMP-1 items are accurate to 7 decimal digits and COMP-2 items to 16 decimal digits. However, for mainframe compatibility the DISPLAY statement shows 8 decimal places for COMP-1 and 18 for COMP-2. Any operations using floating-point items should take the limits of accuracy into account, and should disregard decimal places beyond the limits of accuracy.

OSVSVSC2MFXOPEN COMPUTATIONAL-3 ANS85or PACKED-DECIMAL
Format

This format, commonly called binary-coded decimal format, represents numeric data items in radix 10, but with each digit of the value held in only one half of one computer character, as described in Table 6 below. The sign is held in a separate trailing digit (half-character) position; that is, at the right-hand or least significant end of the item.

MFAny unused half bytes are set to zero.

Digit Value Digit Representation in Hexadecimal
Left Half-Character (odd digit) Right Half-Character (even digit)
0 x"00" x"00"
1 x"10" x"01"
2 x"20" x"02"
3 x"30" x"03"
4 x"40" x"04"
5 x"50" x"05"
6 x"60" x"06"
7 x"70" x"07"
8 x"80" x"08"
9 x"90" x"09"
Table 6: COMPUTATIONAL-3 Digit Representation

OSVSVSC2MFXOPENNote: Count even and odd starting from the right.

Table 8 shows the sign digit used for COMPUTATIONAL-3; storage requirements for this format depend only on the number of "9s" in the PICTURE clause of the data item as shown in Table 9.

Sign Convention in the PICTURE Clause Sign of Data Item Value Sign Half-character, in Hexadecimal
Unsigned n/a x"0F"
Signed + x"0C"
Signed - x"0D"
Table 7: COMPUTATIONAL-3 Sign Digit Representation
Bytes Required Number of Digits (Signed or Unsigned)
1 1
2 2-3
3 4-5
4 6-7
5 8-9
6 10-11
7 12-13
8 14-15
9 16-17
10 18-19
11 20-21
12 22-23
13 24-25
14 26-27
15 28-29
16 30-31
17 32-33
18 34-35
19 36-37
20 38
Table 8: Numeric Data Storage for the COMP(UTATIONAL)-3 ANS85 or PACKED-DECIMAL
PICTURE Clause.
Example:
  1. For COMPUTATIONAL-3 and PICTURE 9999, the number +1234 would be stored as follows:

    where F represents the non-printing plus sign.

  2. For COMPUTATIONAL-3 and PICTURE S9999, the number + 1234 would be stored as follows:

    where C represents the plus sign.

  3. For COMPUTATIONAL-3 and PICTURE S9999, the number -1234 would be stored as follows:

    where D represents the minus sign.

The SYNCHRONIZED clause (with or without the LEFT or RIGHT phrase) has no effect on COMPUTATIONAL-3 data declarations.

MFXOPENOS390 MFCOMPUTATIONAL-X and
COMPUTATIONAL-5 Formats

These formats are as for COMPUTATIONAL format except for the differences given below. See the section COMPUTATIONAL, BINARY, or COMPUTATIONAL-4 Format.

They both differ in the following ways from the COMPUTATIONAL format:

VSC2MF POINTER Format

The POINTER format holds a value that represents the memory address of an available data item. If the data item becomes unavailable (for example, because it is in a program that has been canceled) then the POINTER format is considered to hold a value that is incompatible with the format.

The default amount of storage allocated for the POINTER format may vary depending on the operating environment but is at least four bytes. The method of representation of the memory address varies between environments and is in general consistent with the representation used in non-COBOL languages.

When the IBMCOMP system directive is on, padding bytes can be generated before a pointer data item with a SYNC clause; these bytes are not part of the data item and are never affected by data stored in the item.

MFCOB370 PROCEDURE-POINTER Format

The PROCEDURE-POINTER format holds a value that represents the memory address of an available procedure. If the procedure becomes unavailable (for example, because it is in a program that has been canceled) then the PROCEDURE-POINTER format is considered to hold a value that is incompatible with the format.

The default amount of storage allocated for the PROCEDURE-POINTER format may vary depending on the operating environment but is at least four bytes. If the COBOL370 directive is specified, then eight bytes of storage are allocated. The method of representation of the memory address varies between environments and is in general consistent with the representation used in non-COBOL languages.

When the IBMCOMP system directive is on, padding bytes can be generated before a procedure-pointer data item with a SYNC clause; these bytes are not part of the data item and are never affected by data stored in the item.

Uniqueness of Reference

Qualification

Every user-specified name that defines an element in a COBOL source element.

ANS85and is referenced in that source element

must be unique, either because no other name has the identical spelling and hyphenation, or because the name exists within a hierarchy of names such that references to the name can be made unique by mentioning one or more of the higher levels of the hierarchy. The higher levels are called qualifiers and the process that specifies uniqueness is called qualification. Enough qualification must be mentioned to make the name unique; however, it may not be necessary to mention all levels of the hierarchy.

In the Data Division, all data-names used for qualification must be associated with a level indicator or a level-number. Therefore, two identical data-names must not appear as entries subordinate to a group item unless they are capable of being made unique through qualification

ANS85or they are never referenced

. In the Procedure Division, two identical paragraph-names must not appear in the same section.

In the hierarchy of qualification, names associated with a level indicator are the most significant, followed by those names associated with level-number 01, followed by names associated with level-number 02 through 49. A section-name is the highest (and the only) qualifier available for a paragraph-name. Thus, the most significant name in the hierarchy must be unique and cannot be qualified. Subscripted or indexed data-names and conditional variables, as well as procedure-names and data-names, can be made unique by qualification. The name of a conditional variable can be used as a qualifier for any of its condition-names. Regardless of the available qualification, no name can be both a data-name and procedure-name.

Qualification is performed by following a data-name, a condition-name, a paragraph-name, or a text-name by one or more phrases composed of a qualifier preceded by IN or OF, which are logically equivalent.

ANS85When the resource named is a function, the function definition may require the user to specify in the reference to the function a value or set of values for one or more parameters which determine the value of the function for that particular reference. This is accomplished through the specification of arguments as described in the section Function-identifier.

General Format:
Format 1

Format 2

Format 3

MFXOPENFormat 4

MFXOPEN

General Rules:
  1. Each qualifier must be of a successively higher level and within the same hierarchy as the name it qualifies.
  2. The same name must not appear at two levels in a hierarchy

    ANS85if it is explicitly referenced within the source unit
    .

  3. If a data-name or a condition-name is assigned to more than one data item in a source element, the data-name or condition-name must be qualified each time it is referred to in the Procedure, Environment, and Data Divisions (except in the REDEFINES clause, where qualification must not be used).
  4. A paragraph-name must not be duplicated within a section. When a paragraph-name is qualified by a section-name, the word SECTION must not appear. A paragraph-name need not be qualified when referred to from within the same section.

    ANS85Neither a paragraph-name nor a section-name need be unique, or capable of being made unique, unless explicitly referenced.

  5. A data-name cannot be subscripted when it is being used as a qualifier.
  6. A name can be qualified even when it does not need qualification; if there is more than one combination of qualifiers that ensures uniqueness, then any such set can be used. The complete set of qualifiers for a data-name must not be the same as any partial set of qualifiers for another data-name.

    Qualified data-names can have up to five qualifiers.

    ANS85Up to fifty qualifiers are permitted.

  7. If more than one COBOL library is available to your COBOL system, text-name must be qualified each time it is referenced.

    OSVSVSC2MFThis restriction is not enforced.

Subscripting

Subscripts can be used only when reference is made to an individual element within a list or table of like elements that have not been assigned individual data-names (see the topic The OCCURS Clause).

The subscript can be represented either by a numeric literal that is an integer, by a data-name, or by a data-name followed by the operator "+" or "-" , followed by an unsigned integer numeric literal. The data-name must be a numeric elementary item that represents an integer, and the whole subscript must be delimited by the balanced pair of separators, left-parenthesis and right-parenthesis.

The subscript data-name can be signed and, if signed, must be positive. The lowest possible subscript value is 1. This value points to the first element of the table. The next sequential elements of the table are pointed to by subscripts whose values are 2, 3, ... . The highest permissible subscript value, in any particular case, is the maximum number of occurrences of the item as specified in the OCCURS clause.

The subscript, or set of subscripts, that identifies the table element is delimited by the balanced pair of separators, left parenthesis and right parenthesis following the table element data-name. The table element data-name appended with a subscript is called a subscripted data-name or an identifier. When more than one subscript is required, they are written in the order of successively less inclusive dimensions of the data organization. Up to 3 subscripts are permitted.

ANS85Up to 7 subscripts are permitted.

MFUp to 16 subscripts are permitted.

General Format

Syntax Rules
  1. The data description entry containing data-name-1 or the data-name associated with condition-name-1 must contain an OCCURS clause or must be subordinate to a data description entry which contains an OCCURS clause.
  2. Except as defined in Syntax Rule 7, when a reference is made to a table element, the number of subscripts must equal the number of OCCURS clauses in the description of the table element being referenced. When more than one subscript is required, the subscripts are written in the order of successively less inclusive dimensions of the table.
  3. ANS85 The subscript ALL can be used only when the subscripted identifier is used as a function argument and cannot be used when condition-name-1 is specified. (See the topic Arguments.)
  4. Integer-1 can be signed, and if signed, must be positive.
  5. Data-name-2 can be qualified and must be a numeric elementary item representing an integer.
  6. Index-name-1 must correspond to a data description entry in the hierarchy of the table being referenced which contains an INDEXED BY phrase specifying that index-name.

    OSVSVSC2MF An index described for some other table can be used instead, provided the two tables have elements of the same size.

  7. Each table element reference must be subscripted except when such reference appears:
    1. In a USE FOR DEBUGGING statement
    2. As the subject of a SEARCH or SORT statement
    3. In a REDEFINES clause
    4. In the KEY IS phrase of an OCCURS clause.
  8. OSVSThe mixing of subscripts and indices in the same identifier is illegal.

    ANS85The mixing of subscripts and indices in the same identifier is legal.

General Rules
  1. The value of the subscript must be a positive integer. The lowest possible occurrence number represented by a subscript is 1. The first element of any given dimension of a table is referenced by an occurrence number of 1. Each successive element within that dimension of the table is referenced by occurrence numbers of 2, 3, ... . The highest permissible occurrence number for any given dimension of the table is the maximum number of occurrences of the item specified in the associated OCCURS clause.

    MFIf the subscript is a floating-point data item, the value is rounded to the nearest integer, otherwise any fractional part is truncated.

    If arithmetic-expression-1 is specified, and the final result of the arithmetic expression is not an integer, the final result is truncated. Intermediate results are not truncated.

    If arithmetic-expression-1 is specified, and if the final result or any intermediate result of the arithmetic expression is negative, the effect is unpredictable.

  2. The value of the index referenced by index-name-1 corresponds to the occurrence number of an element in the associated table.
  3. The value of the index referenced by index-name-1 must be initialized before it is used as a subscript. An index can be given an initial value by either a PERFORM statement with the VARYING phrase, a SEARCH statement with the ALL phrase, or a SET statement. An index can be modified only by the PERFORM, SEARCH, and SET statements.
  4. If

    ANS85integer-2 or

    integer-3 is specified, the value of the subscript is determined by incrementing by the value of

    ANS85integer-2 or

    integer-3 (when the operator "+" is used) or by decrementing by the value of

    ANS85integer-2 or

    integer-3 (when the operator "-" is used),

    ANS85either

    the occurrence number represented by the value of the index referenced by index-name-1

    ANS85or the value of the data item referenced by data-name-2
    .

Comments:

MFIf the NOBOUND Compiler directive is specified, the General Rules are not applicable at run time.

Indexing

References can be made to individual elements within a table of like elements by specifying indexing for that reference. An index is assigned to that level of the table by using the INDEXED BY phrase in the definition of a table. A name given in the INDEXED BY phrase is known as an index-name and is used to refer to the assigned index. The value of an index corresponds to the occurrence number of an element in the associated table or any other table. An index-name must be initialized before it is used as a table reference. An index-name can be given an initial value by a SET statement.

Unlike a subscript, which is simply a numeric data item or literal, an index is a special type of item and holds a representation of an occurrence number. The form of this representation can vary; the contents of an index cannot be regarded as a numeric value.

Direct indexing is specified by using an index-name in the form of a subscript. Relative indexing is specified when the index-name is followed by the operator "+" or "-", followed by an unsigned integer numeric literal, all delimited by the balanced pair of separators left parenthesis and right parenthesis following the table element data-name. The occurrence number resulting from relative indexing is determined by incrementing (where the operator "+" is used) or decrementing (where the operator "-" is used), by the value of the literal, the occurrence number represented by the value of the index. When more than one index-name is required, they are written in the order of successively less inclusive dimensions of the data organization.

A table can be indexed only by the index described in its INDEXED BY phrase.

OSVSVSC2MFAn index described for some other table can be used instead provided the two tables have elements of the same size.

At the time of execution of a statement which refers to an indexed table element, the value contained in the index used to index it must neither correspond to a value less than one nor to a value greater than the highest permissible occurrence number of an element of the associated table. This restriction also applies to the value resulting from relative indexing.

MFIf the NOBOUND Compiler directive is specified, this rule is not applicable at run time.

Up to 3 index-names can be used with a data-name.

ANS85Up to 7 index-names can be used with a data-name.

MFUp to 16 index-names can be used with a data-name.

The general format for indexing is included in the general format for subscripting; see the section Subscripting.

ANS85 Function-identifier

A function-identifier references the unique data item that results from the evaluation of a function.

General Format

Syntax Rules
  1. A function-identifier must not be specified as a receiving operand.
  2. The word FUNCTION is required

    ISO2002ISO2002unless either of the following apply:

    1. intrinsic-function-name-1 is specified in the Repository paragraph
    2. function-prototype-name-1 is specified.
  3. ISO2002Function-prototype-name-1 must be a function prototype specified in the Repository paragraph.
  4. ISO2002The word OMITTED must not be specified if intrinsic-function-name-1 is specified.
  5. Argument-1 must be an identifier, a literal, or an arithmetic expression. Specific rules governing the number, class, and category of argument-1 are given for intrinsic functions in the definition of that intrinsic function in the section Definitions of Functions in the chapter Procedure Division - Intrinsic Functions

    ISO2002and for user-defined functions in the section Conformance for Parameters and Returning Items in the chapter Procedure Division
    .

  6. ISO2002If the word OMITTED is specified, the OPTIONAL phrase must be specified for the corresponding formal parameter.
  7. ISO2002If function-prototype-name-1 is specified and the formal parameter corresponding to argument-1 is specified with a BY VALUE phrase, argument-1 must be of class numeric, object or pointer.
  8. A numeric function must not be specified where an integer operand is required, even though a particular reference of the numeric function might yield an integer value.
  9. An integer function other than the integer form of the ABS function must not be specified where an unsigned integer is required.
  10. A function-identifier which references an integer or numeric function can only be used in an arithmetic expression.
  11. ISO2002If function-prototype-name-1 is specified, the rules for conformance specified in the section Conformance for Parameters and Returning Items in the chapter Procedure Division apply.
  12. A reference modifier can be specified only for functions of the category alphanumeric

    ISO2002MFor national
    .

  13. If a function's definition permits arguments and a left parenthesis immediately follows function-prototype-name-1 or intrinsic-function-name-1, the left parenthesis is always treated as the left parenthesis of that function's arguments.

    Note: For a function that may be referenced either with or without arguments, such as the RANDOM function, careful coding is necessary to ensure correct interpretation. For example, in the following:

     FUNCTION MAX (FUNCTION RANDOM (A) B)

    'A' is treated as an argument to the RANDOM function. If 'A' is instead meant to be a second argument to the MAX function, different coding is necessary - either:

     FUNCTION MAX (FUNCTION RANDOM () A B)
    
       or
     FUNCTION MAX ( (FUNCTION RANDOM) (A) B)
    
       or
     FUNCTION MAX (FUNCTION RANDOM A B)
General Rules
  1. A function-identifier references a temporary data item whose value is determined when the function is referenced at run time.

    If intrinsic-function-name-1 is specified, the temporary data item is an elementary data item whose description and category are specified by the definition of that intrinsic function in the section Definitions of Functions in the chapter Procedure Division - Intrinsic Functions.

    ISO2002If function-prototype-name-1 is specified, the description, class, and category of the temporary data item is that specified by the description in the Linkage Section of the item specified in the RETURNING phrase of the PROCEDURE DIVISION header of the function prototype identified by function-prototype-name-1.

  2. At the time reference is made to a function, its arguments are evaluated individually in the order specified in the list of arguments, from left to right. An argument being evaluated may itself be a function-identifier or may be an expression containing function-identifiers. There is no restriction preventing the function referenced in evaluating an argument from being the same function as that for which the argument is specified. In other words, recursion is permitted. Additional rules for intrinsic functions are given in the section Intrinsic Functions

    ISO2002for user-defined functions in the sections The PROCEDURE DIVISION Header and Conformance for Parameters and Returning Items in the chapter Procedure Division

    MFIf a function is expecting an integer argument, then if a floating-point argument is provided, the value is rounded to the nearest integer, otherwise any fractional part is truncated.

  3. ISO2002If function-prototype-name-1 is specified, the function to be activated is identified by function-prototype-name-1 in accordance with the rules specified in the section The Repository Paragraph in the chapter Environment Division, and function-prototype-name-1 is used to determine the characteristics of the activated function.
  4. ISO2002If function-prototype-name-1 is specified, the manner used for passing each argument is determined as follows:
    1. BY REFERENCE is assumed when the BY REFERENCE phrase is specified or implied for the corresponding formal parameter and argument-1 is an identifier that is permitted as a receiving operand, other than an object property, object data item or factory object data item.
    2. BY CONTENT is assumed when the BY REFERENCE phrase is specified or implied for the corresponding formal parameter and argument-1 is a literal, an arithmetic expression, an object property, object data item, factory object data item or any identifier that is not permitted as a receiving operand.
    3. BY VALUE is assumed when the BY VALUE phrase is specified for the corresponding formal parameter.
  5. Evaluation of the function-identifier proceeds as follows:
    1. Each argument-1 is evaluated at the beginning of the evaluation of the function-identifier. The values of argument-1 are made available to the activated function at the time control is transferred to that function.
    2. The run-time system attempts to locate the function being activated.

      ISO2002If function-prototype-name-1 is specified, the rules are specified in the section Conventions for Function-prototype-names. Additional rules are given in the section The Repository Paragraph in the chapter Environment Division.

    3. If the function is located but the resources necessary to execute the function are not available, the function is not activated. The run-time resources that are checked in order to determine the availability of the function for execution are defined by the implementor.
    4. The function specified by the function-identifier is made available for execution and control is transferred to the activated function in a manner consistent with the call convention specified for the function.

      ISO2002If function-prototype- name-1 is specified and the function to be activated is a COBOL function, its execution is as described in the section The PROCEDURE DIVISION Header in the chapter Procedure Division.

      If intrinsic-function-name-1 is specified, its execution is as described in the chapter Procedure Division - Intrinsic Functions.

      ISO2002If function-prototype-name-1 is specified and the function to be activated is not a COBOL function, the execution is as defined in your COBOL system documentation on interfacing.

  6. If the word OMITTED is specified or a trailing argument is omitted, the omitted-argument condition for that parameter evaluates to TRUE in the activated function. (See the topic The Omitted-Argument Condition.)
  7. If a parameter for which the omitted-argument condition is true is referenced in an activated function, except as an argument or in the omitted-argument condition,, you will get runtime error 203.
Reference Modification

Reference modification defines a unique data item by specifying an identifier, a leftmost position and a length.

General Format

identifier-1 ( leftmost-position : [length] )

Syntax Rules
  1. Identifier-1 must reference a data item that is one of the following:
  2. Leftmost-position and length must be arithmetic expressions.
  3. Unless otherwise specified, reference modification is allowed anywhere an identifier referencing a data item of the class alphanumeric or national is permitted.
  4. Identifier-1 must not include reference-modification.
  5. If identifier-1 is a function-identifier, it must reference an alphanumeric or national function.
General Rules
  1. Leftmost-position represents an alphanumeric position or national position when identifier-1 references an alphanumeric or national data item, respectively.
  2. Each position of the data item referenced identifier-1 is assigned an ordinal number incrementing by one from the leftmost position to the rightmost position. The leftmost position is assigned the ordinal number one. If the data description entry for identifier-1 contains a SIGN IS SEPARATE clause, the sign position is assigned an ordinal number within that data item.
  3. If the data item referenced by identifier-1 is explicitly or implicitly described as usage DISPLAY and the category is numeric,

    OSVSVSC2MFexternal floating-point,

    numeric edited, alphabetic, or alphanumeric edited, it is operated upon for purposes of reference modification as if it were redefined as an alphanumeric data item of the same size as the data item referenced by identiifer-1.

  4. Reference modification for an operand is evaluated as follows:
    1. If subscripting is specified for the operand, the reference modification is evaluated immediately after evaluation of the subscripts. If an ALL subscript is specified for an operand, the reference-modifier is applied to each of the implicitly specified elements of the table.
    2. If subscripting is not specified for the operand, the reference modification is evaluated at the time subscripting would have been evaluated if subscripts had been specified.
    3. If reference modification is specified in a function reference, the reference modification is evaluated immediately after evaluation of the function.
    4. If reference modification is specified in an object property reference, the reference modification is evaluated immediately after evaluation of the object property.
  5. Reference modification creates a unique data item that is a subset of the data item referenced by identifier-1. This unique data item is defined as follows:
    1. The evaluation of leftmost-position specifies the ordinal position of the leftmost character of the unique data item in relation to the leftmost character of the data item referenced by identifier-1. Evaluation of leftmost-position must result in a positive nonzero integer less than or equal to the number of positions in the data item referenced by identifier-1.

      VSC2MFThe results are rounded if the expression is in floating-point, and truncated if the expression is in fixed-point.

    2. The evaluation of length specifies the size in characters of the data item to be used in the operation. The evaluation of length must result in a positive nonzero integer. The sum of leftmost-position and length minus the value one, must be less than, or equal to, the number of characters in the data item referenced by identifier-1. If length is not specified, the unique data item extends from and includes the character identified by leftmost-position, up to and including the rightmost character of the data item referenced by identifier-1.

      VSC2MFThe results are rounded if the expression is in floating-point, and truncated if the expression is in fixed-point.

      Note: There is no check that the evaluation of leftmost-position and length produce valid values. If these evaluations do not conform to the restrictions stated in this rule, the result is undefined and other data items may be corrupted.

  6. The unique data item is considered an elementary data item without the JUSTIFIED clause. The unique data item has the same class, category and usage as that defined for the data item referenced by identifier-1, except that:
  7. OSVS If the OSVS Compiler directive is set, reference modification cannot be used in conditional expressions (see the topic Conditional Expressions).
Identifier

An identifier is a sequence of character-strings and separators used to reference data uniquely.

General Formats
Format 1

Format 2

ISO2002MFFormat 3
   property-name-1 OF identifier-1
ISO2002MFFormat 4
   inline-invocation-1
ISO2002MFFormat 5
   identifier-2 object-view-1
ISO2002MFFormat 6

ISO2002MF

Syntax Rules:
  1. Subscript-1 represents either subscripting (see the section Subscripting) or indexing (see the section Indexing).
General Rules:
    Format 2
  1. The words IN and OF are equivalent.
  2. A data-name must neither be subscripted nor indexed when it is being used as an index, or subscript.
  3. Indexing is not permitted where subscripting is not permitted.
  4. An index can be modified only by the SET, SEARCH, and PERFORM statements. Data items described by the USAGE IS INDEX clause permit storage of the values associated with index-names as data. Such data items are called index data items.
  5. Literals used as subscripts must be positive numeric integers. Literals used for relative subscripting and indexing must be unsigned numeric integers.
  6. ISO2002Format 3
  7. ISO2002Object properties provide a special syntax to get information out of and pass information back into an object. The mechanisms for accessing object properties are get property methods and set property methods. A get property method is a method explicitly defined with the GET PROPERTY phrase or a method implicitly generated for a data item described with the PROPERTY clause; a set property method is a method explicitly defined with the SET PROPERTY phrase or a method implicitly generated for a data items described with the PROPERTY clause.
  8. ISO2002Property-name-1 must be an object property specified in the Repository paragraph.
  9. ISO2002Identifier-1 must be an object reference; neither a universal object reference, nor the predefined object reference NULL can be specified.
  10. ISO2002If the object property is used as a sending item, a get property method must exist for property-name-1 in the object referenced by identifier-1.
  11. ISO2002If the object property is used as a receiving item, a set property method must exist for property-name-1 in the object referenced by identifier-1.
  12. ISO2002The description of an object property used as a sending item is the same as the description of the returning item of the get property method. This object property can be specified wherever a data item with that description would be valid as a sending item.
  13. ISO2002The description of an object property used as a receiving item is the same as the description of the using parameter of the set property method. This object property may be specified wherever a data item with that description would be valid as a receiving item.
  14. ISO2002The data description of the item specified in the RETURNING phrase of the get property method must be the same as the data description of the item specified as the USING parameter of the set property method.
  15. ISO2002When an object property is used only as a sending item, a conceptual temporary data item, temp-1 is used in its place. The value of the property is determined as though the associated get property method were invoked, in accordance with the rules of the INVOKE statement, and the returned value placed in temp-1. The data description of temp-1 is the same as the data description of the item specified in the RETURNING phrase of the get property method.
  16. ISO2002When an object property is used only as a receiving item, a conceptual temporary data item, temp-2, is used in its place. The value of the property is assigned as though the associated set property method were invoked, in accordance with the rules of the INVOKE statement, passing the content of temp-2 as the parameter. The data description of temp-2 is the same as the data description of the item specified as the USING parameter of the set property method.
  17. ISO2002When an object property is used as both a sending item and a receiving item, conceptual temporary data items temp-1 and temp-2 are used in its place; temp-1 and temp-2 are the same temporary data item, where temp-2 redefines temp-1. For sending operations, the value of the property is determined in the same manner as for sending items in general rule 1; for receiving operations, the value of the property is assigned in the same manner as for receiving items in general rule 2. The data descriptions of temp-1 and temp-2 are the same as the data description of the item specified in the RETURNING phrase of the get property method.
  18. ISO2002MFFormat 4
  19. ISO2002MFInline-invocation-1 is defined by the section Inline Method Invocation
  20. ISO2002MFFormat 5
  21. ISO2002MFObject-view-1 is defined by the section Object-view
  22. ISO2002MFFormat 6
  23. ISO2002MFAddress-identifiers are defined by the section Data-address-identifier and the section Program-address-identifier.
Condition-name

Each condition-name must be unique, or be made unique through qualification and/or indexing, or subscripting. If qualification is used to make a condition-name unique, the associated conditional variable can be used as the first qualifier. The hierarchy of names associated with the conditional variable or the conditional variable itself must be used to make the condition-name unique.

If references to a conditional variable require indexing or subscripting, references to any of its condition-names require the same combination of indexing or subscripting.

The format and restrictions on the combined use of qualification, subscripting, and indexing of condition-names are exactly those of "identifier" except that data-name-1 is replaced by condition-name-1.

In the general formats, "condition-name" refers to a condition-name qualified, indexed or subscripted, as necessary.

Inline method invocation

Inline method invocation references a temporary data item returned from invocation of a method.

General Format

Syntax Rules
  1. Inline method invocation must not be specified as a receiving operand.
  2. Identifier-1 must be of class object; neither the predefined object reference NULL nor a universal object reference may be specified.
  3. One of the INVOKE statements specified in general rule 1 must be valid according to syntax rules for the INVOKE statement.
  4. The data item referenced in the RETURNING phrase of the invoked method's PROCEDURE DIVISION header must not be described with the ANY LENGTH clause.
General Rules
  1. An inline method invocation references a temporary data item with the same class, category, and content as the temp-identifier that would be returned from the execution of the applicable form of INVOKE statement, as follows:

    INVOKE identifier-1 literal-1 USING arguments RETURNING temp-identifier INVOKE identifier-1 literal-1 RETURNING temp-identifier INVOKE class-name-1 literal-1 USING arguments RETURNING temp-identifier INVOKE class-name-1 literal-1 RETURNING temp-identifier
    where:
    1. arguments are the operands specified within parentheses in the inline method invocation, if any
    2. temp-identifier has the same description, class, and category as the RETURNING parameter in the specification of the method identified by literal-1 and either identifier-1 or class-name-1
    3. temp-identifier is a temporary item that exists for the purpose of effecting the inline invocation in this way and for no other purpose
Object-view

An object-view causes an object reference to be treated as though it had the specified description. A runtime conformance check for this description will be done on the object.

General Format

Syntax Rules
  1. Identifier-1 must be of class object; the predefined object references SUPER and NULL must not be specified.
  2. An object-view must not be specified as a receiving operand.
General Rules
  1. This reference of identifier-1 is treated at compile-time as though it had the description specified by the AS phrase.
  2. If class-name-1 is specified without either of the optional phrases, identifier-1 is treated as though it were described as USAGE IS OBJECT REFERENCE class-name-1. If the object referenced by identifier-1 is not an object of class-name-1 or an object of a subclass of class-name-1, the EC-OO-CONFORMANCE exception condition is set to exist.
  3. If the FACTORY phrase is specified and the ONLY phrase is not specified, identifier-1 is treated as though it were described as USAGE OBJECT REFERENCE FACTORY OF class-name-1. If the object referenced by identifier-1 is not the factory object of class-name-1 or the factory object of a subclass of class-name-1, the EC-OO-CONFORMANCE exception condition is set to exist.
  4. If the ONLY phrase is specified and the FACTORY phrase is not specified, identifier-1 is treated as though it were described as USAGE OBJECT REFERENCE class-name-1 ONLY. If the object referenced by identifier-1 is not an object of class-name-1, the EC-OO-CONFORMANCE exception condition is set to exist.
  5. If both the FACTORY phrase and the ONLY phrase are specified, identifier-1 is treated as though it were described as USAGE OBJECT REFERENCE FACTORY OF class-name-1 ONLY. If the object referenced by identifier-1 is not the factory object of class-name-1, the EC-OO-CONFORMANCE exception condition is set to exist.
  6. If interface-name-1 is specified, identifier-1 is treated as though it were described as USAGE OBJECT REFERENCE interface-name-1. If the object referenced by identifier-1 does not implement interface-name-1, the EC-OO-CONFORMANCE exception condition is set to exist.
  7. If UNIVERSAL is specified, identifier-1 is treated as though it were described as USAGE OBJECT REFERENCE without any of the optional phrases to indicate the class or interface for objects referenced by identifier-1. The EC-OO-CONFORMANCE exception condition is not set to exist.
Data-address-identifier

A data-address-identifer references the unique data item that contains the address of a data item.

General Format
ADDRESS of identifier-1
Syntax Rules
  1. Identifier-1 must reference a data item defined in the File Section, Working-Storage Section, Local-Storage Section or Linkage Section. Identifier-1 must not be defined in the Working-Storage or the File Section of an instance object or a factory object.
  2. Identifier-1 must not reference an object reference.
  3. This identifier format must not be specified as a receiving opernad.
General Rules
  1. Data-address-identifier creates a unique data item of class pointer and category data-pointer that contains the address of identifier-1.
Program-address-identifier

General Format

Syntax Rules
  1. Identifier-1 must of of category alphanumeric or national.
  2. Literal-1 must be an alphanumeric or national literal.
  3. Program-prototype-name-1 must be a program prototype specified in the Repository paragraph.
  4. This identifier format must not be specified as a receiving operand.
General Rules
  1. Program-address-identifier creates a unique data item of class pointer and category program-pointer that contains the address of a program identified by one of the following:
    1. the content of the data item referenced by identifier-1
    2. the value of literal-1
    3. program-prototype-name-1.

    If identifier-1 or literal-1 is specified, COBOL Words in the chapter Concepts of the COBOL Language describes how this value is used to identify the referenced program.

  2. The program may be written in COBOL or in another language. For a COBOL program, the address is that of the outermost program identified by the externalized program-name in its Program-ID paragraph.
  3. When program-prototype-name-1 is specified, the program-address-identifier has the characteristics of a program-pointer restricted to program-prototype-name-1.
  4. If the runtime system cannot locate the program, the value of the address-identifier is the predefined address NULL.

Explicit and Implicit Specifications

There are four types of explicit and implicit specifications that occur in COBOL source elements:

  1. Explicit and implicit Procedure Division references.
  2. Explicit and implicit transfers of control.
  3. Explicit and implicit attributes.
  4. ANS85Explicit and implicit scope terminators.

Explicit and Implicit Procedure Division References

A COBOL source element can reference data items either explicitly or implicitly in Procedure Division statements. An explicit reference occurs when the name of the referenced item is written in a Procedure Division statement or when the name of the referenced item is copied into the Procedure Division by the processing of a COPY statement

ANS85, a REPLACE statement

OSVSVSC2, an -INC statement, or ++INCLUDE statement

. An implicit reference occurs when the item is referenced by a Procedure Division statement without the name of the referenced item being written in the source statement.

An implicit reference also occurs during the execution of a PERFORM statement, when the index or data item referenced by the index-name or identifier specified in the VARYING, AFTER or UNTIL phrase is initialized, modified, or evaluated by the control mechanism associated with that PERFORM statement. Such an implicit reference occurs if and only if the data item contributes to the execution of the statement.

Explicit and Implicit Transfers of Control

The flow of control mechanism transfers control from statement to statement in the sequence in which they were written unless an explicit transfer of control overrides this sequence or there is no next executable statement to which control may be passed. The transfer of control from statement to statement occurs without the writing of an explicit Procedure Division statement, and, therefore, is an implicit transfer of control.

COBOL provides both an explicit and an implicit means of altering the implicit control transfer mechanism.

In addition to the implicit transfer of control between consecutive statements, implicit transfer of control occurs when the normal flow is altered without the execution of a procedure branching statement. COBOL provides the following types of implicit control flow alterations which override the statement-to-statement transfers of control:

  1. If a paragraph is being executed under control of another COBOL statement (for example, PERFORM, USE, SORT and MERGE) and the paragraph is the last paragraph in the range of the controling statement, then an implied transfer of control occurs from the last statement in the paragraph to the control mechanism of the last executed controling statement. Further, if a paragraph is being executed under the control of a PERFORM statement which causes iterative execution and that paragraph is the first paragraph in the range of that PERFORM statement, an implicit transfer of control occurs between the control mechanism associated with that PERFORM statement and the first statement in that paragraph for each iterative execution of the paragraph.
  2. When a SORT or MERGE statement is executed, an implicit transfer of control occurs to any associated input or output procedures.
  3. When any COBOL statement is executed that results in the execution of a declarative section, an implicit transfer of control to the declarative section occurs.
  4. Note: Another implicit transfer of control occurs after execution of the declarative section, as described in item 1. above.

  5. MFIn any file operation (including OPEN and CLOSE), if a file does not have a FILE STATUS data item declared for it and the file is not explicitly covered by a USE statement, then it is covered by an implicit USE statement. The implied USE procedure is equivalent to:
    USE AFTER ERROR PROCEDURE ON file-name. 
    IF status-key-1 >= 3
      DISPLAY error-message UPON CONSOLE 
      STOP RUN.

    See your COBOL system documentation for descriptions of error messages.

An explicit transfer of control consists of an alteration of the implicit control transfer mechanism by the execution of a procedure branching, ending or conditional statement. An explicit transfer of control between statements can be caused only by the execution of a procedure branching or conditional statement. An explicit transfer of control between sentences can be caused only by the execution of the NEXT SENTENCE phrase of an IF or SEARCH statement.

The execution of the procedure branching statement ALTER does not in itself constitute an explicit transfer of control, but affects the explicit transfer of control that occurs when the associated GO TO statement is executed. The procedure branching statement EXIT PROGRAM causes an explicit transfer of control only when the statement is executed in a called program.

The term "next executable sentence" is used to refer to the next COBOL sentence to which control is either implicitly transferred according to the rules above, or explicitly transferred as a result of execution of the NEXT SENTENCE phrase. The next executable sentence is the first sentence following the separator period that terminates the current sentence. There is no next executable sentence when there is no next executable statement as described below.

The term "next executable statement" is used to refer to the next COBOL statement to which control is transferred according to the rules above and the rules associated with each language element in the Procedure Division.

There is no next executable statement following:

Explicit and Implicit Attributes

Attributes can be implicitly or explicitly specified. Any attribute which has been explicitly specified is called an explicit attribute. If an attribute has not been specified explicitly, then the attribute takes on the default specification. Such an attribute is known as an implicit attribute.

For example, the usage of a data item need not be specified, in which case a data item's usage is DISPLAY

OSVSVSC2MF, unless the PICTURE character-string contains a "G" or an "N", in which case a data item's usage is DISPLAY-1
.

ANS85 Explicit and Implicit Scope Terminators

Scope terminators delimit the scope of certain Procedure Division statements (delimited scope statements), and are of two types: explicit and implicit.

The explicit scope terminators are listed below:

ANS85Note: In some cases the delimited scope statement with which an explicit scope delimiter is paired is determined differently for different COBOL language specifications.

Implicit scope termination occurs: