COBOL Std 9 Output Formatting Rules
Jump to navigation
Jump to search
9. Output Formatting Rules[edit]
9.1 Print File Definition[edit]
- Every print file must have an explicit LINAGE clause specifying lines-per-page, footing area, and bottom margin.
- Record length must be stated explicitly in the FD; for report files, 132 characters is the baseline.
- FILE STATUS must be checked after every OPEN, WRITE, and CLOSE.
9.2 Page Layout[edit]
| Element | Rule |
|---|---|
| Page heading | Written on the first line after a new-page trigger. Carries report title. |
| Column header | Written immediately after the page heading. Column names must match the data. |
| Data lines | Zero-suppress numeric fields (PIC Z(9) or Z(3)9). Pad with at least 2 spaces between columns.
|
| End-of-page trigger | Fire EOP processing at linage-counter = (lines-per-page − footing-area − 1).
|
| Page footing | Right-aligned page number in format page: ZZZZ9. Increment page counter after writing.
|
9.3 New-Page Flag Pattern[edit]
Control page breaks with a numeric flag (SW-NEW-PAGE) rather than compiler-specific ADVANCE:
<syntaxhighlight lang="cobol">
03 SW-NEW-PAGE PIC 9 VALUE 1.
88 NEW-PAGE-NEEDED VALUE 1.
88 NO-NEW-PAGE VALUE 0.
</syntaxhighlight>
Set SW-NEW-PAGE = 1 at initialisation and after writing each page footing; clear to 0 after writing the heading.
9.4 Partial-Line Flush on Close[edit]
When the UI "stop" method is invoked, pad remaining print columns with zeros (or spaces for string data) and keep calling the write paragraph until the new-page flag fires. This guarantees the last partial data line is always written before CLOSE.
9.5 Console Logging[edit]
- Route all structured log messages through the UI program's log-message method (
DISPLAY process-message UPON scherm). - DISPLAY directly upon scherm is permitted only for emergency abort messages and low-level SQL diagnostic dumps.
- Structured messages must carry: program-name, paragraph-name, and a human-readable message of up to 92 characters.