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







2 responses
[…] Read my previous post on COBOL Strings-INSPECT VERB. […]
LikeLike
[…] though I was busy in my work, I decided to spend some time for our readers on technical help. COBOL strings is a key subject and across all the big mainframe projects (Finance, Insurance and Manufacture) without strings […]
LikeLike