Compaq COBOL AAQ2G1FTK User Manual

Page 155

Advertising
background image

Using the STRING, UNSTRING, and INSPECT Statements

5.2 Separating Data Using the UNSTRING Statement

Table 5–4 Results of Delimiting with an Asterisk

FIELD1
PIC X(6)
VALUE IS:

FIELD2
PICTURE IS:

FIELD2
Value After
UNSTRING

XXX

ABC

ABCDEF

X(7)

ABCDEF

XXX JUSTIFIED

DEF

******

XXX

###

*ABCDE

XXX

###

A*****

XXX JUSTIFIED

##A

246***

S9999

024F

12345*

S9999 TRAILING SEPARATE

2345+

2468**

S999V9 LEADING SEPARATE

+4680

*246**

9999

0000

Legend: # = space

If the delimiter matches the first character in the sending item, the compiler
considers the size of the sending item to be zero. The operation still takes place,
however, and fills the receiving item with spaces (if it is nonnumeric) or zeros (if
it is numeric).

A delimiter can also be applied to an UNSTRING statement that has multiple
receiving items:

UNSTRING FIELD1 DELIMITED BY SPACE

INTO FIELD2A FIELD2B.

The compiler generates code that scans FIELD1 searching for a character that
matches the delimiter. If it finds a match, it moves the scanned characters
to FIELD2A and sets the scanner to the next character position to the right
of the character that matched. The compiler then resumes scanning FIELD1
for a character that matches the delimiter. If it finds a match, it moves all of
the characters between the character that first matched the delimiter and the
character that matched on the second scan, and sets the scanner to the next
character position to the right of the character that matched.

The DELIMITED BY phrase handles additional items in the same manner as it
handled FIELD2B.

Table 5–5 illustrates the results of the following delimited UNSTRING operation
into multiple receiving items:

UNSTRING FIELD1 DELIMITED BY "*"

INTO FIELD2A FIELD2B.

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

Advertising