Day 11: COBOL String Handling Techniques for Concatenation, Substring Extraction, and Text Manipulation in Business Applications

 



1. Introduction: Importance of String Handling in COBOL

In the world of business computing, string manipulation is everywhere — from formatting customer names to creating reports or validating inputs like IDs and addresses. COBOL provides powerful string handling verbs that let you manage and modify character data effectively.

Unlike modern languages where string functions are built-in, COBOL uses a clear and structured approach through verbs such as STRING, UNSTRING, and INSPECT. These verbs help you join, split, or analyze strings with full control — essential for data formatting in financial, banking, and enterprise applications.

Understanding these operations will make your COBOL programs more dynamic, especially when dealing with user inputs, reports, or record formatting for file processing.


2. The STRING Verb: Combining Multiple Text Fields

The STRING verb is used to concatenate multiple fields into a single variable. It is commonly used when building a formatted message or combining first name and last name.

Example:

DATA DIVISION. WORKING-STORAGE SECTION. 01 FIRST-NAME PIC X(10) VALUE "PRAVEEN". 01 LAST-NAME PIC X(10) VALUE "MAHESH". 01 FULL-NAME PIC X(25). PROCEDURE DIVISION. STRING FIRST-NAME DELIMITED BY SPACE " " DELIMITED BY SIZE LAST-NAME DELIMITED BY SPACE INTO FULL-NAME END-STRING. DISPLAY "FULL NAME: " FULL-NAME.

Explanation:

  • DELIMITED BY controls how much of each field is joined.

  • You can include literals (like spaces) in between.

  • The result is stored in a new variable (FULL-NAME).

This is perfect for combining names, addresses, or formatted output before writing to files or reports.


3. UNSTRING and INSPECT: Splitting and Analyzing Text

a) UNSTRING

The UNSTRING verb splits a single text value into multiple fields — very useful for processing CSV or delimited input data.

Example:

DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-DATA PIC X(30) VALUE "101,PRAVEEN,65000". 01 EMP-ID PIC 9(3). 01 EMP-NAME PIC X(10). 01 EMP-SAL PIC 9(6). PROCEDURE DIVISION. UNSTRING INPUT-DATA DELIMITED BY "," INTO EMP-ID, EMP-NAME, EMP-SAL END-UNSTRING. DISPLAY "ID: " EMP-ID " NAME: " EMP-NAME " SALARY: " EMP-SAL.

This allows you to extract structured fields from raw text — an everyday COBOL task when reading data files.

b) INSPECT

The INSPECT verb analyzes or modifies text, such as counting or replacing characters:

INSPECT EMP-NAME TALLYING WS-COUNT FOR ALL "E". DISPLAY "NUMBER OF E's: " WS-COUNT.

This is especially useful for data validation, cleaning, or reporting.


🧠 Key Takeaways

  • STRING joins multiple text fields together.

  • UNSTRING splits a single text value into separate fields.

  • INSPECT is used for counting, finding, or replacing characters.

  • String handling is vital for text-based data operations, file reading, and report generation.

  • These features make COBOL flexible and practical for legacy enterprise systems.


💻 Practice Task

  1. Write a COBOL program named StringOperations.cbl.

  2. Accept an input like "2001,RAHUL SHARMA,IT,75000".

  3. Use UNSTRING to extract Employee ID, Name, Department, and Salary.

  4. Use STRING to format it as "RAHUL SHARMA works in IT Department earning ₹75000".

  5. Use INSPECT to count how many times the letter “A” appears in the employee’s name

  6. "This Content Sponsored by SBO Digital Marketing.

    Mobile-Based Part-Time Job Opportunity by SBO!

    Earn money online by doing simple content publishing and sharing tasks. Here's how:

    • Job Type: Mobile-based part-time work
    • Work Involves:
      • Content publishing
      • Content sharing on social media
    • Time Required: As little as 1 hour a day
    • Earnings: ₹300 or more daily
    • Requirements:
      • Active Facebook and Instagram account
      • Basic knowledge of using mobile and social media

    For more details:

    WhatsApp your Name and Qualification to 9994104160

    a.Online Part Time Jobs from Home

    b.Work from Home Jobs Without Investment

    c.Freelance Jobs Online for Students

    d.Mobile Based Online Jobs

    e.Daily Payment Online Jobs

    Keyword & Tag: #OnlinePartTimeJob #WorkFromHome #EarnMoneyOnline #PartTimeJob #jobs #jobalerts #withoutinvestmentjob"

Comments