MainframeMaster

COBOL Tutorial

COBOL FIRST Clause

The FIRST clause represents a fundamental page control mechanism within COBOL's Report Writer facility, serving as the primary specification for defining the initial line position where detail content begins on each report page. This clause embodies the principles of structured page layout management by providing precise control over vertical positioning, enabling sophisticated report formatting capabilities, and supporting consistent page structure across multi-page documents while maintaining optimal readability and professional presentation standards in enterprise reporting environments and business documentation systems.

Syntax and Usage

FIRST DETAIL Syntax
cobol
1
2
3
4
5
6
RD report-name PAGE LIMIT IS integer LINES HEADING integer FIRST DETAIL integer LAST DETAIL integer FOOTING integer.
Report Writer
Page Control
Layout Management

Comprehensive FIRST Implementation

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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
IDENTIFICATION DIVISION. PROGRAM-ID. FIRST-CLAUSE-COMPREHENSIVE. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMPLOYEE-INPUT-FILE ASSIGN TO 'EMPLOYEES.DAT' ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS INPUT-FILE-STATUS. SELECT PAYROLL-REPORT-FILE ASSIGN TO 'PAYROLL.RPT' ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS REPORT-FILE-STATUS. DATA DIVISION. FILE SECTION. FD EMPLOYEE-INPUT-FILE BLOCK CONTAINS 0 RECORDS RECORD CONTAINS 150 CHARACTERS. 01 EMPLOYEE-INPUT-RECORD. 05 EMP-ID PIC 9(6). 05 EMP-NAME PIC X(30). 05 EMP-DEPARTMENT PIC X(20). 05 EMP-POSITION PIC X(25). 05 EMP-SALARY PIC 9(7)V99. 05 EMP-HIRE-DATE PIC 9(8). 05 EMP-STATUS PIC X(10). 05 FILLER PIC X(40). FD PAYROLL-REPORT-FILE BLOCK CONTAINS 0 RECORDS RECORD CONTAINS 132 CHARACTERS. 01 PAYROLL-REPORT-RECORD PIC X(132). REPORT SECTION. RD PAYROLL-REPORT CONTROLS ARE FINAL EMP-DEPARTMENT PAGE LIMIT IS 66 LINES HEADING 1 FIRST DETAIL 8 LAST DETAIL 58 FOOTING 62. *> Report Header with FIRST positioning 01 REPORT-HEADER TYPE IS REPORT HEADING. 05 LINE NUMBER IS 1. 10 COLUMN 1 PIC X(25) VALUE 'EMPLOYEE PAYROLL REPORT'. 10 COLUMN 50 PIC X(10) VALUE 'PAGE'. 10 COLUMN 61 PIC ZZ9 SOURCE IS PAGE-COUNTER. 10 COLUMN 70 PIC X(5) VALUE 'DATE:'. 10 COLUMN 76 PIC X(10) SOURCE IS WS-CURRENT-DATE. 05 LINE NUMBER IS 2. 10 COLUMN 1 PIC X(80) VALUE ALL '='. 05 LINE NUMBER IS 4. 10 COLUMN 1 PIC X(6) VALUE 'EMP ID'. 10 COLUMN 10 PIC X(20) VALUE 'EMPLOYEE NAME'. 10 COLUMN 35 PIC X(15) VALUE 'DEPARTMENT'. 10 COLUMN 55 PIC X(15) VALUE 'POSITION'. 10 COLUMN 75 PIC X(10) VALUE 'SALARY'. 10 COLUMN 90 PIC X(10) VALUE 'HIRE DATE'. 10 COLUMN 105 PIC X(6) VALUE 'STATUS'. 05 LINE NUMBER IS 5. 10 COLUMN 1 PIC X(110) VALUE ALL '-'. *> Detail Line starting at FIRST DETAIL line 8 01 EMPLOYEE-DETAIL TYPE IS DETAIL. 05 LINE NUMBER IS PLUS 1. 10 COLUMN 1 PIC 9(6) SOURCE IS EMP-ID. 10 COLUMN 10 PIC X(20) SOURCE IS EMP-NAME. 10 COLUMN 35 PIC X(15) SOURCE IS EMP-DEPARTMENT. 10 COLUMN 55 PIC X(15) SOURCE IS EMP-POSITION. 10 COLUMN 75 PIC ZZZ,ZZ9.99 SOURCE IS EMP-SALARY. 10 COLUMN 90 PIC 99/99/9999 SOURCE IS WS-FORMATTED-DATE. 10 COLUMN 105 PIC X(6) SOURCE IS EMP-STATUS. WORKING-STORAGE SECTION. 01 FILE-STATUS-CODES. 05 INPUT-FILE-STATUS PIC XX. 88 INPUT-SUCCESS VALUE '00'. 88 INPUT-EOF VALUE '10'. 05 REPORT-FILE-STATUS PIC XX. 88 REPORT-SUCCESS VALUE '00'. 01 REPORT-CONTROL-VARIABLES. 05 WS-CURRENT-DATE PIC X(10). 05 WS-FORMATTED-DATE PIC 99/99/9999. 05 WS-EMPLOYEE-COUNT PIC 9(3) VALUE 1. PROCEDURE DIVISION. MAIN-PROCESSING. OPEN OUTPUT EMPLOYEE-INPUT-FILE OPEN OUTPUT PAYROLL-REPORT-FILE INITIATE PAYROLL-REPORT PERFORM UNTIL INPUT-EOF READ EMPLOYEE-INPUT-FILE AT END CONTINUE NOT AT END GENERATE EMPLOYEE-DETAIL END-READ END-PERFORM TERMINATE PAYROLL-REPORT CLOSE EMPLOYEE-INPUT-FILE CLOSE PAYROLL-REPORT-FILE STOP RUN.

Key Features and Benefits

Page Layout Control
  • • Defines starting position for detail lines
  • • Ensures consistent spacing after headers
  • • Controls vertical page utilization
  • • Maintains professional appearance
Report Writer Integration
  • • Works with HEADING clause
  • • Coordinates with LAST DETAIL
  • • Integrates with FOOTING positioning
  • • Supports automatic page breaks

Interactive Tutorial

Hands-On Exercise: Report Layout Design
Practice using FIRST DETAIL for optimal page layout

Exercise 1: Basic Page Layout

cobol
1
2
3
4
5
6
7
8
9
10
11
12
RD CUSTOMER-REPORT PAGE LIMIT IS 60 LINES HEADING 1 FIRST DETAIL 6 LAST DETAIL 52 FOOTING 56. *> This creates: *> Lines 1-5: Header area *> Lines 6-52: Detail area (47 lines available) *> Lines 53-55: Gap before footer *> Lines 56-60: Footer area

Exercise 2: Optimized Layout

cobol
1
2
3
4
5
6
7
8
9
10
11
12
RD SALES-REPORT PAGE LIMIT IS 66 LINES HEADING 1 FIRST DETAIL 8 LAST DETAIL 58 FOOTING 62. *> This provides: *> Lines 1-7: Extended header area *> Lines 8-58: Detail area (51 lines available) *> Lines 59-61: Footer buffer *> Lines 62-66: Footer area

Best Practices

Knowledge Check

Test Your Understanding

Question 1: Page Layout

If PAGE LIMIT IS 66 LINES, HEADING 1, and FOOTING 62, what's the optimal FIRST DETAIL setting?

Answer: FIRST DETAIL 6 or 8 would be optimal, allowing 4-6 lines for headers and maintaining good spacing before detail content begins.

Question 2: Error Prevention

What happens if FIRST DETAIL is set to line 3 with HEADING 1?

Answer: This creates insufficient space for headers, potentially causing overlapping content or formatting errors. Headers need adequate space before detail lines begin.

Question 3: Best Practice

How do you determine the optimal FIRST DETAIL line number?

Answer: Consider header content (titles, column headers, separators), control break headers, and visual spacing. Allow 2-3 buffer lines after the last header element.

Common Patterns

Standard Business Report
cobol
1
2
3
4
5
6
7
8
9
10
11
RD BUSINESS-REPORT PAGE LIMIT IS 66 LINES HEADING 1 FIRST DETAIL 8 LAST DETAIL 58 FOOTING 62. *> Provides: *> 7 lines for headers *> 51 lines for details *> 4 lines for footers
Compact Report Layout
cobol
1
2
3
4
5
6
7
8
9
10
11
RD COMPACT-REPORT PAGE LIMIT IS 60 LINES HEADING 1 FIRST DETAIL 6 LAST DETAIL 54 FOOTING 58. *> Provides: *> 5 lines for headers *> 49 lines for details *> 3 lines for footers

Frequently Asked Questions