skip to main content

Procedure Division Statements : INSPECT

INSPECT
General Format
Format 1
INSPECT identifier-1 TALLYING tallying-phrase
Format 2
INSPECT identifier-1 REPLACING replacing-phrase
Format 3
INSPECT identifier-1 TALLYING tallying-phrase REPLACING replacing-phrase
Format 4
INSPECT identifier-1 CONVERTING {identifier-6} TO {identifier-7} [after-before-phrase]
where tallying-phrase is:
{ identifier-2 FOR {CHARACTERS [ after-before-phrase ]           } ... } ...
                   {ALL { {identifier-3} [ after-before-phrase ] } ... }
                   {LEADING { {identifier-3} [ after-before-phrase ] ... }
where after-before-phrase is:
{ [ AFTER INITIAL {identifier-4} ] }
{ [ BEFORE INITIAL [TRAILING] {identifier-4} ] }
where replacement-phrase is:
CHARACTERS               BY replacement-item [ after-before-phrase ]       } ...
ALL     { {identifier-3} BY replacement-item [ after-before-phrase ] } ... }
LEADING { {identifier-3} BY replacement-item [ after-before-phrase ] } ... }
FIRST   { {identifier-3} BY replacement-item [ after-before-phrase ] } ... }
where replacement-item is:
Syntax Rules
All Formats
1.
2.
3.
4.
Formats 1 AND 3
5.
6.
Formats 2 AND 3
7.
8.
Format 1
9.
Format 4
10.
General Rules
All Formats
1.
2.
3.
A.
B.
C.
D.
4.
5.
Formats 1 AND 2
6.
7.
A.
i.
ii.
iii.
B.
C.
D.
E.
8.
A.
B.
C.
Format 1
9.
10.
11.
A.
B.
C.
12.
13.
If multiple FOR clauses are specified in the tallyling-phrase, the runtime resolves each one of them by analyzing Identifier-1 from the position of the previous verified condition. If -ca compiler option is used, instead, the runtime analyzes Identifier-1 from the beginning when resolving each one of the FOR clauses.
Formats 2 and 3
14.
15.
Format 2
16.
17.
A.
B.
C.
D.
18.
Format 3
19.
Format 4
20.
21.
22.
23.
Examples
Format 1 - Counting some capital letters on a string
initialize ws-count
move    "Another Beautiful Day" to ws-str
inspect ws-str tallying ws-count 
        for all "A" "B" "C" "D" "E" "F"
Format 2 - Changing "a" by "o" not from the beginning but after another character.
move "a first sentence with a. Hella Warld!" to ws-str
inspect ws-str replacing all "a" by "o" after initial "."
Format 2 - Replace all characters in string by zeroes
77 ws-str pic x(15) value "hello world!".
inspect ws-str replacing characters by zero
Format 2 - Replace characters by zeroes before the first quote
77 ws-str   pic x(30value 'hello world! "do not change"'.
77 ws-str   pic x(30value 'hello world! "do not change"'.
inspect ws-str replacing 
        characters by zeros
        before initial quote
Format 3 - Count the leading zeroes on a string and also change the first "a" by "2" after a specific character
initialize ws-count
move "00academy00" to ws-str
inspect ws-str tallying ws-count for leading "0"
        replacing first "a" by "2"
        after initial "c"
Format 4 - Converting Uppercase to Lowercase
move "THIS IS THE SENTENCE" to ws-str
inspect ws-str 
        converting "ABCDEFGHIJKLMNOPQRSTUVWXYZ" to
                   "abcdefghijklmnopqrstuvwxyz"

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left