Friday, September 4, 2009

The UNSTRING Statement

The UNSTRING Statement
Syntax
Format
UNSTRING identifier-1 [ DELIMITED BY [ALL] { identifier-2
literal-1 } [ OR [ALL] { identifier-3
literal-2 }] ... ]
INTO {identifier-4 [DELIMITER IN identifier-5] [COUNT IN identifier-6]}...
[WITH POINTER identifier-7]
[TALLYING IN identifier-8]
[ON OVERFLOW imperative-statement-1]
[NOT ON OVERFLOW imperative-statement-2]
[END-UNSTRING]
Description
The UNSTRING statement is used to parse individual items from within a single string. Any number of items may be parsed. Entire or partial strings may be parsed. As many items as are provided as INTO operands will be parsed.
The POINTER clause can be used to start in a position other than 1. For example, if the POINTER variable has a value of 3, character 1 and 2 of the string will not be included, and the unstringing operation will proceed from the third character. As each character is inserted into a receiving field, the value of the POINTER variable will be incremented, so that the POINTER variable may be used to UNSTRING more values from where the previous UNSTRING operation left off.
The COUNT phrase can be used to determine the length of any parsed string.
Only as much of the values in the receiving field will be changed as is necessary to hold the newly parsed string, for example, in the statement
UNSTRING A DELIMITED BY SPACES INTO B C.
If A is a five character unstring with a value of "A A A" and B is a two character string with an original value of BB and C is a two character string with an original value of CC, after the UNSTRING statement is executed, B will have a value of AB and C will have a value of AC.
Tips
1. The operands should be non-numeric.
2. The POINTER and COUNT operands, if any, must be positive integers, that is their pictures should contain only 9's.
3. INITIALIZE the receiving items before the UNSTRING, to remove unwanted characters that may be left from a prior operation.
4. Use the OVERFLOW clause to detect field overflow on the receiving field(s).