inspect in cobol, cobol inspect replacing leading spaces, cobol inspect tallying characters, COBOL Tutorial, cobol inspect
COBOL Tutorial COBOL Inspect Statement

COBOL Inspect statement (Inspect statement in COBOL).

Topictrick.com
3 min readJul 26, 2019

Welcome back to another exciting tutorial on “COBOL Inspect Statement”. String manipulation is an integral part of any programming language and COBOL also provides many intrinsic functions that can be used to manipulate the string, one such function is COBOL Inspect statement.

The INSPECT statement in COBOL is generally used for string manipulation in the COBOL program.

INSPECT in COBOL is primarily used for manipulating string or text. The COBOL INSPECT statement lets you count characters in a field or replace characters in a field. The INSPECT statement has four different formats that vary based on the use of the Tallying, Replacing and Converting clauses.

You can use the COBOL Inspect clause for replacing, converting or counting the characters in a given variable. A variable can be alphabetic, alphanumeric, or numeric with usage as the display. When you code CHARACTERS in the Tallying clause, it refers to all of the characters in the field that’s being inspected.

In contrast, ALL refers to all occurrences of the specified character or characters, and LEADING refers to all occurrences of the specified character or characters at the start of the field.

Inspect statement in COBOL, has following variants. Let’s discuss each variant with example.

  1. COBOL Inspect with Replacing Phrase.
  2. COBOL Inspect with Tallying Phrase.
  3. COBOL Inspect with Converting Phrase.
  4. COBOL Inspect with Tallying and Replacing Phrase.
Inspect statement in COBOL, COBOL Tutorial, Inspect with replacing
COBOL Tutorial: COBOL INSPECT Statement

COBOL Inspect Syntax.

COBOL inspect syntax, Inspect Statement in COBOL, inspect statement syntax in cobol, cobol inspect replacing statement syntax
COBOL Inspect Syntax.

Example 1: COBOL Inspect Statement.

.....
WORKING-STORAGE SECTION.
01 WS-DTE PIC X(10) VALUE “10-11-2020”.
PROCEDURE DIVISION.
A000-MAIN-SECTION.
INSPECT WS-DTE REPLACING ALL "-" BY "/".

Output - 10/11/2020

Example 2: COBOL Inspect with TALLYING.

.....
WORKING-STORAGE SECTION.
01 WS-NME PIC X(15) VALUE “DAVID MURPHY”.
01 WS-CNT PIC 9(03) VALUE ZEROES.
PROCEDURE DIVISION.
A000-MAIN-SECTION.
INSPECT WS-NME TALLYING WS-CNT FOR ALL SPACES.
Output - 004

Example 3: COBOL Inspect with REPLACE.

.....
INSPECT WS-NME REPLACING ALL "D" BY
"d" AFTER INITIAL "D".
Output - DAVId MURPHY

Example 4: COBOL Inspect with CONVERTING.

.....
INSPECT WS-NME CONVERTING
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO "abcdefghijklmnopqrstuvwxyz".
Output - david murphy

You can use the COBOL Inspect clause with the Tallying and Replacing clauses to both count and replace characters in a field operation.

COBOL Tutorial: Inspect statement in COBOL.

You’ll learn about each of COBOL INSPECT statement formats with examples.

Read More…

Please Subscribe to Topictrick & Don’t forget to press THE BELL ICON to never miss any updates. Please visit below mention the link to stay connected with Topictrick.
Topictrick.com
Youtube
Follow us on Twitter
Facebook
Linkedin
Reddit
Mainframe Blog

Thank you for your support.

Topictrick™

--

--

Topictrick.com
Topictrick.com

Written by Topictrick.com

Topictrick is a comprehensive repository of programming language tutorial and tech reviews. Also, it showcases what new in the tech industry. One place for all.

No responses yet