Compaq COBOL AAQ2G1FTK User Manual

Page 171

Advertising
background image

Using the STRING, UNSTRING, and INSPECT Statements

5.3 Examining and Replacing Characters Using the INSPECT Statement

An identifier must be an elementary item of DISPLAY usage. It can be any
data class. However, if it is not alphanumeric, the compiler performs an
implicit redefinition of the item. This redefinition is identical to the
BEFORE/AFTER delimiter redefinition discussed in Section 5.3.2.

The words ALL and LEADING supply conditions that further delimit the
inspection operation:

ALL specifies that every match that the search argument finds in the
delimited character string be counted in the tally counter. When a literal
follows the word ALL, it does not have the same meaning as the figurative
constant, ALL literal. The ALL literal meaning of ALL ‘‘,’’ is a string of
consecutive commas (as many as the context of the statement requires). ALL
‘‘,’’ used as a tally argument means ‘‘count each comma without regard to
adjacent characters.’’

LEADING specifies that only adjacent matches of the TALLY argument
at the leftmost position of the delimited character string be counted. At
the first failure to match the tally argument, the compiler terminates
counting and causes the argument to become inactive. The sample statement
INSPECT...TALLYING (scanning FIELD1, tallying in TLY, and looking for
the arguments and delimiters listed in the left column) gives the results in
Table 5–12 (if the program initializes TLY to 0).

Table 5–12 LEADING Delimiter of the Inspection Operation

Argument and Delimiter

FIELD1 Value

Contents of TLY After Scan

F***0**F

2

F**0F**

0

LEADING ‘‘*’’ AFTER ‘‘0’’.

F**F**0

0

0***F**

3

F**0**F***

1

F**F0***FF

1

LEADING ‘‘**’’ AFTER ‘‘0’’.

F**F0****F**

2

F**F**0*

0

5.3.5.3 The Tally Argument List

One INSPECT...TALLYING statement can contain more than one tally argument,
and each argument can have a separate BEFORE/AFTER phrase and tally
counter associated with it. These tally arguments with their associated tally
counters and BEFORE/AFTER phrases form an argument list. The manner in
which this list is processed affects the action of any given tally argument.

The following examples show INSPECT statements with argument lists. The text
with each example explains how that list is processed.

INSPECT FIELD1 TALLYING T FOR

ALL ","
ALL "."
ALL ";".

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

Advertising