Compaq COBOL AAQ2G1FTK User Manual

Page 156

Advertising
background image

Using the STRING, UNSTRING, and INSPECT Statements
5.2 Separating Data Using the UNSTRING Statement

Table 5–5 Results of Delimiting Multiple Receiving Items

Values After UNSTRING Operation

FIELD1
PIC X(8)
VALUE IS:

FIELD2A
PIC X(3)

FIELD2B
PIC X(3)

ABC*DEF*

ABC

DEF

ABCDE*FG

ABC

FG#

A*B****

A##

B##

*AB*CD**

###

AB#

**ABCDEF

###

###

A*BCDEFG

A##

BCD

ABC**DEF

ABC

###

A******B

A##

###

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 "**"

INTO FIELD2A FIELD2B.

Table 5–6 Results of Delimiting with Two Asterisks

Values After UNSTRING Operation

FIELD1
PIC X(8)
VALUE IS:

FIELD2A
PIC XXX

FIELD2B
PIC XXX
JUSTIFIED

ABC**DEF

ABC

DEF

A*B*C*D*

A*B

###

AB***C*D

AB#

C*D

AB**C*D*

AB#

*D*

AB**CD**

AB#

#CD

AB***CD*

AB#

CD*

AB*****CD

AB#

###

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

Advertising