Inspect Converting Example


Scenario - Converting a string from upper case to lower case.

Code -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. INSPECTC.
       AUTHOR. MTH.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-VAR.
          05 WS-DATA    PIC X(40) VALUE
             "COBOL LANGUAGE IS A HIGH LEVEL LANGUAGE".
          05 WS-SOURCE  PIC X(26) VALUE 
             "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
          05 WS-TARGET  PIC X(26) VALUE
             "abcdefghijklmnopqrstuvwxyz".

       PROCEDURE DIVISION.
           DISPLAY "BEFORE CONVERSION:     " WS-DATA.  
           INSPECT WS-DATA
                   CONVERTING WS-SOURCE TO WS-TARGET
                         BEFORE "IS".
           DISPLAY "AFTER CONVERSION:      " WS-DATA.
           STOP RUN.

Output -

BEFORE CONVERSION:     COBOL LANGUAGE IS A HIGH LEVEL LANGUAGE
AFTER CONVERSION:      cobol language IS A HIGH LEVEL LANGUAGE

Explaining Example -

In the above example:

  • All the uppercase characters before "IS" is converted lowecase characters. The output is "cobol language IS A HIGH LEVEL LANGUAGE ".