Reference Modification [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
Reference Modification
Reference modification is a feature of the 1985 ANSI COBOL standard.
Reference modification is a method of referencing data by specifying a
leftmost character and length for the data item.
Syntax
[REV BEG]
The format of a reference modifier is:
(leftmost-character-position: [length])
[REV END]
You use a reference modifier with a data item or a function identifier.
The general format for reference modification is:
data-name-1 (leftmost-character-position: [length])
[REV BEG]
The format for reference modification with COBOL functions is:
FUNCTION function-name-1 [({parameter-1} ... )] (leftmost-character-position: [length])[REV END]
Parameters
data-name-1 must reference a data item whose usage is
DISPLAY. data-name-1 can be qualified or
subscripted.
leftmost-character- must be an arithmetic expression.
position
length must be an arithmetic expression.[REV BEG]
function-name-1 must be an alphanumeric COBOL function. For a
list of COBOL functions, see Chapter 10 ,
"COBOL Functions."
parameter-1 is any parameter to the function
function-name-1.[REV END]
Reference modification is allowed wherever an identifier referencing an
alphanumeric data item[REV BEG] or alphanumeric function[REV END] is
permitted, except in identifier-3 of the STRING statement and
identifier-1 of the UNSTRING statement.
Reference Modification Rules
The following rules apply when using reference modification:
* Each character of a data item referenced by data-name-1[REV BEG]
or by function-name-1 and its parameters, if any,[REV END] is
assigned an ordinal number according to its position. The
leftmost position is assigned the number one and the number of
each successive position to the right is incremented by one. If
the data description entry for data-name-1 contains a SIGN IS
SEPARATE clause, the sign position is assigned an ordinal number
within that data item.
* If data-name-1[REV BEG] or function-name-1[REV END] is numeric,
numeric-edited, alphabetic, or alphanumeric-edited, reference
modification operates upon the item as if it were redefined as an
alphanumeric data item of the same size.
* For an operand, reference modification is evaluated as follows:
* If you specify subscripting for an operand, the reference
modification is evaluated immediately after the
subscripts.[REV BEG]
If you specify an ALL subscript for an operand, the
reference-modifier is applied to each element of the table.
(Using ALL as a subscript is only allowed when the operand
is a parameter to a function.)[REV END]
* If subscripting is not specified for the operand, the
reference modification is evaluated at the time
subscripting would be evaluated if subscripts had been
specified.
[REV BEG]
* If you specify reference modification for a function
reference, the reference modification is done immediately
after the function is evaluated.[REV END]
* Reference modification creates a unique data item that is a subset
of the data item referenced by[REV BEG] data-name-1 or
function-name-1 and its arguments, if any.[REV END]
This unique data item is defined as follows:
* The leftmost-character-position specifies the ordinal
position of the leftmost character of the unique data item
in relation to the leftmost character of[REV BEG]
data-name-1 or function-name-1.[REV END] Evaluation of the
leftmost-character-position must result in a positive
nonzero integer less than or equal to the number of
characters in the data item.
* The length specifies the size of the data item to be used
in the operation. The result must be a positive nonzero
integer. The sum of leftmost-character-position and length
minus 1 must be less than or equal to the number of
characters in the data item[REV BEG] data-name-1 or
function-name-1.[REV END]
* If length is not specified, the unique data item extends
from the leftmost-character-position through the rightmost
character of the data item.
* The unique data item is considered an elementary data item without
the JUSTIFIED clause.[REV BEG] When a function is referenced, it
has the class and category of alphanumeric. When data-name-1 is
specified, the unique data item[REV END] has the same class and
category as data-name-1 except that the categories numeric,
numeric-edited, and alphanumeric-edited are considered class and
category alphanumeric.
Examples
Based upon the following example, Table 4-3 shows the result of
reference modification upon four statements:
01 TAB.
05 ELEMENT PIC X(5)
OCCURS 5 TIMES VALUE "12345".
01 X PIC X(3).
Table 4-3. Reference Modification Results
---------------------------------------------------------------------------
| | |
| Statement | Result |
| | |
---------------------------------------------------------------------------
| | |
| MOVE "ABC" TO ELEMENT (3) (2:) | Changes the third element of |
| | ELEMENT table to 1ABC_. |
| | |
---------------------------------------------------------------------------
| | |
| MOVE "ABC" TO ELEMENT (2) (4:) | Changes the second element of |
| | ELEMENT table to 123AB. |
| | |
---------------------------------------------------------------------------
| | |
| MOVE "ABC" TO ELEMENT (1) (1:4) | Changes the first element to |
| | ABC_5. |
| | |
---------------------------------------------------------------------------
| | |
| MOVE ELEMENT (5) (2:2) TO X. | Changes X to 23_. |
| | |
---------------------------------------------------------------------------
Based on the following example, Table 4-4 shows the result of
reference modification without subscripting upon three statements:
01 Y PIC XXXX VALUE SPACES.
Table 4-4. Reference Modification Without Subscripting
---------------------------------------------------------------------------------------------
| | |
| Statement | Result |
| | |
---------------------------------------------------------------------------------------------
| | |
| MOVE "AB" TO Y(2:) | _AB_ |
| | |
---------------------------------------------------------------------------------------------
| | |
| MOVE "XYZ" TO Y(2:) | _XYZ |
| | |
---------------------------------------------------------------------------------------------
| | |
| MOVE "F" TO Y(2:1) | _FYZ |
| | |
---------------------------------------------------------------------------------------------
[REV BEG]
The following program shows reference modification on function calls:
10 $CONTROL POST85
11 IDENTIFICATION DIVISION.
12 PROGRAM-ID. FUNC-EXAMPLE.
13 ENVIRONMENT DIVISION.
14 DATA DIVISION.
15 WORKING-STORAGE SECTION.
16 01 TAB.
17 05 ELEMENT PIC X(5) USAGE DISPLAY
18 OCCURS 5 TIMES VALUE "12345".
19 PROCEDURE DIVISION.
20 FIRST-PARA.
21 DISPLAY FUNCTION WHEN-COMPILED
22 DISPLAY FUNCTION WHEN-COMPILED (9:2)
23 DISPLAY FUNCTION CURRENT-DATE
24 DISPLAY FUNCTION CURRENT-DATE (1:4)
25 MOVE "93843" TO ELEMENT (2)
26 MOVE "38103" TO ELEMENT (3)
27 MOVE "49382" TO ELEMENT (4)
28 MOVE "78397" TO ELEMENT (5)
29 DISPLAY FUNCTION MAX ( ELEMENT (ALL) )
30 DISPLAY FUNCTION MAX ( ELEMENT (ALL) ) (2:2)
31 STOP RUN.
The above program displays the following kind of output:
1991011612272700-0500 Output from WHEN-COMPILED, line 21.
12 Output from reference-modified WHEN-COMPILED, line 22.
1991011612283000-0500 Output from CURRENT-DATE, line 23.
1991 Output from reference-modified CURRENT-DATE, line 24.
93843 Output from MAX, line 29.
38 Output from reference-modified MAX, line 30.
[REV END]
MPE/iX 5.0 Documentation