With INSPECT verb we can convert lower case characters to upper case:
INSPECT text-one CONVERTING ‘abcdefgh’ TO ‘ABCDEFGH’ .
The main usage of INSPECT is we can customise the string:
Secondly, it counts all the letters in an array:
PERFORM VARYING idx 1 BY 1 UNTIL idx > 100
INSPECT text-one TALLYING COUNT1(idx) FOR ALL LETTER1(idx)
All the letters in LETTER1 table counted into Count1.
Thirdly, REPLACING as needed one or multiple letters in output string.
INSPECT text-two REPLACING ALL “H” BY “K”
AFTER INITIAL “C” BEFORE INITIAL “O”.
Replacing also works, to replace only if found 4 letter word:
PERFORM VARYING idx FROM 1 BY 1 UNTIL idx > 100
INSPECT text-three REPLACING testable(idx) BY “1234”
There are many other usages. In my next post, I will discuss about problems that we meet in daily use.