Using the STRING, UNSTRING, and INSPECT Statements
5.3 Examining and Replacing Characters Using the INSPECT Statement
INSPECT FIELD1 REPLACING
ALL "," BY SPACE
ALL "." BY SPACE
ALL ";" BY SPACE.
The previous three replacement arguments all have the same replacement value,
SPACE, and are active over the entire item being inspected. The statement
replaces all commas, periods, and semicolons with space characters and leaves all
other characters unchanged.
INSPECT FIELD1 REPLACING
ALL "0" BY "1"
ALL "1" BY "0".
Each of these two replacement arguments has its own replacement value and is
active over the entire item being inspected. The statement exchanges zeros for 1s
and 1s for zeros. It leaves all other characters unchanged.
INSPECT FIELD1 REPLACING
ALL "0" BY "1" BEFORE SPACE
ALL "1" BY "0" BEFORE SPACE.
Note
When a search argument finds a match in the item being inspected,
the code replaces that character-string and scans to the next position
beyond the replaced characters. It ignores the remaining arguments and
applies the first argument in the list to the character-string in the new
position. Thus, it never inspects the new value that was supplied by
the replacement operation. Because of this, the search arguments can
have the same values as the replacement arguments with no chance of
interference.
The statement also exchanges zeros and 1s. Here, however, the first space in
FIELD1 causes both arguments to become inactive.
INSPECT FIELD1 REPLACING
ALL "0" BY "1" BEFORE SPACE
ALL "1" BY "0" BEFORE SPACE
CHARACTERS BY "*" BEFORE SPACE.
The first space causes the three replacement arguments to become inactive. This
argument list exchanges zeros for 1s, 1s for zeros, and asterisks for all other
characters in the delimited area. If the BEFORE phrase is removed from the
third argument, that argument will remain active across all of FIELD1. Within
the area delimited by the first space character, the third argument replaces all
characters except 1s and zeros with asterisks. Beyond this area, it replaces
all characters (including the space that delimited FIELD1 for the first two
arguments, and any zeros and 1s) with asterisks.
5.3.6.5 Interference in Replacement Argument Lists
When several search arguments, all active at the same time, contain one or more
identical characters, they can interfere with each other—and consequently affect
the replacement operation. This interference is similar to the interference that
occurs between tally arguments.
The action of a search argument is never affected by the BEFORE/AFTER
delimiters of other arguments, because the compiler scans for delimiter matches
before it scans for replacement operations.
5–32 Using the STRING, UNSTRING, and INSPECT Statements
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......