Day 17: COBOL Report Generation and Formatting Techniques for Professional Business Outputs

 


1. Introduction: COBOL’s Power in Business Reporting

In the business world, data is valuable only when presented clearly — and that’s exactly where COBOL shines. From payroll slips to monthly sales summaries, COBOL systems have been generating reports for decades with precise column alignment, totals, and formatted values.

Unlike modern GUIs, COBOL reports are usually text-based, designed for printing or exporting to files. COBOL gives you full control over spacing, justification, currency symbols, and page layout, making it ideal for producing professional business documents.

COBOL uses the WRITE and DISPLAY statements for output, but the real formatting magic happens through Report Sections or structured output layouts designed in the DATA DIVISION.

In this lesson, you’ll learn how to:

  • Format report headings and columns

  • Generate totals and summaries

  • Produce clear, aligned output suitable for print or file export


2. Example: Generating a Salary Report in COBOL

Here’s a simple program that produces a formatted salary report for employees.

Program: EMPREPORT.cbl

IDENTIFICATION DIVISION. PROGRAM-ID. EMPREPORT. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMPFILE ASSIGN TO "EMPLOYEE.DAT" ORGANIZATION IS SEQUENTIAL. DATA DIVISION. FILE SECTION. FD EMPFILE. 01 EMP-RECORD. 05 EMP-ID PIC 9(4). 05 EMP-NAME PIC A(20). 05 EMP-SALARY PIC 9(6)V99. WORKING-STORAGE SECTION. 01 WS-TOTAL-SALARY PIC 9(8)V99 VALUE 0. 01 WS-LINE PIC X(80). 01 WS-DASH PIC X(80) VALUE ALL "-". 01 WS-EOF PIC X VALUE "N". PROCEDURE DIVISION. OPEN INPUT EMPFILE DISPLAY WS-DASH DISPLAY "EMPLOYEE SALARY REPORT" DISPLAY WS-DASH DISPLAY "ID NAME SALARY" DISPLAY WS-DASH PERFORM UNTIL WS-EOF = "Y" READ EMPFILE AT END MOVE "Y" TO WS-EOF NOT AT END MOVE SPACES TO WS-LINE STRING EMP-ID DELIMITED BY SIZE SPACE EMP-NAME DELIMITED BY SIZE SPACE "$" EMP-SALARY DELIMITED BY SIZE INTO WS-LINE END-STRING DISPLAY WS-LINE ADD EMP-SALARY TO WS-TOTAL-SALARY END-READ END-PERFORM DISPLAY WS-DASH DISPLAY "TOTAL SALARY: $" WS-TOTAL-SALARY DISPLAY WS-DASH CLOSE EMPFILE STOP RUN.

Explanation:

  • STRING combines multiple fields into one formatted output line.

  • DISPLAY prints headings, details, and totals.

  • WS-DASH is used for decorative report lines.

  • WS-TOTAL-SALARY accumulates a running total of all salaries.

This report will look like this on output:

------------------------------------------------------------ EMPLOYEE SALARY REPORT ------------------------------------------------------------ ID NAME SALARY ------------------------------------------------------------ 1001 ALICE WILLIAMS $55000.75 1002 BOB JONES $47000.00 ------------------------------------------------------------ TOTAL SALARY: $102000.75 ------------------------------------------------------------

3. Practical Use Cases and Report Design Tips

Common Business Reports:

  • 🧾 Payroll reports — employee ID, department, gross and net pay.

  • 🛒 Inventory reports — product name, stock, reorder levels.

  • 💰 Sales summaries — region-wise totals or monthly summaries.

Report Design Tips:

  • Always use fixed column widths for alignment.

  • Use STRING or UNSTRING for combining text.

  • Format numeric fields with proper PIC clauses (e.g., ZZ,ZZ9.99).

  • Add headers, footers, and totals for clarity.

  • For long reports, implement pagination using counters and headings per page.


🧠 Key Takeaways

  • COBOL’s structured output control enables clean, aligned text reports.

  • Use STRING, DISPLAY, and WRITE for formatted printing.

  • Maintain readability with headings, separators, and totals.

  • Proper formatting improves usability for audits and management review.

  • COBOL’s reporting features remain essential in enterprise systems today.


💻 Practice Task

  1. Create a program SALESREP.cbl that:

    • Reads SALES.DAT containing (Invoice-ID, Product, Amount).

    • Displays a formatted report with totals.

  2. Add a grand total line at the end.

  3. Bonus: Sort the report by product name before displaying.

"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