The below are top four COBOL ‘INSPECT’ examples. These you can use directly into your project.
With INSPECT verb you can convert lower case characters to upper case:
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) END-PERFORM
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" END-PERFORM
There are many other usages. In my next post, I will discuss about problems that we meet in daily use.