Compaq COBOL AAQ2G1FTK User Manual

Page 167

Advertising
background image

Using the STRING, UNSTRING, and INSPECT Statements

5.3 Examining and Replacing Characters Using the INSPECT Statement

Table 5–10 (Cont.) Values Resulting from Implicit Redefinition

Original
Value

Altered
Value

Restored Value

5 (65)

5 (65)

E (105)

6 (66)

6 (66)

F (106)

7 (67)

7 (67)

G (107)

8 (70)

8 (70)

H (110)

9 (71)

9 (71)

I (111)

All other
values

0 (60)

} (173)

5.3.4 Examining the INSPECT Operation

Regardless of the type of inspection (TALLYING or REPLACING), the INSPECT
statement has only one method for inspecting the characters in the item. This
section analyzes the INSPECT statement and describes this inspection method.

Figure 5–3 shows an example of the INSPECT statement. The item to be
inspected must be named (FIELD1 in our example), and the item name must be
followed by a TALLYING phrase (TALLYING TLY). The TALLY phrase must be
followed by one or more identifiers or literals ( B ). These identifiers or literals
comprise the arguments. More than one argument makes up the argument list.

Figure 5–3 Sample INSPECT Statement

ZK−6052−GE

"B"

FOR ALL

BEFORE "A"

Argument

Delimiter

phrase

TALLYING TLY

Operation

phrase

INSPECT FIELD1

Item being

inspected

Each argument in an argument list can have other items associated with it.
Thus, each argument that is used in a TALLYING operation must have a tally
counter (such as TLY in the example) associated with it. The tally counter is
incremented each time it matches the argument with a character or group of
characters in the item being inspected.

Each argument in an argument list used in a REPLACING operation must have
a replacement item associated with it. The compiler generates code that uses the
replacement item to replace each string of characters in the item that matches
the argument. Figure 5–4 shows a typical REPLACING phrase (with $ as the
replacement item).

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

Advertising