Day 9: Understanding COBOL Tables and Arrays for Managing Repetitive Data Efficiently in Business Applications

 

1. Introduction: Why Tables and Arrays Are Important in COBOL

In any business application, handling repetitive data efficiently is essential. Whether it’s storing multiple employee salaries, tracking product prices, or keeping a list of customer balances, COBOL uses Tables (or Arrays) to manage such repetitive information.

Unlike databases or indexed files, tables in COBOL are in-memory structures that allow fast access to repeated groups of data using subscripting or indexing. For example, instead of writing separate variables for 100 employees, you can store all salaries in a single table and access them by index — making programs shorter, faster, and more maintainable.

Tables form the foundation of many COBOL data operations, including report generation, searching, and data sorting. As you work with COBOL more deeply, understanding tables will be vital for optimizing program logic and reducing redundancy.


2. Defining and Accessing a Table in COBOL

A table is declared in the DATA DIVISION, typically under the WORKING-STORAGE SECTION, using the OCCURS clause to specify repetition.

Example:

DATA DIVISION. WORKING-STORAGE SECTION. 01 EMPLOYEE-SALARY-TABLE. 05 EMPLOYEE-SALARY OCCURS 5 TIMES PIC 9(6)V99.

Here:

  • OCCURS 5 TIMES defines 5 repeating salary entries.

  • Each element is accessed by a subscript, like EMPLOYEE-SALARY(1) or EMPLOYEE-SALARY(5).

You can assign and display values like this:

PROCEDURE DIVISION. MOVE 25000.50 TO EMPLOYEE-SALARY(1). MOVE 32000.75 TO EMPLOYEE-SALARY(2). DISPLAY "FIRST SALARY: " EMPLOYEE-SALARY(1). DISPLAY "SECOND SALARY: " EMPLOYEE-SALARY(2).

This approach saves code and makes it easy to loop through data dynamically.


3. Using PERFORM Loops with Tables

One of the most powerful uses of tables in COBOL is combining them with PERFORM loops to process data efficiently.

Example program to accept and display 5 employee salaries:

IDENTIFICATION DIVISION. PROGRAM-ID. TABLE-DEMO. DATA DIVISION. WORKING-STORAGE SECTION. 01 EMPLOYEE-SALARY-TABLE. 05 EMPLOYEE-SALARY OCCURS 5 TIMES PIC 9(6)V99. 01 I PIC 9 VALUE 1. PROCEDURE DIVISION. DISPLAY "ENTER 5 EMPLOYEE SALARIES:". PERFORM VARYING I FROM 1 BY 1 UNTIL I > 5 DISPLAY "ENTER SALARY " I ": " ACCEPT EMPLOYEE-SALARY(I) END-PERFORM. DISPLAY "EMPLOYEE SALARY LIST:". PERFORM VARYING I FROM 1 BY 1 UNTIL I > 5 DISPLAY "EMPLOYEE " I " SALARY: " EMPLOYEE-SALARY(I) END-PERFORM. STOP RUN.

This small program demonstrates how COBOL can manage lists or batches of information without database operations. You can later enhance it by adding search functionality using the SEARCH verb.


🧠 Key Takeaways

  • COBOL Tables are used to store multiple occurrences of similar data.

  • The OCCURS clause defines how many times a field repeats.

  • Access elements using subscripts (e.g., EMPLOYEE-SALARY(3)).

  • Use PERFORM loops to iterate through the table for data entry and display.

  • Tables are stored in memory — perfect for temporary, fast-access data processing.


💻 Practice Task

  1. Write a COBOL program named StudentMarksTable.cbl.

  2. Create a table to store marks of 10 students using OCCURS.

  3. Use PERFORM to accept and display all marks.

  4. Add logic to calculate the average mark of the class.



"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