Compaq COBOL AAQ2G1FTK User Manual

Page 169

Advertising
background image

Using the STRING, UNSTRING, and INSPECT Statements

5.3 Examining and Replacing Characters Using the INSPECT Statement

Table 5–11 Relationship Among INSPECT Argument, Delimiter, Item Value, and

Argument Active Position

Argument and
Delimiter

FIELD1
Value

Argument
Active at
Position

Contents of
TLY After Scan

ALL

BXBXXXXBB

6

2

‘‘B’’ AFTER ‘‘XX’’

XXXXXXXX

3

0

BXBXBBBBXX

never

0

BXBXXBXXB

6

2

‘‘X’’ AFTER ‘‘XX’’

XXXXXXXX

3

6

BBBBBBXX

never

0

BXYBXBXX

7

0

‘‘B’’ AFTER ‘‘XB’’

XBXBXBXB

3

3

BBBBBBXB

never

0

XXXXBXXXX

6

0

‘‘BX’’ AFTER ‘‘XB’’

XXXXBBXXX

6

1

XXBXXXXBX

4

1

When an argument has an associated BEFORE delimiter, the inactive/active
states reverse roles: the argument is in an active state when the scanning
begins and becomes inactive at the character position that matches the delimiter.
Regardless of the presence of the BEFORE delimiter, an argument becomes
inactive when the scanner approaches the rightmost position of the item and the
remaining characters are fewer in number than the characters in the argument.
In such a case, the argument cannot possibly find a match in the item, so it
becomes inactive.

Because the BEFORE/AFTER delimiters are found on a separate scan of the item,
the compiler generates code that recognizes and sets up the delimiter boundaries
before it scans for an argument match; therefore, the same characters can be used
as arguments and delimiters in the same phrase.

5.3.4.3 Finding an Argument Match

The compiler generates code that selects arguments from the argument list
in the order in which they appear in the list. If the first one it selects is an
active argument, and the conditions stated in the INSPECT statement allow a
comparison, the compiler generates code that compares it to the character at the
scanner’s position. If the active argument does not find a match, the compiler
generates code that takes the next active argument from the list and compares
that to the same character. If none of the active arguments finds a match, the
scanner moves one position to the right and begins the inspection operation again
with the first active argument in the list. The inspection operation terminates at
the rightmost position of the item.

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

Advertising