COBOL Manual for TNS and TNS/R Programs

Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs522555-006
9-277
UNSTRING
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
the first item to be copied is “The” and the second is “UNSTRING” and so on.
If you specify two or more delimiters, the unstring operation compares their
values with the sending area in the same order as they appear in the phrase. If
a match occurs, the corresponding set of characters in the sending area forms
the delimiter string; any delimiters not yet tested are ignored. If no delimiter
value matches the sending area at the current position, the unstring operation
repeats the delimiter search beginning with the next character of the sending
area. No character in the sending area can be considered a part of more than
one delimiter.
If you execute
UNSTRING U DELIMITED BY SPACE OR "I"
INTO WORD-1 WORD-2 WORD-3
WORD-4 WORD-5 WORD-6
the first item to be copied is “The,” the second item is “UNSTR,” the third is
“NG,” and so on.
Two special cases are consecutive delimiters and multicharacter delimiters.
If ALL was not specified and the unstring operation encounters two
consecutive delimiters, it interprets the sending item as zero if result is
numeric. If result is not numeric, the unstring operation interprets the
sending item as spaces.