Using the STRING, UNSTRING, and INSPECT Statements
5.2 Separating Data Using the UNSTRING Statement
Table 5–5 Results of Delimiting Multiple Receiving Items
FIELD1
PIC X(8)
VALUE IS:
ABC*DEF*
ABCDE*FG
A*B****
*AB*CD**
**ABCDEF
A*BCDEFG
ABC**DEF
A******B
Legend: # = space
The previous examples illustrate the limitations of a single-character delimiter.
To overcome these limitations, a delimiter of more than one character or a
delimiter preceded by the word ALL may be used.
Table 5–6 shows the results of the following UNSTRING operation using a
2-character delimiter:
UNSTRING FIELD1 DELIMITED BY "**"
Table 5–6 Results of Delimiting with Two Asterisks
FIELD1
PIC X(8)
VALUE IS:
ABC**DEF
A*B*C*D*
AB***C*D
AB**C*D*
AB**CD**
AB***CD*
AB*****CD
Legend: # = space
Unlike the STRING statement, the UNSTRING statement accepts the ALL
literal as a delimiter. When the word ALL precedes the delimiter, the action of
the UNSTRING statement remains essentially the same as with one delimiter
until the scanning operation finds a match. At this point, the compiler scans
farther, looking for additional consecutive strings of characters that also match
5–10 Using the STRING, UNSTRING, and INSPECT Statements
FIELD2A
PIC X(3)
ABC
ABC
A##
###
###
A##
ABC
A##
INTO FIELD2A FIELD2B.
FIELD2A
PIC XXX
ABC
A*B
AB#
AB#
AB#
AB#
AB#
Values After UNSTRING Operation
FIELD2B
PIC X(3)
DEF
FG#
B##
AB#
###
BCD
###
###
Values After UNSTRING Operation
FIELD2B
PIC XXX
JUSTIFIED
DEF
###
C*D
*D*
#CD
CD*
###
Need help?
Do you have a question about the COBOL AAQ2G1FTK and is the answer not in the manual?