Character-Strings COBOL

A character-string is a sequence of one or more characters that forms a COBOL word, literal, PICTURE character-string, or comment-entry. A character-string is delimited by separators.

COBOL Words

A COBOL word is a character-string of not more than 30 characters which forms a user-defined word, a system-name, a context-sensitive word,or a reserved word. Each character of a COBOL word is selected from the set of letters, digits and the hyphen. The hyphen may not appear as the first or last character. Lowercase letters are considered equivalent to the corresponding uppercase letters. Within a source program, reserved words and user-defined words form disjoint sets; reserved words and systemnames form disjoint sets, system-names and user-defined words form intersecting sets.

The same COBOL word may be used as a system-name and as a user-defined word within a source program; the class of a specific occurrence of this COBOL word is determined by the context of the clause or phrase in which it occurs.

User-Defined Words

User-defined words comprise alphabetic and numeric characters,and the hyphen. A user-defined word can neither begin nor end with a hyphen. With the exception of paragraph-names, section-names, level-numbers and segment-numbers, all user-defined words must contain at least one alphabetic character.

Here are the types of user-defined words:

User-Defined Words

Within a given source program,but excluding any contained program,the user-defined words are grouped into the following disjoint sets:

User-Defined Words

All user-defined words, except segment-numbers and level-numbers,can belong to only one of these disjoint sets. Further, all user-defined words within a given disjoint set must be unique, except as specified in the rules for uniqueness of reference. Segment-numbers and level-numbers need not be unique;a given specification of a segment-number or level-number may be identical to any other segment-number or level-number.

The types of user-defined words are defined as follows:

  1. Alphabet-name:An alphabet-name identifies a character code set. It must contain at least one alphabetic character and must be unique.
  2. Cd-name:A cd-name identifies a Message Control System (MCS) interface area, which is described in a communication description entry within the Communication Section of the Data Division. Cd-names must be unique and contain at least one alphabetic character.
    Note:An MCS is application-specific and not supplied with RM/COBOL. See the RM/COBOL User’s Guide for further information.
  3. Class-name:A class-name identifies a user-specified list of characters. A class-name must be unique and it must contain at least one alphabetic character. A class-name is defined in the SPECIAL-NAMES paragraph of the Environment Division. It may then be used in a class condition test in the Procedure Division to determine if the current contents of a data item consist entirely of characters in the list identified by the class-name.
  4. Condition-name:A condition-name may be defined in the SPECIAL-NAMES paragraph within the Environment Division or in a level-number 88 description within the Data Division. Condition-names must contain at least one alphabetic character.
    A SPECIAL-NAMES condition-name is assigned to ON STATUS or OFF STATUS of one of eight system software switches.
    A level-number 88 condition-name is assigned to a specific value,set of values,or range of values within a complete set of values that a data item may assume. The data item itself is called a conditional variable.
    A condition-name may be used in conditions as an abbreviation for the relation condition which tests whether the associated switch or conditional variable is equal to one of the set of values to which that condition-name is assigned. A conditionname may also be used in a SET statement, indicating that the associated value is to be moved to the conditional variable.
  5. Constant-name:A constant-name is defined in a level-number 78 data description entry and names a literal value. A constant-name must be defined before any reference to the constant-name. Constant-names must contain at least one alphabetic character and must be unique. A constant-name is always global and thus may be referenced in any program contained in the program that defines the constant-name.
    An integer-valued constant-name may be defined using a constant-expression. The constant-expression is evaluated at the time of the definition during compilation and any reference to the constant-name is equivalent to a reference to the resultant integer value. The constant-expression may refer to previously defined integervalued constant-names.
    References to constant-names may be used in any context where the assigned literal value could be used unless otherwise prohibited. The effect of a constant-name reference is the same as if the literal value assigned to the constant-name were written instead. Constant-names that have an integer value may be used wherever integer is specified in the syntax formats, for example, integers in BLOCK or RECORD clauses of a file control entry, integer occurrence counts in an OCCURS clause, and in constant-expressions used to define other integer-valued constant names. An integer-valued constant-name may also be used as the integer repeat count specification in PICTURE character-strings.
  6. Data-name:A group of contiguous characters or a numeric value treated as a unit of data is called a data item, and it is named by a data-name. A data-name must contain at least one alphabetic character. References to data items must be made unique by qualification, the appending of subscripts,or both.
    Complete unique references to data items are called identifiers.When used in the general formats, ‘data-name’ represents a word that must not be reference-modified, subscripted, or qualified unless specifically permitted by the rules of the format.
  7. File-name:File-names are the internal names for files accessed by the source program. They are not necessarily the same as the external names by which the file is known to the runtime operating system. File-names must contain at least onealphabetic character and must be unique.
  8. Index-name:An index-name names an index associated with a specific table. It must contain at least one alphabetic character and must be unique.
  9. Level-number:A level-number specifies the position of a data item within a data hierarchy. A level-number is a one- or two-digit number in the range 01–49,66,77,78,or88.
    Level-numbers 66, 77, and 88 identify special properties of a data description entry.
  10. Library-name;A library-name is a user-defined word that identifies a library to be used by the compiler for a given COPY statement. Library-names must be unique.
  11. Mnemonic-name:A mnemonic-name is a user-defined word that is associated in the SPECIAL-NAMES paragraph with a switch-name, feature-name or low-volume-I-O-name. Mnemonic-names must be unique and must contain at least one alphabetic character.
  12. Paragraph-name:A paragraph-name identifies the beginning of a set of COBOL procedural sentences. A reference to a nonunique paragraph-name must be made unique by qualification with a section-name. Paragraph-names are equivalent only if they are composed of the same sequence of the same number of digits or characters.
  13. Program-name:The program-name identifies the source and object programs. The name must contain at least one alphabetic character.
  14. Record-name:Record-names name data records within a file. They must contain at least one alphabetic character and, if not unique, must be made unique by qualification with the file-name.
  15. Routine-name:A routine-name is a user-defined word that identifies a procedure written in a language other than COBOL.
  16. Screen-name:A screen-name identifies a set of one or more entries; these entries define fields within a region of a terminal screen. Screen-names must contain at least one alphabetic character and,if not unique,must be made unique by qualification.
  17. Section-name:A section-name identifies the beginning of a set of paragraphs. Section-names must be unique and must contain at least one alphabetic character.
  18. Segment-number:A segment-number specifies the segmentation classification of a section. It is a one- to three-digit number in the range 00–127.
  19. Split-key-name:A split-key-name is a user-defined word that names a concatenation of one or more data items within a record associated with an indexed file. The concatenation of the data items forms a single record key for that file. References to split-key-names must be made unique by qualification. The only qualifier allowed for a split-key-name is the file-name of the file with which the split-key-name is associated.
  20. Symbolic-character:A symbolic-character is a user-defined word that identifies a user-defined figurative constant. Symbolic-characters must be unique and must contain at least one alphabetic character.
  21. Text-name:A text-name is the name of a library text file. It must correspond exactly to a valid file access name that is known to the compile-time operating system.

System-Names

System-names identify certain hardware or software system components. System-names consist of code-names,device-names, feature-names, label-names, low-volume-I-O-names, record delimiting techniques,and switch-names. Most system-names are not reserved words, but certain reserved words may be used as system-names.

System Names

System NamesSystem Names

Reserved Words

Reserved words are those words reserved for use by the RM/COBOL compiler. A reserved word must not appear as a user-defined word within a program. Appendix A, Reserved Words, contains a complete list of reserved words.
Five kinds of reserved words are recognized by the compiler:

  1. Keywords. Keywords are required elements of the formats.Their presence indicates specific compiler action.
  2. Optional Words. Optional words are optional elements of the formats. Their presence has no effect on the object program.
  3. Connectives.OF and IN are used interchangeably to connect qualifiers to a user-defined word. AND and OR are logical connectives, used in the formation of conditions.
  4. Special Registers. Special registers are compiler-generated storage areas. They are used to store information that is produced in conjunction with the use of specific features. The format and description of the eight special registers are described below.
  5. Note: The special registers may be referenced only in Procedure Division statements with the exception of the PROGRAM-ID special register.

    Reserved Words

    The ADDRESS special register returns the address of identifier-1 as a pointer data item. It may only be used in certain contexts of the Procedure Division where a pointer is allowed, which are a relation condition with another pointer data item, a CALL statement USING phrase, or a Format 5 or 6 SET statement.The ADDRESS special register is not allowed in the GIVING phrase of a CALL statement even though a pointer data item is allowed there. When specified in the USING phrase of a CALL statement,the ADDRESS special register is always passed by content. When identifier-1 is a Linkage Section data item for which the base address has not been set by being associated with an actual argument in a calling program or by execution of a SET statement, the ADDRESS special register will return a null pointer value. If identifier-1 were referenced in such a case without the ADDRESS special register, the run unit would terminate with a data reference error. Thus, the ADDRESS special register may be used in an IF statement to prevent a data reference termination of the run unit by avoiding the reference when the ADDRESS OF identifier-1 is equal to NULL.

    count

    The COUNT special register exists for each COBOL table data item, that is, data-name-1 must refer to a data item described with the OCCURS clause. For a fixed occurrence table, COUNT returns the fixed number of occurrences specified in the OCCURS clause. For a variable occurrence table, COUNT returns the value of the data-name specified by the DEPENDING ON phrase of the OCCURS clause. It may be used wherever an integer literal may be used in the Procedure Division.

    count max

    The COUNT-MAX special register exists for each COBOL table data item, that is, data-name-1 must refer to a data item described with the OCCURS clause. COUNT-MAX always returns the maximum number of occurrences specified in the OCCURS clause. For a fixed occurrence table, COUNT, COUNT-MAX, and COUNT-MIN will return the same value. It may be used wherever an integer literal may be used in the Procedure Division.

    count min

    The COUNT-MIN special register exists for each COBOL table data item, that is, data-name-1 must refer to a data item described with the OCCURS clause. COUNT-MIN always returns the minimum number of occurrences specified in the OCCURS clause. For a fixed occurrence table, COUNT, COUNT-MAX, and COUNT-MIN will return the same value. It may be used wherever an integer literal may be used in the Procedure Division.

    length

    The LENGTH special register exists for any data item or literal. It returns the length of the data item referenced by identifier-1 or value referenced by literal-1. It may be used wherever an integer literal may be used in the Procedure Division. For a variable length group, the LENGTH special register returns the current length of the group. For a reference modified identifier, the LENGTH special register returns the length of the result of the reference modification, that is, the result of the evaluation of the length modifier if it was specified or the remaining length of the data item after the offset has been applied if the length modifier is not specified. For a literal, the LENGTH special register returns the number of characters in the literal. If the literal is a numeric literal, the number of characters is the same as the number of digits.That is,for a numeric literal, the sign and decimal point characters, if specified, are not counted in the length of the literal.

    linage counter

    The LINAGE-COUNTER special register is a line counter,generated by the presence of a LINAGE clause in a file description entry.

    PROGRAM-ID

    The PROGRAM-ID special register exists for any program. It returns the program-name of the program in which it is used. It may be used wherever a nonnumeric literal may be used in the program, except for the END PROGRAM header. The PROGRAM-ID special register is an exception to the rule that special registers may be referenced only in Procedure Division statements. The PROGRAM-ID special register may be specified in VALUE clauses of data description entries for nonnumeric data items or constant-name definitions. If the program-name is specified as a nonnumeric literal in the PROGRAM-ID paragraph, the value of the PROGRAM-ID special register will match that nonnumeric literal,including its case; otherwise, the value of the PROGRAM-ID special register will be in uppercase.

    RETURN-CODE

    The RETURN-CODE special register has the implicit description PICTURE S9999 COMP-4, and can be set by the user to pass a return code to the calling program or the operating system before executing a STOP RUN, EXIT PROGRAM or GOBACK statement. When control is returned to a calling program, the return code passed by the called program is available to the calling program in the RETURN-CODE special register;the return code value can be tested by specifying RETURN-CODE in a relation condition.When control is returned to the operating system, the return code may be available to the command language in a system dependent manner;see the RM/COBOL User’s Guide for specific information. The return code is initialized to zero at the start of a run unit. This is the normal return code for successful completion;other values returned are conventionally in multiples of four. Some return code values, generally the higher values,are reserved for runtime-detected errors;see the appropriate chapters on installation and system considerations in the RM/COBOL User’s Guide.
    The return code is implicitly set to the value specified in statements having the following form:

    stop run

    This statement is equivalent to the statement sequence:

    move

  6. Special Characters. The special character reserved words are the arithmetic operators (including the unary operators + and –),relational operators,and concatenation operator:
  7. Special Characters

Context-Sensitive Words

The words listed in Table A-1 on page A-7 are context-sensitive words and are reserved in the specified language construct or context.If a context-sensitive word is used where the context-sensitive word is permitted in the general format,the word is treated as a keyword;otherwise,it is treated as a user-defined word.

Literals

A literal is a character-string whose representation is identical to its value.Literals are either numeric or nonnumeric.

Numeric Literals

A numeric literal represents a numeric value,not a character-string.Numeric literals are built according to the following rules:

  1. The literal must contain at least 1 but not more than 30 digits.
  2. The literal may contain a single + or – as the first character.
  3. The literal may contain a single decimal point if the decimal point is not the last character. The decimal point must be represented with a comma if the DECIMAL-POINT IS COMMA clause is specified in the SPECIAL-NAMES paragraph.

The word integer, when used in the syntax charts in this manual, designates an unsigned,numeric literal without a decimal point. Its value cannot be zero unless specifically allowed within a particular context.

Here are some examples:

1234
+1234
–1.234
.1234
+.1234

Nonnumeric Literals

A nonnumeric literal is a character-string enclosed in quotation marks. The character-string may contain any character from the character set of the computer. Quotation marks within the string are represented by two contiguous quotation marks. Either the quotation mark or the apostrophe may be used as the delimiter, but within one literal, the first quotation mark establishes the delimiter character for that literal. The value of the literal is the string itself excluding the delimiting character and one of each contiguous pair of embedded quotation marks. The literal may contain from 1 to 65535 characters.

Hexadecimal literals of the form:

Nonnumeric Literals

are also permitted as another form of nonnumeric literal, where h is any valid hexadecimal digit. Two hexadecimal digits occupy one character position. If an odd number of hexadecimal digits is specified, the compiler assumes an additional hexadecimal zero digit on the right to complete the rightmost character position.

Table lists some nonnumeric literals and their associated values.

All nonnumeric literals are of category alphanumeric.

Non numeric Literals and Their Values

Non numeric Literals and Their Values

Figurative Constants

Figurative constants identify commonly used constant values. These constant values are generated by the compiler according to the context in which the references occur. Note that figurative constants represent values, not literal occurrences. Thus, QUOTE cannot delimit a nonnumeric literal, SPACE is not a separator, and so forth. Singular and pluralforms of figurative constants may be used interchangeably.

The following constant represents the value 0 or one or more zero characters, depending on context.

[ALL] ZERO,[ALL] ZEROS,[ALL] ZEROES

The following constant represents one or more space characters.

[ALL] SPACE, [ALL] SPACES

Except in the SPECIAL-NAMES paragraph, the following constant represents one or more occurrences of the character that has the highest ordinal position in the program collating sequence.The native HIGH-VALUE is FFh.

[ALL] HIGH-VALUE, [ALL] HIGH-VALUES

Except in the SPECIAL-NAMES paragraph, the following constant represents one or more occurrences of the character that has the lowest ordinal position in the program collating sequence. The native LOW-VALUE is 00h.

[ALL] LOW-VALUE, [ALL] LOW-VALUES

The following constant represents one or more quotation marks.

[ALL] QUOTE, [ALL] QUOTES

The following constant represents one or more null or unset pointer values. The usage of this constant is POINTER. Thus, this constant may only be used in places where pointer literal is allowed,which are in the VALUE clause in the data description entry of a usage POINTER data item,in relation conditions involving another pointer data item, in the USING phrase of the CALL statement, and in Format 5 of the SET statement.

[ALL] NULL, [ALL] NULLS

The following constant represents all or part of the string generated by successive concatenations of the characters comprising literal-1. literal-1 must be a nonnumeric literal and may be a concatenation expression.literal-1 must not be a figurative constant.

ALL literal-1

The following constant represents one or more of the character specified as the value of symbolic-character-1 in the SYMBOLIC CHARACTERS clause of the SPECIAL-NAMES paragraph.

[ALL ] symbolic-character-1

When a figurative constant represents a string of one or more characters,the length of the string is determined by the compiler from context according to the following rules:

  1. When a figurative constant is associated with another data item,as when the figurative constant is moved to or compared with another data item, the string of characters specified by the figurative constant is repeated character-by-character on the right until the size of the resultant string is equal to the size in characters of the associated data item. This is done prior to and independent of the application of any JUSTIFIED clause that may be associated with the data item. When the figurative constant is specified in a concatenation expression, its length is determined as if the figurative constant were not associated with any other data item per rules 2 and 3 below, regardless of the context in which the concatenation expression is specified.
  2. When a figurative constant, other than ALL literal, is not associated with another data item, as when the figurative constant appears in a DISPLAY, STOP, STRING, or UNSTRING statement, the length of the string is one character.
  3. When the figurative constant ALL literal is not associated with another data item, the length of the string is the length of the literal.

A figurative constant may be used wherever literal appears in syntax,with the following exceptions:

  • If the literal is restricted to a numeric literal,the only figurative constant permitted is ZERO(ZEROS, ZEROES).
  • When a figurative constant other than ALL literal is used, the word ALL is redundant and is used for readability only.
  • If the literal is restricted to a pointer literal, the only figurative constant permitted is NULL (NULLS). NULL (NULLS) may only be used in VALUE clauses associated with a pointer data item, in relation conditions involving another pointer item,in the USING phrase of the CALL statement, in the REPLACING phrase of the INITIALIZE statement,and in Format 5 of the SET statement.

Each reserved word which refers to a figurative constant value is a distinct character-string with the exception of constructs using the word ALL, such as ALL literal, ALL SPACES, and so forth, which are composed of two distinct characterstrings.

Concatenation Expressions

A concatenation expression consists of two nonnumeric literals separated by the concatenation operator &:

literal-1 & literal-2

Both literal-1 and literal-2 must be nonnumeric literals, but either may be specified with a hexadecimal literal, a figurative constant (including a symbolic-character), or a constant-name that refers to a nonnumeric value. When a figurative constant is specified in a concatenation expression, its length is determined by the rules for a figurative constant that is not associated with another data item regardless of the context in which the concatenation expression is used.

The value of a concatenation expression is the concatenation of the value of literal-1 and literal-2.

A concatenation expression may be used anywhere a nonnumeric literal may be used unless otherwise prohibited by specific rules of a given format. literal-1 of a concatenation expression may be a concatenation expression, but, for formal reasons having to do with termination of the syntax production, literal-2 cannot be a concatenation expression. However, any number of nonnumeric literals may be concatenated by repeated application of literal-1 being a concatenation expression.

PICTURE Character-Strings

A PICTURE character-string consists of certain combinations of characters used as symbols. Any punctuation character appearing as part of a PICTURE character-string is considered a symbol, not a punctuation character. If the punctuation character comma, period, or semicolon is followed by a space, it is a separator that delimits the PICTURE character-string and is not part of the PICTURE character-string.

Comment-Entry

A comment-entry is an entry in the Identification Division that may contain any characters from the character set of the computer. It terminates at the next nonblank area A.



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics