MainframeMaster

COBOL Tutorial

COBOL WRITERS - Quick Reference

Progress0 of 0 lessons

Overview

WRITERS in COBOL refers to the Report Writer functionality, which provides a powerful and flexible way to generate formatted reports. Report Writer automates many aspects of report generation including page formatting, headings, footings, and control breaks, making it easier to create professional-looking reports.

Key Features

  • Automatic formatting - Handles page layout and positioning
  • Report groups - Organize report content into logical sections
  • Control breaks - Automatic handling of data grouping
  • Page management - Automatic page breaks and headers/footers

Syntax and Usage

Report Writer syntax and usage patterns for different report generation scenarios.

Basic Report Writer Structure

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
IDENTIFICATION DIVISION. PROGRAM-ID. REPORT-WRITER-EXAMPLE. DATA DIVISION. REPORT SECTION. RD SALES-REPORT PAGE LIMIT IS 60 LINES HEADING 1 FIRST DETAIL 5 LAST DETAIL 55 FOOTING 58. 01 PAGE-HEADING TYPE IS PAGE HEADING. 03 LINE 1. 05 COLUMN 20 VALUE "SALES REPORT". 05 COLUMN 60 VALUE "PAGE ". 05 COLUMN 66 PIC ZZZ9 SOURCE PAGE-COUNTER. 01 DETAIL-LINE TYPE IS DETAIL. 03 LINE PLUS 1. 05 COLUMN 5 PIC X(20) SOURCE CUSTOMER-NAME. 05 COLUMN 30 PIC ZZZ,ZZ9.99 SOURCE SALE-AMOUNT. PROCEDURE DIVISION. INITIATE SALES-REPORT GENERATE DETAIL-LINE TERMINATE SALES-REPORT STOP RUN.

Basic Report Writer structure with page heading and detail lines.

Report Writer with Control Breaks

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
IDENTIFICATION DIVISION. PROGRAM-ID. REPORT-CONTROL-BREAKS. DATA DIVISION. REPORT SECTION. RD DEPARTMENT-REPORT CONTROL IS DEPT-NUMBER PAGE LIMIT IS 60 LINES. 01 DEPT-HEADING TYPE IS CONTROL HEADING DEPT-NUMBER. 03 LINE PLUS 1. 05 COLUMN 10 VALUE "DEPARTMENT: ". 05 COLUMN 22 PIC 9(3) SOURCE DEPT-NUMBER. 01 DETAIL-LINE TYPE IS DETAIL. 03 LINE PLUS 1. 05 COLUMN 5 PIC X(20) SOURCE EMPLOYEE-NAME. 05 COLUMN 30 PIC ZZZ,ZZ9.99 SOURCE SALARY. 01 DEPT-FOOTING TYPE IS CONTROL FOOTING DEPT-NUMBER. 03 LINE PLUS 1. 05 COLUMN 25 VALUE "DEPT TOTAL: ". 05 COLUMN 38 PIC ZZZ,ZZ9.99 SOURCE DEPT-TOTAL. PROCEDURE DIVISION. INITIATE DEPARTMENT-REPORT GENERATE DETAIL-LINE TERMINATE DEPARTMENT-REPORT STOP RUN.

Report Writer with control breaks for grouping data by department.

Report Writer with Multiple Groups

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
IDENTIFICATION DIVISION. PROGRAM-ID. REPORT-MULTIPLE-GROUPS. DATA DIVISION. REPORT SECTION. RD COMPREHENSIVE-REPORT PAGE LIMIT IS 66 LINES HEADING 1 FIRST DETAIL 10 LAST DETAIL 60 FOOTING 63. 01 REPORT-HEADING TYPE IS REPORT HEADING. 03 LINE 1. 05 COLUMN 25 VALUE "COMPREHENSIVE SALES REPORT". 03 LINE 3. 05 COLUMN 10 VALUE "DATE: ". 05 COLUMN 16 PIC X(10) SOURCE CURRENT-DATE. 01 PAGE-HEADING TYPE IS PAGE HEADING. 03 LINE 1. 05 COLUMN 5 VALUE "CUSTOMER". 05 COLUMN 25 VALUE "PRODUCT". 05 COLUMN 45 VALUE "AMOUNT". 03 LINE 2. 05 COLUMN 1 VALUE ALL "-". 01 DETAIL-LINE TYPE IS DETAIL. 03 LINE PLUS 1. 05 COLUMN 5 PIC X(20) SOURCE CUSTOMER-NAME. 05 COLUMN 25 PIC X(15) SOURCE PRODUCT-NAME. 05 COLUMN 45 PIC ZZZ,ZZ9.99 SOURCE SALE-AMOUNT. 01 PAGE-FOOTING TYPE IS PAGE FOOTING. 03 LINE 63. 05 COLUMN 5 VALUE "PAGE ". 05 COLUMN 10 PIC ZZZ9 SOURCE PAGE-COUNTER. PROCEDURE DIVISION. INITIATE COMPREHENSIVE-REPORT GENERATE DETAIL-LINE TERMINATE COMPREHENSIVE-REPORT STOP RUN.

Report Writer with multiple report groups for comprehensive reporting.

Report Types

Page Heading

Appears at the top of each page.

cobol
1
2
01 PAGE-HEADING TYPE IS PAGE HEADING. 03 LINE 1 COLUMN 20 VALUE "REPORT TITLE".

Detail Line

Contains the main report data.

cobol
1
2
3
01 DETAIL-LINE TYPE IS DETAIL. 03 LINE PLUS 1. 05 COLUMN 5 PIC X(20) SOURCE DATA-FIELD.

Control Heading

Appears at the start of a control group.

cobol
1
2
3
4
01 CONTROL-HEADING TYPE IS CONTROL HEADING FIELD-NAME. 03 LINE PLUS 1. 05 COLUMN 10 VALUE "GROUP: ". 05 COLUMN 17 PIC 9(3) SOURCE FIELD-NAME.

Control Footing

Appears at the end of a control group.

cobol
1
2
3
4
01 CONTROL-FOOTING TYPE IS CONTROL FOOTING FIELD-NAME. 03 LINE PLUS 1. 05 COLUMN 25 VALUE "TOTAL: ". 05 COLUMN 32 PIC ZZZ,ZZ9.99 SOURCE GROUP-TOTAL.

Best Practices

  • Plan report structure - Design the report layout before implementation
  • Use meaningful names - Choose descriptive names for report groups and fields
  • Handle page limits - Set appropriate page limits and line spacing
  • Test thoroughly - Test reports with various data volumes and scenarios
  • Consider performance - Optimize report generation for large datasets

WRITERS Quick Reference

Report TypeSyntaxUse Case
Page HeadingTYPE IS PAGE HEADINGPage titles and headers
Detail LineTYPE IS DETAILMain report data
Control HeadingTYPE IS CONTROL HEADINGGroup headers
Control FootingTYPE IS CONTROL FOOTINGGroup totals and summaries

Test Your Knowledge

1. What is the primary purpose of WRITERS in COBOL?

  • To read data from files
  • To generate formatted reports and output using Report Writer functionality
  • To perform calculations
  • To handle exceptions

2. Which section is used to define Report Writer reports?

  • FILE SECTION
  • WORKING-STORAGE SECTION
  • REPORT SECTION
  • LINKAGE SECTION

3. What is a Report Group in Report Writer?

  • A collection of files
  • A logical grouping of report lines with similar formatting and processing
  • A type of data structure
  • A program parameter

4. Which statement is used to generate Report Writer output?

  • WRITE
  • GENERATE
  • DISPLAY
  • PRINT

5. What is the purpose of LINE and COLUMN clauses in Report Writer?

  • To define file positions
  • To specify the exact position of report elements on the page
  • To define data types
  • To handle errors

Frequently Asked Questions