Compaq COBOL AAQ2G1FTK User Manual

Page 157

Advertising
background image

Using the STRING, UNSTRING, and INSPECT Statements

5.2 Separating Data Using the UNSTRING Statement

the delimiter item. It considers the ALL delimiter to be one, two, three, or more
adjacent repetitions of the delimiter item. Table 5–7 shows the results of the
following UNSTRING operation using an ALL delimiter:

UNSTRING FIELD1 DELIMITED BY ALL "*"

INTO FIELD2A FIELD2B.

Table 5–7 Results of Delimiting with ALL Asterisks

Values After UNSTRING Operation

FIELD1
PIC X(8)
VALUE IS:

FIELD2A
PIC XXX

FIELD2B
PIC XXX
JUSTIFIED

ABC*DEF*

ABC

DEF

ABC**DEF

ABC

DEF

A******F

A##

##F

A*F*****

A##

##F

A*CDEFG

A##

EFG

Legend: # = space

Table 5–8 shows the results of the following UNSTRING operation that combines
ALL with a 2-character delimiter:

UNSTRING FIELD1 DELIMITED BY ALL "**"

INTO FIELD2A FIELD2B.

Table 5–8 Results of Delimiting with ALL Double Asterisks

Values After UNSTRING Operation

FIELD1
PIC X(8)
VALUE IS:

PIC XX

PIC XXX
JUSTIFIED

ABC**DEF

ABC

DEF

AB**DE**

AB#

#DE

A***D***

A##

#*D

A*******

A##

##*

Legend: # = space

In addition to unchangeable delimiters, such as literals and figurative constants,
delimiters can be designated by identifiers. Identifiers permit variable delimiting.
Consider the following sample statement:

UNSTRING FIELD1 DELIMITED BY DEL1

INTO FIELD2A FIELD2B.

The data name DEL1 must be alphanumeric; it can be either a group or an
elementary item. If the delimiter contains a subscript, the subscript may vary as
a side effect of the UNSTRING operation.

Using the STRING, UNSTRING, and INSPECT Statements 5–11

Advertising