MainframeMaster

COBOL Tutorial

Progress0 of 0 lessons

COBOL ADVANCING PAGE Clause

The ADVANCING PAGE clause is used in WRITE statements to control page breaks and form feeds.

Overview

The ADVANCING PAGE clause provides control over page formatting in output operations. It allows you to force page breaks and advance to the next page when writing output, which is essential for creating well-formatted reports and documents.

This clause is particularly useful for controlling the layout of printed output and ensuring that content is properly organized across multiple pages.

Syntax

cobol
1
WRITE record-name ADVANCING PAGE

Basic syntax for the ADVANCING PAGE clause. The record-name specifies what to write, and ADVANCING PAGE forces a page break.

Parameters

  • record-name: The record or data to be written to output
  • ADVANCING PAGE: Clause that forces a page break and advances to the next page

Practical Examples

Example 1: Basic Page Break

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. ADVANCING-PAGE-EXAMPLE. DATA DIVISION. WORKING-STORAGE SECTION. 01 PAGE-HEADER PIC X(80) VALUE "PAGE HEADER - REPORT TITLE". 01 DATA-LINE PIC X(80) VALUE "This is a data line in the report". 01 PAGE-FOOTER PIC X(80) VALUE "PAGE FOOTER - END OF PAGE". PROCEDURE DIVISION. MAIN-PROCESS. * Write page header WRITE PAGE-HEADER ADVANCING PAGE * Write some data lines WRITE DATA-LINE ADVANCING 1 LINE WRITE DATA-LINE ADVANCING 1 LINE WRITE DATA-LINE ADVANCING 1 LINE * Force another page break WRITE PAGE-HEADER ADVANCING PAGE * Write more data WRITE DATA-LINE ADVANCING 1 LINE WRITE PAGE-FOOTER ADVANCING 1 LINE STOP RUN.

This example demonstrates basic page break usage. The ADVANCING PAGE clause forces page breaks when writing page headers, creating a new page for each section of the report.

Example 2: Report with Multiple Pages

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
IDENTIFICATION DIVISION. PROGRAM-ID. MULTI-PAGE-REPORT. DATA DIVISION. WORKING-STORAGE SECTION. 01 REPORT-HEADER PIC X(80) VALUE "SALES REPORT - QUARTERLY SUMMARY". 01 SECTION-HEADER PIC X(80) VALUE "SECTION: PRODUCT SALES". 01 DATA-RECORD PIC X(80). 01 PAGE-NUMBER PIC 9(3) VALUE 1. PROCEDURE DIVISION. GENERATE-REPORT. * Start first page WRITE REPORT-HEADER ADVANCING PAGE * Write section header WRITE SECTION-HEADER ADVANCING 2 LINES * Simulate writing data records PERFORM WRITE-DATA-RECORDS * Start new page for next section ADD 1 TO PAGE-NUMBER WRITE REPORT-HEADER ADVANCING PAGE WRITE SECTION-HEADER ADVANCING 2 LINES STOP RUN. WRITE-DATA-RECORDS. MOVE "Product A - Sales: $1000" TO DATA-RECORD WRITE DATA-RECORD ADVANCING 1 LINE MOVE "Product B - Sales: $1500" TO DATA-RECORD WRITE DATA-RECORD ADVANCING 1 LINE MOVE "Product C - Sales: $2000" TO DATA-RECORD WRITE DATA-RECORD ADVANCING 1 LINE.

This example shows how to create a multi-page report using ADVANCING PAGE. Each major section starts on a new page, providing clear separation between different parts of the report.

Example 3: Formatted Document Output

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. FORMATTED-DOCUMENT. DATA DIVISION. WORKING-STORAGE SECTION. 01 DOCUMENT-TITLE PIC X(80) VALUE "COMPANY POLICY DOCUMENT". 01 CHAPTER-HEADER PIC X(80) VALUE "CHAPTER 1: INTRODUCTION". 01 PARAGRAPH-TEXT PIC X(80) VALUE "This is the first paragraph of the document.". 01 SECTION-BREAK PIC X(80) VALUE "----------------------------------------". PROCEDURE DIVISION. CREATE-DOCUMENT. * Document title page WRITE DOCUMENT-TITLE ADVANCING PAGE WRITE SECTION-BREAK ADVANCING 2 LINES * Chapter 1 WRITE CHAPTER-HEADER ADVANCING PAGE WRITE PARAGRAPH-TEXT ADVANCING 2 LINES WRITE PARAGRAPH-TEXT ADVANCING 2 LINES * Chapter 2 (new page) MOVE "CHAPTER 2: MAIN CONTENT" TO CHAPTER-HEADER WRITE CHAPTER-HEADER ADVANCING PAGE WRITE PARAGRAPH-TEXT ADVANCING 2 LINES STOP RUN.

This example demonstrates creating a formatted document with proper page breaks. Each chapter starts on a new page, and the document title has its own dedicated page.

Example 4: Conditional Page 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
29
30
31
IDENTIFICATION DIVISION. PROGRAM-ID. CONDITIONAL-PAGE-BREAKS. DATA DIVISION. WORKING-STORAGE SECTION. 01 LINE-COUNT PIC 9(3) VALUE 0. 01 MAX-LINES-PER-PAGE PIC 9(3) VALUE 60. 01 DATA-LINE PIC X(80) VALUE "This is a data line in the report". 01 PAGE-HEADER PIC X(80) VALUE "REPORT HEADER - PAGE ". 01 PAGE-NUMBER PIC 9(3) VALUE 1. PROCEDURE DIVISION. PROCESS-REPORT. * Write initial page header WRITE PAGE-HEADER ADVANCING PAGE ADD 1 TO LINE-COUNT * Process data with conditional page breaks PERFORM UNTIL LINE-COUNT >= 200 WRITE DATA-LINE ADVANCING 1 LINE ADD 1 TO LINE-COUNT * Check if page break is needed IF LINE-COUNT >= MAX-LINES-PER-PAGE ADD 1 TO PAGE-NUMBER WRITE PAGE-HEADER ADVANCING PAGE MOVE 1 TO LINE-COUNT END-IF END-PERFORM STOP RUN.

This example shows conditional page breaks based on line count. The program tracks the number of lines written and forces a page break when the maximum lines per page is reached.

Best Practices and Considerations

Best Practices

  • Use ADVANCING PAGE for major section breaks in reports
  • Plan page layout and line counts carefully
  • Use consistent page formatting throughout reports
  • Consider printer and output device capabilities
  • Test page breaks with actual output devices

Considerations

  • Output device compatibility and form feed handling
  • Page size and line count limitations
  • Performance implications of frequent page breaks
  • Integration with other formatting options
  • Cross-platform output consistency

Test Your Knowledge

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

  • To advance program execution
  • To control page breaks and form feeds in output
  • To advance file pointers
  • To advance memory allocation

2. In which statement is the ADVANCING PAGE clause most commonly used?

  • READ statement
  • WRITE statement
  • PERFORM statement
  • DISPLAY statement

3. What is the relationship between ADVANCING PAGE and output formatting?

  • They are unrelated
  • ADVANCING PAGE controls output page formatting
  • Output formatting enables ADVANCING PAGE
  • They are the same thing

4. When should you use the ADVANCING PAGE clause?

  • Only for file operations
  • When you need to control page breaks in formatted output
  • Only for error conditions
  • Only for display purposes

5. What happens when an ADVANCING PAGE clause is executed?

  • The program stops
  • A page break is forced and output advances to the next page
  • All files are closed
  • Memory is freed

Frequently Asked Questions