[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
This example produces the following results:
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 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.
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. |
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 |
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:
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.
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:
The next two sections describe these conventions.
Previous | Next | Contents | Index |