When the STRING statement is executed, data is transferred from the sending
fields to the receiving field. The order in which sending fields are processed
is the order in which they are specified. The following rules apply:
- Characters from the sending fields are transferred to the receiving field,
according to the rules for alphanumeric to alphanumeric elementary moves,
except that no space filling is provided (see MOVE Statement).
- When DELIMITED BY identifier/literal is specified, the contents of each
sending item are transferred, character-by-character, beginning with the leftmost
character and continuing until either:
- A delimiter for this sending field is reached (the delimiter itself is
not transferred), or
- The rightmost character of this sending field has been transferred.
- When DELIMITED BY SIZE identifier is specified, each entire sending field
is transferred to the receiving field.
- When the receiving field is filled, or when all the sending fields have
been processed, the operation is ended.
- When the POINTER phrase is specified, an explicit pointer field is available
to the COBOL user to control placement of data in the receiving field. The
user must set the explicit pointer's initial value, which must not be less
than 1 and not more than the character count of the receiving field. (Note
that the pointer field must be defined as a field large enough to contain
a value equal to the length of the receiving field plus 1; this precludes
arithmetic overflow when the system updates the pointer at the end of the
transfer.)
- When the POINTER phrase is not specified, no pointer is available to the
user. However, a conceptual implicit pointer with an initial value of 1 is
used by the system.
- Conceptually, when the STRING statement is executed, the initial pointer
value (explicit or implicit) is the first character position within the receiving
field into which data is to be transferred. Beginning at that position, data
is then positioned, character-by-character, from left to right. After each
character is positioned, the explicit or implicit pointer is increased by
1. The value in the pointer field is changed only in this manner. At the
end of processing, the pointer value always indicates a value equal to one
character beyond the last character transferred into the receiving field.
Subscripting, reference modification, variable-length calculations, or
function evaluations are performed only once, at the beginning of the processing
of the STRING statement. So if identifier-3 or identifier-4 is used as a subscript,
reference modifier, or function argument in the STRING statement, or affects
the length or location of any identifiers of the STRING statement, these values
are determined at the beginning of the STRING statement, and are not affected by any results of the STRING statement.
If identifier-1 or identifier-2 occupy the same storage area as identifier-3
or identifier-4, or if identifier-3 and identifier-4 occupy the same storage
area, the result of the execution of the STRING statement is undefined.
After STRING statement execution is completed, only that part of the receiving
field into which data was transferred is changed. The rest of the receiving
field contains the data that was present before this execution of the STRING
statement.
When the following STRING statement is executed, the results obtained will
be like those illustrated in
Figure 1.
STRING ID-1 ID-2 DELIMITED BY ID-3
ID-4 ID-5 DELIMITED BY SIZE
INTO ID-7 WITH POINTER ID-8
END-STRING
Figure 1. Results of STRING Statement Execution