COBOL/400 Language Help


Reference Modification

Reference modification resembles substringing in other computer languages. Reference modification defines a data item by specifying a starting position and length for the item. It is generally allowed anywhere an identifier referencing an alphanumeric data item is allowed.

                 *------------------*
                 V                  +
->->--data-name-1--*------------------*---------------------->
                 *-OF-*-data-name-2-*
                 *-IN-*
 
->---(leftmost-character-position:-*--------*-)-------------><-
                                  *-length-*
 

Without reference modification, you cannot use operands that are longer than 32 767 bytes in the following statements:

ACCEPT
CANCEL
DISPLAY
EVALUATE (relational condition)
IF (relational condition)
PERFORM (relational condition)
STRING
UNSTRING
USE (USE FOR DEBUGGING)
Note:
When you use IF condition-name, an implicit comparison of the condition-name (88-level item) with its condition variable takes place, even though the condition variable is not referenced in the IF statement. Therefore, IF condition-name cannot be used when the associated condition variable is longer than 32 767 bytes.

With reference modification, this 32 767-byte limit does not apply if the length of the operand is known at compilation time. In other words, the reference modification length specification (or starting position in the absence of a length specification) must be a numeric literal.

Evaluation of Operands

Reference modification for an operand is evaluated as follows:

Reference modification creates a unique data item which is a subset of the data item referenced by data-name-1. This unique data item is considered an elementary data item without the JUSTIFIED clause. It has the same class and category as that defined for the data item referenced by data-name-1, except that the categories numeric, numeric-edited, and alphanumeric-edited are considered class and category alphanumeric.

For example:

MOVE whole-name(1:25) TO last-name
 

This example transfers the first 25 characters in the variable whole-name to the variable last-name.

Range Errors

An out-of-range reference modification component, such as a leftmost-character-position of zero, causes system message MCH0603. This is the same message that signals errors in subscript ranges and character-string boundaries.

Restrictions on Reference Modification

The INDICATORS phrase does not support reference modification, and the same is generally true of record-names.

The following statements do not support reference modification:

INSPECT
Extended ACCEPT
Extended DISPLAY

In addition, you cannot reference modify:

For the START statement, you can reference modify the last occurrence of data-name-1 only.


[ Top of Page | Previous Page | Next Page | Table of Contents ]