[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

This example produces the following results:

  1. : STUVWX
  2. : S
  3. : A

6.2.3 Reference Modification

Reference modification defines a subset of a data item by specifying its leftmost character and length.


data-name must refer to a data item whose usage is DISPLAY.

function-name must refer to an alphanumeric function.

The specifications for leftmost-character-position and length must be arithmetic expressions.

Each character of a data item has an ordinal number corresponding to its position. The leftmost position is number 1; successive positions to the right are numbered 2, 3, 4, and so on. If the data-name's data description entry has a SIGN IS SEPARATE clause, the sign position is assigned an ordinal number in the data item.

For a data item defined as numeric, numeric edited, alphanumeric, alphabetic, or alphanumeric edited, reference modification operates as if the data item were redefined as an alphanumeric data item the same size as that referred to by data-name.

Unless otherwise specified by the rules for a statement, reference modification is evaluated only once, at the beginning of a statement. Reference modification is evaluated immediately after subscripting or indexing evaluation. Rules that describe the evaluation of subscripting for the various statements also apply to the evaluation of reference modification.

The components of reference modification define the data item as follows:

  • The evaluation of leftmost-character-position specifies the ordinal position of the data item's leftmost character. This position is relative to the leftmost character of the data item referred to by data-name. Evaluation of leftmost-character-position must result in an integer that is not less than 1, or greater than the number of characters in the data item referred to by data-name.
  • The evaluation of length specifies the size of the unique data item. The evaluation must result in a positive integer. The sum of leftmost-character-position and length minus the value 1 must not exceed the number of characters in the data item referred to by data-name.
  • If there is no length, the data item extends:
    • From and including the character identified by leftmost-character-position of the data item referred to by data-name
    • To and including the rightmost character of the data item referred to by data-name

The resulting unique data item is treated as an elementary item without the JUSTIFIED clause. It has the same class and category as the data item referred to by data-name. However, the categories numeric, numeric edited, and alphanumeric edited are considered category alphanumeric.

Reference modification is valid anywhere an alphanumeric identifier is allowed unless specific rules for a general format prohibit it.

Note

Use the check compiler option with the bounds keyword for run-time upper- and lower-bound reference modification range verification. The default is not to check. For more information, refer to the COBOL online help file for your particular platform.

Examples


WORKING-STORAGE SECTION.
01  ITEMA PIC X(15) VALUE IS "ABCDEFGHIJKLMNO".
01  ITEMB PIC 99 VALUE IS 10.
IDENTIFIER VALUE
ITEMA (2:3) BCD
ITEMA (ITEMB:2) JK
ITEMA (ITEMB / 2:ITEMB - 6) EFGH
ITEMA (ITEMB:) JKLMNO

6.2.4 Identifiers

In Procedure Division rules, the term identifier means the complete specification of a data item. The term refers to all words required to make your reference to the item unique.

To reference a data item that is a function, a function-identifier is used. For information on functions, see Chapter 7.

The general formats for identifiers are as follows:


For more information on the methods of uniquely specifying data items, see the following:

6.2.5 Ensuring Unique Condition-Names

If the name you use as a condition-name appears in more than one place in your program, it can be made unique through qualification, indexing, or subscripting. Your condition-name also is unique when the scope of names conventions by themselves ensure this as described in Section 6.2.6, Scope of Names.

The first qualifier for a condition-name can be the name of the item with which it is associated (the conditional variable). When qualifying condition-names, you must use the name of the conditional variable itself or the names of items that contain it.

References to a condition-name must have the same combination of subscripting or indexing that you use for the conditional variable.

The formats you use to ensure unique condition-names are the same as those used for an identifier, except condition-name replaces data-name.

In Procedure Division rules, the term condition-name refers to a condition-name along with any qualification and subscripting or indexing needed to avoid ambiguity.

6.2.6 Scope of Names

A contained COBOL program can refer to a user-defined word in its containing program if the user-defined word has the global attribute. (See Section 1.2.1.1 in Section 1.2.1.) Some user-defined words always have the global attribute, some never have the attribute (that is, they are local), and some might or might not, depending on the use of the GLOBAL clause. The following rules explain how to use different kinds of user-defined words and what kinds of local and global name scoping to expect.

  1. The following types of user-defined words are always local and can be referenced only by statements and entries in the program declaring them:
    • Paragraph-name
    • Section-name
  2. These user-defined words are always local when you define them in the Report Section. Only those statements and entries in the program containing the entries can reference them.
    • Condition-name
    • Data-name
    • Record-name
  3. The following user-defined word is always local when you define it in the Screen Section. Only those statements and entries in the program containing the entries can reference it.
    • Screen-name
  4. Because you cannot specify a Configuration Section for a program contained within another program, the following types of user-defined words are always global when declared in the Configuration Section. You can reference them only by statements and entries either in the program that contains the Configuration Section or in any program contained within that program.
    • Alphabet-name
    • Condition-name (declared in the Special Names paragraph)
    • Mnemonic-name
    • Symbolic-character-name
    • Switch-name
    • Class-name
  5. The following user-defined words are global if you specify the GLOBAL clause:
    • Condition-name (declared in the Data Division)
    • Data-name
    • File-name
    • Index-name
    • Record-name
    • Report-name
    • Segmented-key-name (if you specify the GLOBAL clause on the corresponding file-name)

Specific conventions for declarations and references apply to these types of user-defined words whenever the previous conditions do not apply.

Whenever duplicate names exist, a program always references the resource in its own program. If the resource is not in the referencing program, the following two conventions are used:

  • Conventions for resolving program-name references
  • Conventions for resolving other references

The next two sections describe these conventions.


Previous Next Contents Index