Compaq COBOL AAQ2G1FTK User Manual
Page 172
Using the STRING, UNSTRING, and INSPECT Statements
5.3 Examining and Replacing Characters Using the INSPECT Statement
These three tally arguments have the same tally counter, T, and are active over
the entire item being inspected. Thus, the preceding statement adds the total
number of commas, periods, and semicolons in FIELD1 to the initial value of
T. Because the TALLYING phrase supports multiple arguments and only one
counter is used, the previous statement could have been written as follows:
INSPECT FIELD1 TALLYING T FOR ALL "," "." ";".
INSPECT FIELD1 TALLYING
T1 FOR ALL ","
T2 FOR ALL "."
T3 FOR ALL ";".
Each tally argument in this statement has its own tally counter and is active
over the entire item being inspected. Thus, the preceding statement adds the
total number of commas in FIELD1 to the initial value of T1, the total number of
periods to the initial value of T2, and the number of semicolons to T3.
INSPECT FIELD1 TALLYING
T1 FOR ALL "," AFTER "A"
T2 FOR ALL "." BEFORE "B"
T3 FOR ALL ";".
Each tally argument in the preceding statement has its own tally counter; the
first two arguments have delimiter phrases, and the last one is active over the
entire item being inspected. Thus, the first argument is initially inactive and
becomes active only after the scanner encounters an A; the second argument
begins the scan in the active state but becomes inactive after a B has been
encountered; and the third argument is active during the entire scan of FIELD1.
Table 5–13 shows various values of FIELD1 and the contents of the three tally
counters after the scan of the previous statements. Assume that the counters are
initialized to 0 before the INSPECT statement.
Table 5–13 Results of the Scan with Separate Tallies
Contents of Tally Counters After Scan
FIELD1
Value
T1
T2
T3
A.C;D.E,F
1
2
1
A.B.C.D
0
1
0
A,B,C,D
3
0
0
A;B;C;D
0
0
3
*,B,C,D
0
0
0
The BEFORE/AFTER phrase applies only to the argument that precedes it and
delimits the item for that argument only. Each BEFORE/AFTER phrase causes a
separate scan of the item to determine the limits of the item for its corresponding
argument.
5–26 Using the STRING, UNSTRING, and INSPECT Statements