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

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.
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 .
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
478 Procedure Division Verbs