Line positioning in COBOL controls where report output appears: which line and, in some contexts, which column. You use the LINAGE clause to define the logical page (lines per page, footing area), and the WRITE statement with ADVANCING to move the print position (e.g. one line, or to the next page). Together they give you predictable report layout and page breaks.
For report files (e.g. printer or spooled output), LINAGE tells the run time how big a “page” is. You put it on the FD (file description). Typical form:
123456FD REPORT-FILE LINAGE IS 50 LINES WITH FOOTING AT 45 LINES AT TOP 5 LINES AT BOTTOM 3. 01 REPORT-LINE PIC X(132).
LINAGE IS 50 LINES – the logical page has 50 lines. WITH FOOTING AT 45 – the footing area starts at line 45 (so the body is lines 1–44). LINES AT TOP and LINES AT BOTTOM reserve margin lines. The run time tracks the current line and can trigger AT END-OF-PAGE when the next write would hit the footing. See AT END-OF-PAGE for using that in WRITE.
WRITE ... ADVANCING controls how the file position moves after (or before) writing a record. This gives you line-by-line spacing and page breaks.
| Option | Meaning |
|---|---|
| AFTER ADVANCING 1 LINE | Write the record, then advance one line |
| AFTER ADVANCING n LINES | Write, then advance n lines |
| AFTER ADVANCING PAGE | Write, then advance to the next page |
| BEFORE ADVANCING 1 LINE | Advance one line, then write |
12345678*> Write a line and then advance one line (next write on next line) WRITE REPORT-LINE AFTER ADVANCING 1 LINE *> Write a line and then advance to the next page WRITE REPORT-LINE AFTER ADVANCING PAGE *> Advance two lines, then write (blank line between) WRITE REPORT-LINE AFTER ADVANCING 2 LINES
For sequential report files, there is no COLUMN clause on WRITE. You build each line in working storage: move data into a long field (e.g. PIC X(132)) at the right positions, then WRITE that field. For example, move a title to positions 1–40, a page number to 70–72, and spaces everywhere else. Report Writer and screen I/O (e.g. SCREEN SECTION) may support LINE and COLUMN for direct positioning; check your compiler manual.
Imagine a notepad with a fixed number of lines per page. LINAGE says “this many lines per page.” Each time you write a line, you can say “then move to the next line” or “then turn to a new page.” Line positioning is those rules so your report doesn’t run off the page and new pages start where you expect.
1. What does AFTER ADVANCING PAGE do?
2. What is the LINAGE clause used for?