COBOL INSPECT these four top examples you need to try

The below are top four COBOL ‘INSPECT’ examples. These you can use directly into your project.

Benefit-1:

With INSPECT verb you can convert lower case characters to upper case:

INSPECT text-one CONVERTING 'abcdefgh' TO 'ABCDEFGH'.
The main usage of INSPECT is we can customize the string:

Benefit-2:

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.

Benefit-3:

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".

Benefit-4:

Replacing also works, to replace only if found 4 letter word:

Example:

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.

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.