COBOL Manual for TNS/E Programs (H06.03+)

Procedure Division Verbs
HP COBOL Manual for TNS/E Programs520347-003
9-262
UNSTRING
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.
If the statement includes the DELIMITED phrase, the examination proceeds
left to right until it encounters either a delimiter string or the end of the sending
area. A delimiter string is a contiguous set of characters, beginning with the
character under examination, whose value exactly matches the value of any of
the constants or data items specified in the DELIMITED phrase.
If your program has these data items:
05 U PIC X(32) VALUE "The UNSTRING statement is handy."
* ....'....'....'....'....'....'..
* 5 10 15 20 25 30
01 WORD-LIST.
03 WORD-1 PIC X(8).
03 WORD-2 PIC X(10).
03 WORD-3 PIC X(7).
03 WORD-4 PIC X(3).
03 WORD-5 PIC X(8).
03 WORD-6 PIC X(9).
And if you execute
UNSTRING U DELIMITED BY SPACE
INTO WORD-1 WORD-2 WORD-3
WORD-4 WORD-5 WORD-6