Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

MODULE 8: String handling


EXAMINE

  • INSPECT and EXAMINE are used to perform same operations
  • EXAMINE was present in the earlier version of COBOL and was replaced in ANSI 74 COBOL with more powerful verb INSPECT
  • However, many implementation still uses EXAMINE and thus we are covering it at high level
  • It is suggested to use INSPECT instead of EXAMINE
  • Basic syntax:-

    EXAMINE identifier-1 TALLYING [{ALL/LEADING/UNTIL FIRST} literal-1] REPLACING [{ALL/LEADING/[UNTIL] FIRST} literal-1]

  • In EXAMINE, when TALLYING is used, count is stored in a register called TALLY
  • Example:-
    In DATA DIVISION,

    01 WS-STRING PIC X(17) VALUE ‘MAINFRAME-IS-BEST’.

    In PROCEDURE DIVISION,

    EXAMINE WS-STRING TALLYING ALL ‘-‘ RELACING BY ‘ ‘

    Result: WS-STRING will contain ‘MAINFRAME IS BEST’ and TALLY Register will contain ‘2’
    Reason: There are total ‘2’ occurrences of ‘-‘ replaced by ‘ ‘(space)






© copyright mainframebug.com
Privacy Policy