COBOL Strings, Here are Ideas (1 of 2)

INSPECT Verb plays a crucial role in string manipulation in COBOL. Best practical INSPECT VERB usages are given below. These are ready to use in your COBOL programs.

Converting to UPPER CASE

INSPECT FUNCTION UPPER-CASE(TextLine)
TALLYING LetterCount FOR ALL Letters(LetterPos:1)

INSPECT…Tallying

INSPECT‥TALLYING counts the number of occurrences of a character in a string.

INSPECT…..to count vowels and consonants

INSPECT FUNCTION UPPER-CASE(TextLine) TALLYING
VowelCount FOR ALL "A" "E" "I" "O" "U"
ConsonantCount FOR ALL
"B" "C" "D" "F" "G" "H" "J" "K" "L" "M" "N" "P"
"Q" "R" "S" "T" "V" "W" "X" "Y" "Z"

Best examples of INSPECT…Replacing

INSPECT StringData REPLACING ALL "F" BY "G"
AFTER INITIAL "A" BEFORE INITIAL "Q"

INSPECT StringData REPLACING ALL "F" BY "G"
AFTER INITIAL "A" BEFORE INITIAL "Z"

INSPECT StringData REPLACING FIRST "F" BY "G"
AFTER INITIAL "A" BEFORE INITIAL "Q"

INSPECT StringData REPLACING
ALL "FFFF" BY "DOGS"
AFTER INITIAL "A" BEFORE INITIAL "Z"

INSPECT StringData REPLACING
CHARACTERS BY "z" BEFORE INITIAL "Q"

Best example of INSPECT….converting

INSPECT‥CONVERTING seems very similar to INSPECT‥REPLACING but actually works quite differently. It is used to convert one list of characters to another list of characters on a character-per-character basis.

INSPECT dat1 CONVERTING 'ABCD'  to 'abcd'.

INSPECT TextLine CONVERTING UpperCase TO LowerCase

Author: Srini

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