COBOL Manual for TNS and TNS/R Programs

Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs522555-006
9-276
UNSTRING
Execution of the UNSTRING Statement
The execution of the UNSTRING statement consists of these three phases:
1. Initialization phase
In the initialization phase, the UNSTRING statement performs these
initialization operations before beginning to cycle through the list of INTO
phrases:
It establishes the source item as the sending area. Even if the item has a
variable size (is defined with the OCCURS DEPENDING clause), the initial
size is used as the sending area size for the duration of statement
execution.
If the UNSTRING statement includes the POINTER phrase, the
initialization establishes the pointer item as the pointer variable. The
initial value of this item determines the relative character position within the
sending area at which the unstring operation begins. The first character
position is 1.
This enables you to start the unstring operation at some character other
than the first character in the source item, and to retain a record of where
the unstring operation terminated. (A later UNSTRING statement could
then begin its operation at the point where another one left off.)
If the initial value of the pointer item is less than one or greater than the
size of the source item, then the overflow condition exists immediately
and no unstring operation occurs.
If the UNSTRING statement does not include the POINTER phrase, the
unstring operation begins at the first character position in the sending area.
If the UNSTRING statement includes a TALLYING phrase, the initialization
establishes tally as the tallying variable.
Initialization establishes the first result item as the current receiving
area.
2. UNSTRING cycle phase
In the UNSTRING cycle phase, the unstring operation consists of one or more
cycles. Each cycle examines characters in the “sending area” one by one. The
sending area is the portion of the source item beginning at the current
character position and ending at the last character of the source item. Each
cycle assigns an appropriate string of characters to the current result.
The identification of the item to be copied depends on the presence or
absence of the DELIMITED phrase, and on when the unstring operation
reaches the end of the source item.