Compaq AAQ2G1FTK Marine Radio User Manual


 
Using the STRING, UNSTRING, and INSPECT Statements
5.3 Examining and Replacing Characters Using the INSPECT Statement
The action of a search argument is never affected by the characters of any
replacement value, because the scanner does not inspect the replaced characters
again during execution of the INSPECT statement. Interference between search
arguments, therefore, depends on the order of the arguments, the values of the
arguments, and the active/inactive status of the arguments. The discussion in
Section 5.3.5.4 about interference in tally argument lists generally applies to
replacement arguments as well.
The following rules help minimize interference in replacement argument lists:
1. Place search arguments with LEADING or FIRST conditions at the start of
the list.
2. Place any arguments with the CHARACTERS condition at the end of the list.
3. Consider the order of appearance of any search arguments that contain
identical characters.
5.3.7 Using the CONVERTING Option
When an INSPECT statement contains a CONVERTING phrase, that statement
selectively replaces characters or groups of characters in the designated item;
it executes as if it were a Format 2 INSPECT statement with a series of ALL
phrases. (See the INSPECT statement formats in the Compaq COBOL Reference
Manual.)
An example of the use of the CONVERTING phrase follows:
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGX.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X PIC X(28).
PROCEDURE DIVISION.
A.
MOVE "ABC*ABC*ABC ABC@ABCABC" TO X.
INSPECT X CONVERTING "ABC" TO "XYZ"
AFTER "*" BEFORE "@".
DISPLAY X.
STOP RUN.
X before INSPECT executes X after INSPECT executes
ABC*ABC*ABC ABC@ABCABC ABC*XYZ*XYZ XYZ@ABCABC
5.3.8 Common INSPECT Statement Errors
Programmers most commonly make the following errors when writing INSPECT
statements:
Leaving the FOR out of an INSPECT...TALLYING statement
Using the word WITH instead of BY in the REPLACING phrase
Failing to initialize the tally counter
Omitting the word ALL before the comparison character-string
Using the STRING, UNSTRING, and INSPECT Statements 533