MainframeMaster

COBOL Tutorial

COBOL REPORT Clause - Quick Reference

Progress0 of 0 lessons

Overview

The REPORT clause is used in COBOL's Report Writer feature to define report specifications. It enables automated report generation with consistent formatting, pagination, and calculations.

Purpose and Usage

  • Report definition - Define report structure and characteristics
  • Automated formatting - Generate formatted reports automatically
  • Consistent output - Ensure uniform report appearance
  • Pagination control - Manage page breaks and headers
  • Calculation support - Handle totals and subtotals

Report Writer Concept

REPORT Clause → [Report Groups] → [Report Writer Verbs] → Formatted Output
Automatic: Pagination, Totals, Formatting, Headers, Footers
Reduces manual coding for standard business reports

REPORT clause defines specifications for automated report generation.

Syntax

The REPORT clause follows specific syntax patterns within the REPORTS SECTION and can include various report specifications.

Basic Syntax

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
43
* Basic REPORT clause syntax REPORTS SECTION. RD report-name [IS GLOBAL] [PAGE LIMIT IS integer LINES] [HEADING integer] [FIRST DETAIL integer] [LAST DETAIL integer] [FOOTING integer] [CODE "literal"]. * Complete example REPORTS SECTION. RD SALES-REPORT PAGE LIMIT IS 60 LINES HEADING 1 FIRST DETAIL 5 LAST DETAIL 55 FOOTING 58 CODE "SR". * With global specification RD INVENTORY-REPORT IS GLOBAL PAGE LIMIT IS 66 LINES HEADING 2 FIRST DETAIL 8 LAST DETAIL 60 FOOTING 64. * Multiple reports RD DAILY-REPORT PAGE LIMIT IS 50 LINES HEADING 1 FIRST DETAIL 4 LAST DETAIL 45 FOOTING 48. RD MONTHLY-REPORT PAGE LIMIT IS 80 LINES HEADING 3 FIRST DETAIL 10 LAST DETAIL 70 FOOTING 75.

REPORT clause defines the structure and formatting parameters for reports.

REPORT vs File Processing Comparison

AspectREPORTFile Processing
FormattingAutomaticManual coding
PaginationBuilt-inManual control
TotalsAutomaticManual calculation
FlexibilityStandardizedHighly flexible
Development timeFasterSlower

Report Parameters

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
* PAGE LIMIT - Total lines per page RD REPORT-1 PAGE LIMIT IS 60 LINES * HEADING - Line number for page headers RD REPORT-2 HEADING 1 * FIRST DETAIL - First line for detail records RD REPORT-3 FIRST DETAIL 5 * LAST DETAIL - Last line for detail records RD REPORT-4 LAST DETAIL 55 * FOOTING - Line number for page footers RD REPORT-5 FOOTING 58 * CODE - Report identification code RD REPORT-6 CODE "RPT" * GLOBAL - Report available to subprograms RD REPORT-7 IS GLOBAL * Combined parameters RD COMPLETE-REPORT PAGE LIMIT IS 66 LINES HEADING 1 FIRST DETAIL 5 LAST DETAIL 60 FOOTING 64 CODE "CR" IS GLOBAL

Different parameters control various aspects of report formatting.

Practical Examples

These examples demonstrate how to use the REPORT clause effectively in different report generation scenarios.

Sales Report Definition

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
IDENTIFICATION DIVISION. PROGRAM-ID. SALES-REPORT-GEN. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT SALES-FILE ASSIGN TO "SALES.DAT" ORGANIZATION IS SEQUENTIAL. SELECT REPORT-FILE ASSIGN TO "SALES-REPORT.OUT" ORGANIZATION IS SEQUENTIAL. DATA DIVISION. FILE SECTION. FD SALES-FILE. 01 SALES-RECORD. 05 SALES-DATE PIC 9(8). 05 SALES-AMOUNT PIC 9(7)V99. 05 SALES-REGION PIC X(10). 05 SALES-PRODUCT PIC X(20). FD REPORT-FILE. REPORTS SECTION. RD SALES-REPORT PAGE LIMIT IS 60 LINES HEADING 1 FIRST DETAIL 5 LAST DETAIL 55 FOOTING 58 CODE "SR". * Report groups follow the RD 01 REPORT-HEADING TYPE IS REPORT HEADING. 05 LINE 1. 10 COLUMN 1 PIC X(20) VALUE "SALES REPORT". 10 COLUMN 40 PIC X(10) VALUE "DATE: ". 10 COLUMN 50 PIC 9(8) SOURCE CURRENT-DATE. 05 LINE 2. 10 COLUMN 1 PIC X(20) VALUE "REGION". 10 COLUMN 15 PIC X(20) VALUE "PRODUCT". 10 COLUMN 40 PIC X(10) VALUE "AMOUNT". 01 DETAIL-LINE TYPE IS DETAIL. 05 LINE PLUS 1. 10 COLUMN 1 PIC X(10) SOURCE SALES-REGION. 10 COLUMN 15 PIC X(20) SOURCE SALES-PRODUCT. 10 COLUMN 40 PIC 9(7)V99 SOURCE SALES-AMOUNT. 01 REPORT-FOOTING TYPE IS REPORT FOOTING. 05 LINE 58. 10 COLUMN 1 PIC X(20) VALUE "END OF REPORT". WORKING-STORAGE SECTION. 01 CURRENT-DATE PIC 9(8). PROCEDURE DIVISION. MAIN-PROCESS. OPEN INPUT SALES-FILE OPEN OUTPUT REPORT-FILE INITIATE SALES-REPORT PERFORM UNTIL END-OF-FILE READ SALES-FILE AT END MOVE "Y" TO EOF-FLAG NOT AT END GENERATE DETAIL-LINE END-READ END-PERFORM TERMINATE SALES-REPORT CLOSE SALES-FILE CLOSE REPORT-FILE STOP RUN.

REPORT clause defines the structure for automated sales report generation.

Inventory Report with Totals

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
* Inventory report with automatic totals REPORTS SECTION. RD INVENTORY-REPORT PAGE LIMIT IS 66 LINES HEADING 1 FIRST DETAIL 5 LAST DETAIL 60 FOOTING 64 CODE "INV". 01 PAGE-HEADER TYPE IS PAGE HEADING. 05 LINE 1. 10 COLUMN 1 PIC X(30) VALUE "INVENTORY STATUS REPORT". 10 COLUMN 50 PIC X(10) VALUE "PAGE: ". 10 COLUMN 60 PIC ZZZ9 SOURCE PAGE-COUNTER. 05 LINE 3. 10 COLUMN 1 PIC X(10) VALUE "ITEM CODE". 10 COLUMN 15 PIC X(20) VALUE "DESCRIPTION". 10 COLUMN 40 PIC X(10) VALUE "QUANTITY". 10 COLUMN 55 PIC X(10) VALUE "VALUE". 01 DETAIL-LINE TYPE IS DETAIL. 05 LINE PLUS 1. 10 COLUMN 1 PIC X(10) SOURCE ITEM-CODE. 10 COLUMN 15 PIC X(20) SOURCE ITEM-DESC. 10 COLUMN 40 PIC 9(5) SOURCE ITEM-QTY. 10 COLUMN 55 PIC 9(7)V99 SOURCE ITEM-VALUE. 01 CONTROL-FOOTING TYPE IS CONTROL FOOTING CATEGORY. 05 LINE PLUS 2. 10 COLUMN 1 PIC X(15) VALUE "CATEGORY TOTAL:". 10 COLUMN 40 PIC 9(5) SUM ITEM-QTY. 10 COLUMN 55 PIC 9(7)V99 SUM ITEM-VALUE. 01 REPORT-FOOTING TYPE IS REPORT FOOTING. 05 LINE 64. 10 COLUMN 1 PIC X(15) VALUE "GRAND TOTAL:". 10 COLUMN 40 PIC 9(5) SUM ITEM-QTY. 10 COLUMN 55 PIC 9(7)V99 SUM ITEM-VALUE. * Data structure for inventory records 01 INVENTORY-RECORD. 05 ITEM-CODE PIC X(10). 05 ITEM-DESC PIC X(20). 05 ITEM-QTY PIC 9(5). 05 ITEM-VALUE PIC 9(7)V99. 05 ITEM-CATEGORY PIC X(10). PROCEDURE DIVISION. GENERATE-INVENTORY-REPORT. INITIATE INVENTORY-REPORT PERFORM UNTIL END-OF-FILE READ INVENTORY-FILE AT END MOVE "Y" TO EOF-FLAG NOT AT END GENERATE DETAIL-LINE END-READ END-PERFORM TERMINATE INVENTORY-REPORT.

REPORT clause enables automatic totals and subtotals in inventory reports.

Financial Statement Report

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
* Financial statement with multiple sections REPORTS SECTION. RD FINANCIAL-REPORT PAGE LIMIT IS 80 LINES HEADING 3 FIRST DETAIL 8 LAST DETAIL 70 FOOTING 75 CODE "FIN". 01 REPORT-HEADING TYPE IS REPORT HEADING. 05 LINE 1. 10 COLUMN 1 PIC X(40) VALUE "FINANCIAL STATEMENT". 10 COLUMN 50 PIC X(10) VALUE "PERIOD: ". 10 COLUMN 60 PIC 9(8) SOURCE REPORT-PERIOD. 05 LINE 3. 10 COLUMN 1 PIC X(30) VALUE "ACCOUNT". 10 COLUMN 35 PIC X(20) VALUE "DESCRIPTION". 10 COLUMN 60 PIC X(15) VALUE "AMOUNT". 01 ASSETS-HEADING TYPE IS CONTROL HEADING ASSET-TYPE. 05 LINE PLUS 2. 10 COLUMN 1 PIC X(20) VALUE "ASSETS". 01 ASSET-DETAIL TYPE IS DETAIL. 05 LINE PLUS 1. 10 COLUMN 1 PIC X(10) SOURCE ACCOUNT-NUM. 10 COLUMN 15 PIC X(20) SOURCE ACCOUNT-DESC. 10 COLUMN 40 PIC 9(10)V99 SOURCE ACCOUNT-AMOUNT. 01 ASSET-TOTAL TYPE IS CONTROL FOOTING ASSET-TYPE. 05 LINE PLUS 1. 10 COLUMN 1 PIC X(15) VALUE "TOTAL ASSETS:". 10 COLUMN 40 PIC 9(10)V99 SUM ACCOUNT-AMOUNT. 01 LIABILITIES-HEADING TYPE IS CONTROL HEADING LIABILITY-TYPE. 05 LINE PLUS 2. 10 COLUMN 1 PIC X(25) VALUE "LIABILITIES". 01 LIABILITY-DETAIL TYPE IS DETAIL. 05 LINE PLUS 1. 10 COLUMN 1 PIC X(10) SOURCE ACCOUNT-NUM. 10 COLUMN 15 PIC X(20) SOURCE ACCOUNT-DESC. 10 COLUMN 40 PIC 9(10)V99 SOURCE ACCOUNT-AMOUNT. 01 LIABILITY-TOTAL TYPE IS CONTROL FOOTING LIABILITY-TYPE. 05 LINE PLUS 1. 10 COLUMN 1 PIC X(20) VALUE "TOTAL LIABILITIES:". 10 COLUMN 40 PIC 9(10)V99 SUM ACCOUNT-AMOUNT. 01 REPORT-FOOTING TYPE IS REPORT FOOTING. 05 LINE 75. 10 COLUMN 1 PIC X(20) VALUE "NET WORTH:". 10 COLUMN 40 PIC 9(10)V99 SOURCE NET-WORTH. * Financial data structure 01 FINANCIAL-RECORD. 05 ACCOUNT-NUM PIC X(10). 05 ACCOUNT-DESC PIC X(20). 05 ACCOUNT-AMOUNT PIC 9(10)V99. 05 ACCOUNT-TYPE PIC X(1). 88 ASSET-TYPE VALUE "A". 88 LIABILITY-TYPE VALUE "L". WORKING-STORAGE SECTION. 01 REPORT-PERIOD PIC 9(8). 01 NET-WORTH PIC 9(10)V99. PROCEDURE DIVISION. GENERATE-FINANCIAL-REPORT. INITIATE FINANCIAL-REPORT PERFORM UNTIL END-OF-FILE READ FINANCIAL-FILE AT END MOVE "Y" TO EOF-FLAG NOT AT END GENERATE ASSET-DETAIL GENERATE LIABILITY-DETAIL END-READ END-PERFORM TERMINATE FINANCIAL-REPORT.

REPORT clause supports complex financial reports with multiple sections.

Multi-Report Program

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
* Program with multiple reports REPORTS SECTION. RD DAILY-REPORT PAGE LIMIT IS 50 LINES HEADING 1 FIRST DETAIL 4 LAST DETAIL 45 FOOTING 48 CODE "DLY". RD MONTHLY-REPORT PAGE LIMIT IS 80 LINES HEADING 3 FIRST DETAIL 8 LAST DETAIL 70 FOOTING 75 CODE "MTH". RD SUMMARY-REPORT PAGE LIMIT IS 40 LINES HEADING 2 FIRST DETAIL 5 LAST DETAIL 35 FOOTING 38 CODE "SUM". * Daily report groups 01 DAILY-HEADER TYPE IS REPORT HEADING. 05 LINE 1. 10 COLUMN 1 PIC X(20) VALUE "DAILY ACTIVITY REPORT". 01 DAILY-DETAIL TYPE IS DETAIL. 05 LINE PLUS 1. 10 COLUMN 1 PIC X(10) SOURCE ACTIVITY-DATE. 10 COLUMN 15 PIC X(20) SOURCE ACTIVITY-DESC. 10 COLUMN 40 PIC 9(7)V99 SOURCE ACTIVITY-AMOUNT. * Monthly report groups 01 MONTHLY-HEADER TYPE IS REPORT HEADING. 05 LINE 1. 10 COLUMN 1 PIC X(25) VALUE "MONTHLY SUMMARY REPORT". 01 MONTHLY-DETAIL TYPE IS DETAIL. 05 LINE PLUS 1. 10 COLUMN 1 PIC X(10) SOURCE MONTH-YEAR. 10 COLUMN 15 PIC X(15) SOURCE CATEGORY. 10 COLUMN 35 PIC 9(10)V99 SOURCE MONTHLY-TOTAL. * Summary report groups 01 SUMMARY-HEADER TYPE IS REPORT HEADING. 05 LINE 1. 10 COLUMN 1 PIC X(20) VALUE "ANNUAL SUMMARY REPORT". 01 SUMMARY-DETAIL TYPE IS DETAIL. 05 LINE PLUS 1. 10 COLUMN 1 PIC X(10) SOURCE YEAR. 10 COLUMN 15 PIC X(15) SOURCE ANNUAL-TOTAL. PROCEDURE DIVISION. GENERATE-ALL-REPORTS. * Generate daily report INITIATE DAILY-REPORT PERFORM GENERATE-DAILY-REPORT TERMINATE DAILY-REPORT * Generate monthly report INITIATE MONTHLY-REPORT PERFORM GENERATE-MONTHLY-REPORT TERMINATE MONTHLY-REPORT * Generate summary report INITIATE SUMMARY-REPORT PERFORM GENERATE-SUMMARY-REPORT TERMINATE SUMMARY-REPORT.

Multiple REPORT clauses enable different report types in a single program.

Best Practices and Tips

Following these best practices ensures effective use of the REPORT clause in COBOL applications.

REPORT Best Practices

  • Use meaningful report names - Choose descriptive report identifiers
  • Set appropriate page limits - Consider printer and display constraints
  • Plan line spacing carefully - Allocate space for headers and footers
  • Use consistent formatting - Maintain uniform report appearance
  • Test with various data - Verify formatting with different record counts
  • Document report specifications - Clearly document report requirements

Common Pitfalls to Avoid

PitfallProblemSolution
Insufficient page spaceContent overflowIncrease page limits
Poor line allocationFormatting issuesPlan line spacing carefully
Missing report groupsIncomplete reportsDefine all necessary groups
Incorrect file associationOutput errorsVerify file definitions
Complex report logicMaintenance difficultiesKeep reports simple

Performance Considerations

  • Efficient formatting - Report Writer optimizes output generation
  • Automatic calculations - Built-in totals reduce processing overhead
  • Memory usage - Report Writer manages memory efficiently
  • I/O optimization - Buffered output improves performance
  • Compiler optimization - Modern compilers optimize Report Writer code

When to Use REPORT vs Manual Processing

ScenarioUse REPORTUse Manual Processing
Standard business reportsYesNo
Complex custom formattingNoYes
Automatic totalsYesNo
Rapid developmentYesNo
Non-standard outputNoYes

REPORT Clause Quick Reference

ParameterSyntaxPurpose
Basic reportRD report-nameDefine report structure
Page limitPAGE LIMIT IS n LINESSet page size
HeadingHEADING nSet header line
Detail rangeFIRST DETAIL n LAST DETAIL nSet detail area
FootingFOOTING nSet footer line
CodeCODE "literal"Set report identifier
GlobalIS GLOBALMake available to subprograms

Test Your Knowledge

1. What is the primary purpose of the REPORT clause in COBOL?

  • To create database reports
  • To define Report Writer report specifications
  • To generate file reports
  • To create program documentation

2. In which section is the REPORT clause most commonly used?

  • PROCEDURE DIVISION
  • REPORTS SECTION
  • FILE SECTION
  • WORKING-STORAGE SECTION

3. What happens when a REPORT clause is executed?

  • A report is automatically generated
  • Report specifications are defined
  • A report file is created
  • Report data is processed

4. What is the relationship between REPORT and Report Writer verbs?

  • They are the same thing
  • REPORT defines structure, verbs generate output
  • REPORT is faster than verbs
  • They cannot be used together

5. Which of the following is a valid REPORT clause usage?

  • REPORT report-name
  • REPORT report-name IS report-type
  • REPORT report-name ON file-name
  • All of the above

Frequently Asked Questions