MainframeMaster
MainframeMaster

COBOL Tutorial

Progress0 of 0 lessons

COBOL Page Layout

Page layout in COBOL refers to the design and structure of printed report pages, including the arrangement of headers, footers, margins, spacing, and content positioning. Good page layout ensures reports are professional, readable, and consistent across all pages. Understanding page layout is essential for creating well-formatted reports that are easy to read, properly paginated, and suitable for business use in mainframe COBOL applications.

What is Page Layout?

Page layout encompasses the visual design and organization of report pages:

  • Headers: Information at the top of each page (titles, dates, page numbers)
  • Footers: Information at the bottom of each page (page numbers, totals, notices)
  • Margins: Blank spaces at top, bottom, left, and right edges
  • Spacing: Vertical spacing between sections and lines
  • Content area: The main body where detail lines appear
  • Page breaks: Where new pages begin
  • Alignment: How text and data are positioned horizontally

Effective page layout creates visual hierarchy, improves readability, and provides consistent structure throughout the report.

Standard Page Dimensions

Understanding standard page dimensions helps design appropriate layouts:

Standard COBOL Page Dimensions
AspectStandard ValueDescription
Lines per page66 linesStandard for 11-inch paper at 6 lines per inch
Characters per line132 charactersStandard for wide carriage printers
Alternative lines60 linesCommon for letter-size paper
Header area5-10 linesTypical space reserved for headers
Footer area3-5 linesTypical space reserved for footers
Body area50-58 linesRemaining space for detail lines

Designing Page Headers

Page headers appear at the top of each page and provide context and identification:

Header Components

Effective headers typically include:

  • Report title: The name of the report, often centered
  • Date and time: When the report was generated
  • Page numbers: Current page and total pages (if known)
  • Column headers: Labels for data columns
  • Separator lines: Underlines or borders to separate header from body
  • Company/Department: Organizational identification

Example: Professional Header Design

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
WORKING-STORAGE SECTION. 01 WS-PAGE-HEADER. 05 WS-HEADER-LINE-1. 10 FILLER PIC X(51) VALUE SPACES. 10 FILLER PIC X(30) VALUE 'EMPLOYEE COMPENSATION REPORT'. 10 FILLER PIC X(51) VALUE SPACES. 05 WS-HEADER-LINE-2. 10 FILLER PIC X(10) VALUE 'DATE: '. 10 WS-REPORT-DATE PIC X(10). 10 FILLER PIC X(15) VALUE SPACES. 10 FILLER PIC X(10) VALUE 'TIME: '. 10 WS-REPORT-TIME PIC X(8). 10 FILLER PIC X(15) VALUE SPACES. 10 FILLER PIC X(6) VALUE 'PAGE: '. 10 WS-PAGE-NUM PIC ZZZ9. 10 FILLER PIC X(4) VALUE ' OF '. 10 WS-TOTAL-PAGES PIC ZZZ9. 10 FILLER PIC X(40) VALUE SPACES. 05 WS-HEADER-LINE-3. 10 FILLER PIC X(132) VALUE SPACES. 05 WS-COLUMN-HEADER-1. 10 FILLER PIC X(8) VALUE 'EMP ID'. 10 FILLER PIC X(2) VALUE SPACES. 10 FILLER PIC X(20) VALUE 'EMPLOYEE NAME'. 10 FILLER PIC X(2) VALUE SPACES. 10 FILLER PIC X(15) VALUE 'DEPARTMENT'. 10 FILLER PIC X(2) VALUE SPACES. 10 FILLER PIC X(12) VALUE 'SALARY'. 10 FILLER PIC X(71) VALUE SPACES. 05 WS-COLUMN-HEADER-2. 10 FILLER PIC X(132) VALUE ALL '-'. PROCEDURE DIVISION. WRITE-PAGE-HEADER. *> Get current date and time ACCEPT WS-REPORT-DATE FROM DATE YYYYMMDD ACCEPT WS-REPORT-TIME FROM TIME *> Format date MOVE WS-REPORT-DATE(5:2) TO WS-FORMATTED-DATE(1:2) MOVE '/' TO WS-FORMATTED-DATE(3:1) MOVE WS-REPORT-DATE(7:2) TO WS-FORMATTED-DATE(4:2) MOVE '/' TO WS-FORMATTED-DATE(6:1) MOVE WS-REPORT-DATE(1:4) TO WS-FORMATTED-DATE(7:4) *> Format time MOVE WS-REPORT-TIME(1:2) TO WS-FORMATTED-TIME(1:2) MOVE ':' TO WS-FORMATTED-TIME(3:1) MOVE WS-REPORT-TIME(3:2) TO WS-FORMATTED-TIME(4:2) MOVE ':' TO WS-FORMATTED-TIME(6:1) MOVE WS-REPORT-TIME(5:2) TO WS-FORMATTED-TIME(7:2) *> Set page numbers MOVE WS-CURRENT-PAGE TO WS-PAGE-NUM MOVE WS-TOTAL-PAGES TO WS-TOTAL-PAGES *> Write header lines WRITE REPORT-LINE FROM WS-HEADER-LINE-1 AFTER ADVANCING PAGE WRITE REPORT-LINE FROM WS-HEADER-LINE-2 AFTER ADVANCING 1 LINE WRITE REPORT-LINE FROM WS-HEADER-LINE-3 AFTER ADVANCING 1 LINE WRITE REPORT-LINE FROM WS-COLUMN-HEADER-1 AFTER ADVANCING 1 LINE WRITE REPORT-LINE FROM WS-COLUMN-HEADER-2 AFTER ADVANCING 1 LINE WRITE REPORT-LINE FROM SPACES AFTER ADVANCING 1 LINE *> Reset line counter MOVE 6 TO WS-LINE-COUNT.

This header design includes:

  • Centered title on the first line (calculated padding on both sides)
  • Date, time, and page information on the second line
  • Blank line for spacing
  • Column headers identifying data columns
  • Separator line (dashes) to visually separate header from body
  • Another blank line before detail lines begin

Designing Page Footers

Page footers appear at the bottom of each page and provide summary information or page identification:

Footer Components

Common footer elements include:

  • Page numbers: Current page and total pages
  • Separator lines: Visual separation from body content
  • Totals or summaries: Page-level totals (if applicable)
  • Continuation messages: "Continued on next page" indicators
  • Confidentiality notices: Security or classification labels
  • Report identification: Report name or number

Example: Professional Footer Design

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
WORKING-STORAGE SECTION. 01 WS-PAGE-FOOTER. 05 WS-FOOTER-LINE-1. 10 FILLER PIC X(132) VALUE ALL '-'. 05 WS-FOOTER-LINE-2. 10 FILLER PIC X(50) VALUE SPACES. 10 FILLER PIC X(6) VALUE 'PAGE: '. 10 WS-FOOTER-PAGE PIC ZZZ9. 10 FILLER PIC X(4) VALUE ' OF '. 10 WS-FOOTER-TOTAL PIC ZZZ9. 10 FILLER PIC X(20) VALUE SPACES. 10 FILLER PIC X(20) VALUE 'CONFIDENTIAL REPORT'. 10 FILLER PIC X(22) VALUE SPACES. PROCEDURE DIVISION. WRITE-PAGE-FOOTER. *> Position to footer area (if not using LINAGE) COMPUTE WS-LINES-TO-FOOTER = WS-MAX-LINES - WS-LINE-COUNT IF WS-LINES-TO-FOOTER > 0 WRITE REPORT-LINE FROM SPACES AFTER ADVANCING WS-LINES-TO-FOOTER LINES END-IF *> Write footer lines MOVE WS-CURRENT-PAGE TO WS-FOOTER-PAGE MOVE WS-TOTAL-PAGES TO WS-FOOTER-TOTAL WRITE REPORT-LINE FROM WS-FOOTER-LINE-1 AFTER ADVANCING 1 LINE WRITE REPORT-LINE FROM WS-FOOTER-LINE-2 AFTER ADVANCING 1 LINE.

Controlling Margins

Margins provide space around page content and are controlled using LINAGE:

Using LINAGE for Margins

cobol
1
2
3
4
5
6
7
8
9
10
11
12
FD REPORT-FILE LINAGE IS 66 LINES WITH FOOTING AT 60 LINES AT TOP 6 LINES AT BOTTOM 4. *> This defines: *> - Total page: 66 lines *> - Top margin (header area): 6 lines (lines 1-6) *> - Body area: Lines 7-59 (53 lines available) *> - Footer area starts: Line 60 *> - Bottom margin: 4 lines (lines 60-63, plus 3 lines buffer)

LINAGE parameters:

  • LINAGE IS n: Total lines per page
  • LINES AT TOP m: Lines reserved for header area (top margin)
  • WITH FOOTING AT k: Line where footer area begins
  • LINES AT BOTTOM p: Lines reserved for bottom margin

Left and Right Margins

Left and right margins are controlled by positioning data within the record:

cobol
1
2
3
4
5
6
7
8
9
10
11
*> Left margin: Start data after initial spaces 01 WS-DETAIL-LINE. 05 FILLER PIC X(5) VALUE SPACES. *> Left margin 05 WS-DATA-FIELD PIC X(30). 05 FILLER PIC X(97) VALUE SPACES. *> Right margin *> Or center data with equal margins: 01 WS-CENTERED-LINE. 05 FILLER PIC X(51) VALUE SPACES. *> Left padding 05 WS-CENTERED-TEXT PIC X(30). 05 FILLER PIC X(51) VALUE SPACES. *> Right padding

Spacing and Alignment

Proper spacing and alignment improve readability:

Vertical Spacing

Control vertical spacing between sections:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
*> Single line spacing WRITE REPORT-LINE FROM DETAIL-LINE AFTER ADVANCING 1 LINE *> Double line spacing WRITE REPORT-LINE FROM DETAIL-LINE AFTER ADVANCING 2 LINES *> Blank line for separation WRITE REPORT-LINE FROM SPACES AFTER ADVANCING 1 LINE *> Multiple blank lines PERFORM 3 TIMES WRITE REPORT-LINE FROM SPACES AFTER ADVANCING 1 LINE END-PERFORM

Horizontal Alignment

Align data within columns:

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
*> Left-aligned text 01 WS-LEFT-ALIGNED. 05 WS-TEXT PIC X(20). 05 FILLER PIC X(112) VALUE SPACES. *> Right-aligned numbers 01 WS-RIGHT-ALIGNED. 05 FILLER PIC X(100) VALUE SPACES. 05 WS-AMOUNT PIC $ZZ,ZZZ,ZZ9.99. 05 FILLER PIC X(20) VALUE SPACES. *> Centered text 01 WS-CENTERED. 05 FILLER PIC X(51) VALUE SPACES. 05 WS-TITLE PIC X(30). 05 FILLER PIC X(51) VALUE SPACES.

Page Break Control

Proper page break control ensures content doesn't overflow and pages break at appropriate points:

Manual Page Break Control

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
WORKING-STORAGE SECTION. 01 WS-PAGE-CONTROL. 05 WS-LINE-COUNT PIC 9(3) VALUE 0. 05 WS-MAX-LINES PIC 9(3) VALUE 55. 05 WS-HEADER-LINES PIC 9(2) VALUE 6. 05 WS-FOOTER-LINES PIC 9(2) VALUE 3. PROCEDURE DIVISION. CHECK-PAGE-BREAK. *> Check if we need a new page IF WS-LINE-COUNT >= WS-MAX-LINES PERFORM WRITE-PAGE-FOOTER ADD 1 TO WS-CURRENT-PAGE PERFORM WRITE-PAGE-HEADER MOVE WS-HEADER-LINES TO WS-LINE-COUNT END-IF. WRITE-DETAIL-LINE. PERFORM CHECK-PAGE-BREAK *> Format and write detail line MOVE DATA-FIELDS TO WS-DETAIL-LINE WRITE REPORT-LINE FROM WS-DETAIL-LINE AFTER ADVANCING 1 LINE ADD 1 TO WS-LINE-COUNT.

Using LINAGE for Automatic Page Breaks

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
FD REPORT-FILE LINAGE IS 66 LINES WITH FOOTING AT 60 LINES AT TOP 6 LINES AT BOTTOM 4. PROCEDURE DIVISION. WRITE-DETAIL-LINE. WRITE REPORT-LINE FROM WS-DETAIL-LINE AT END-OF-PAGE PERFORM HANDLE-PAGE-OVERFLOW END-WRITE. HANDLE-PAGE-OVERFLOW. *> Write footer for completed page PERFORM WRITE-PAGE-FOOTER *> Start new page with header ADD 1 TO WS-CURRENT-PAGE PERFORM WRITE-PAGE-HEADER.

Complete Page Layout Example

Here's a complete example demonstrating professional page layout:

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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
IDENTIFICATION DIVISION. PROGRAM-ID. PAGE-LAYOUT-DEMO. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT REPORT-FILE ASSIGN TO PRINTER ORGANIZATION IS SEQUENTIAL. DATA DIVISION. FILE SECTION. FD REPORT-FILE LINAGE IS 66 LINES WITH FOOTING AT 60 LINES AT TOP 6 LINES AT BOTTOM 4. 01 REPORT-LINE PIC X(132). WORKING-STORAGE SECTION. 01 WS-PAGE-CONTROL. 05 WS-CURRENT-PAGE PIC 9(4) VALUE 1. 05 WS-LINE-COUNT PIC 9(3) VALUE 0. 05 WS-MAX-BODY-LINES PIC 9(3) VALUE 54. 01 WS-HEADER. 05 WS-HEADER-1. 10 FILLER PIC X(46) VALUE SPACES. 10 FILLER PIC X(40) VALUE 'EMPLOYEE COMPENSATION ANALYSIS'. 10 FILLER PIC X(46) VALUE SPACES. 05 WS-HEADER-2. 10 FILLER PIC X(10) VALUE 'DATE: '. 10 WS-DATE PIC X(10). 10 FILLER PIC X(15) VALUE SPACES. 10 FILLER PIC X(6) VALUE 'PAGE: '. 10 WS-PAGE PIC ZZZ9. 10 FILLER PIC X(87) VALUE SPACES. 05 WS-HEADER-3. 10 FILLER PIC X(132) VALUE SPACES. 05 WS-COL-HEADER. 10 FILLER PIC X(8) VALUE 'EMP ID'. 10 FILLER PIC X(2) VALUE SPACES. 10 FILLER PIC X(20) VALUE 'NAME'. 10 FILLER PIC X(2) VALUE SPACES. 10 FILLER PIC X(15) VALUE 'DEPARTMENT'. 10 FILLER PIC X(2) VALUE SPACES. 10 FILLER PIC X(12) VALUE 'SALARY'. 10 FILLER PIC X(71) VALUE SPACES. 05 WS-UNDERLINE. 10 FILLER PIC X(132) VALUE ALL '-'. 01 WS-FOOTER. 05 WS-FOOTER-1. 10 FILLER PIC X(132) VALUE ALL '-'. 05 WS-FOOTER-2. 10 FILLER PIC X(60) VALUE SPACES. 10 FILLER PIC X(6) VALUE 'PAGE: '. 10 WS-FOOT-PAGE PIC ZZZ9. 10 FILLER PIC X(4) VALUE ' OF '. 10 WS-FOOT-TOTAL PIC ZZZ9. 10 FILLER PIC X(50) VALUE SPACES. 01 WS-DETAIL-LINE. 05 WS-EMP-ID PIC X(8). 05 FILLER PIC X(2) VALUE SPACES. 05 WS-EMP-NAME PIC X(20). 05 FILLER PIC X(2) VALUE SPACES. 05 WS-DEPT PIC X(15). 05 FILLER PIC X(2) VALUE SPACES. 05 WS-SALARY PIC $ZZ,ZZZ,ZZ9.99. 05 FILLER PIC X(83) VALUE SPACES. PROCEDURE DIVISION. MAIN-PARA. OPEN OUTPUT REPORT-FILE PERFORM WRITE-PAGE-HEADER PERFORM PROCESS-DATA PERFORM WRITE-PAGE-FOOTER CLOSE REPORT-FILE STOP RUN. WRITE-PAGE-HEADER. *> Get current date ACCEPT WS-DATE FROM DATE YYYYMMDD *> Format date (simplified) MOVE WS-DATE TO WS-FORMATTED-DATE *> Set page number MOVE WS-CURRENT-PAGE TO WS-PAGE *> Write header WRITE REPORT-LINE FROM WS-HEADER-1 AFTER ADVANCING PAGE WRITE REPORT-LINE FROM WS-HEADER-2 AFTER ADVANCING 1 LINE WRITE REPORT-LINE FROM WS-HEADER-3 AFTER ADVANCING 1 LINE WRITE REPORT-LINE FROM WS-COL-HEADER AFTER ADVANCING 1 LINE WRITE REPORT-LINE FROM WS-UNDERLINE AFTER ADVANCING 1 LINE WRITE REPORT-LINE FROM SPACES AFTER ADVANCING 1 LINE MOVE 6 TO WS-LINE-COUNT. CHECK-PAGE-BREAK. IF WS-LINE-COUNT >= WS-MAX-BODY-LINES PERFORM WRITE-PAGE-FOOTER ADD 1 TO WS-CURRENT-PAGE PERFORM WRITE-PAGE-HEADER END-IF. WRITE-PAGE-FOOTER. *> Position to footer COMPUTE WS-LINES-TO-SKIP = WS-MAX-BODY-LINES - WS-LINE-COUNT IF WS-LINES-TO-SKIP > 0 WRITE REPORT-LINE FROM SPACES AFTER ADVANCING WS-LINES-TO-SKIP LINES END-IF MOVE WS-CURRENT-PAGE TO WS-FOOT-PAGE MOVE WS-TOTAL-PAGES TO WS-FOOT-TOTAL WRITE REPORT-LINE FROM WS-FOOTER-1 AFTER ADVANCING 1 LINE WRITE REPORT-LINE FROM WS-FOOTER-2 AFTER ADVANCING 1 LINE. PROCESS-DATA. *> Process and write detail lines PERFORM UNTIL END-OF-DATA PERFORM CHECK-PAGE-BREAK *> Get data and format MOVE EMP-ID TO WS-EMP-ID MOVE EMP-NAME TO WS-EMP-NAME MOVE EMP-DEPT TO WS-DEPT MOVE EMP-SALARY TO WS-SALARY WRITE REPORT-LINE FROM WS-DETAIL-LINE AFTER ADVANCING 1 LINE ADD 1 TO WS-LINE-COUNT *> Read next record... END-PERFORM.

Best Practices for Page Layout

Follow these best practices for effective page layout:

  • Consistent headers and footers: Use the same header and footer design on every page for consistency
  • Reserve adequate margins: Leave sufficient space for headers (5-10 lines) and footers (3-5 lines)
  • Center important titles: Center report titles and major section headings for visual impact
  • Use separator lines: Use underlines or dashes to separate headers from body content
  • Align columns consistently: Keep data columns aligned across all pages
  • Check page breaks: Avoid breaking related information across pages when possible
  • Include page numbers: Always include page numbers in headers or footers
  • Use appropriate spacing: Provide adequate spacing between sections for readability
  • Test with actual data: Test your layout with real data volumes to ensure it works correctly
  • Document layout decisions: Comment your code to explain layout choices and calculations

Common Page Layout Patterns

Pattern 1: Simple Report Layout

cobol
1
2
3
4
*> Header: 3 lines (title, date/page, underline) *> Body: 50 lines available *> Footer: 2 lines (separator, page number) *> Total: 55 lines per page

Pattern 2: Detailed Report Layout

cobol
1
2
3
4
5
*> Header: 8 lines (title, subtitle, date/time, *> page info, blank, column headers, underline, blank) *> Body: 48 lines available *> Footer: 4 lines (blank, separator, page info, blank) *> Total: 60 lines per page

Pattern 3: Financial Report Layout

cobol
1
2
3
4
5
6
7
*> Header: 10 lines (company info, report title, *> period info, date/time, page, blank, *> column headers, underline, blank) *> Body: 50 lines available *> Footer: 6 lines (blank, totals, separator, *> page info, confidentiality, blank) *> Total: 66 lines per page

Explain Like I'm 5: Page Layout

Think of page layout like setting up a picture frame:

  • Headers are like the title at the top of a picture - they tell you what the picture (report) is about
  • Footers are like the signature at the bottom - they add important information like page numbers
  • Margins are like the frame around the picture - they give space so nothing gets cut off
  • Spacing is like the gaps between things in the picture - they help you see everything clearly
  • Page breaks are like turning to the next page in a book - they make sure everything fits nicely

So page layout is like arranging everything on a page so it looks nice, fits properly, and is easy to read - just like framing a picture!

Practice Exercises

Complete these exercises to reinforce your understanding:

Exercise 1: Basic Header Design

Create a program that writes a simple page header with a centered title, current date, and page number. Use appropriate spacing and formatting.

Exercise 2: Complete Page Layout

Design a complete page layout with headers (6 lines), body area (50 lines), and footers (4 lines). Include proper margins, column headers, and page break control.

Exercise 3: Centered Text

Write a program that centers a report title in a 132-character line. Calculate the padding needed and demonstrate left, center, and right alignment.

Exercise 4: Page Break Logic

Create a program that processes 200 detail records with proper page break control. Each page should have 50 detail lines, and the program should handle page breaks correctly.

Exercise 5: Professional Footer

Design a professional footer that includes page numbers (current and total), a separator line, and a confidentiality notice. Position it correctly at the bottom of each page.

Test Your Knowledge

1. What does page layout in COBOL refer to?

  • The arrangement of data in memory
  • The design and structure of printed report pages
  • The organization of files
  • The structure of COBOL programs

2. What is the standard number of lines per page in COBOL?

  • 50 lines
  • 60 lines
  • 66 lines
  • 80 lines

3. How do you control top and bottom margins in COBOL?

  • Using MARGIN clauses
  • Using LINAGE with LINES AT TOP and LINES AT BOTTOM
  • Using SPACE statements
  • Using FILLER only

4. What should page headers typically include?

  • Only the report title
  • Report title, date, page number, and column headers
  • Only page numbers
  • Only dates

5. How do you center text in a COBOL report line?

  • Use CENTER statement
  • Calculate (record-width - text-length) / 2 and use FILLER for padding
  • Use ALIGN CENTER
  • Text is always centered automatically

6. When should you trigger a page break?

  • After every 10 lines
  • When the line counter reaches the maximum lines per page
  • Never - COBOL handles it automatically
  • Only at the end of the report

Related Concepts

Related Pages