Print formatting in COBOL is how you build each line that goes to a printer or report file and how you control where that line appears (single space, double space, new page). It involves: (1) defining a record layout with fixed column positions, (2) using edited PICTURE clauses so numbers print with commas, currency, and no leading zeros, (3) placing an ASA control character in the first byte to tell the printer how many lines to advance before printing, and (4) using WRITE with BEFORE or AFTER ADVANCING to control line and page advances. This page covers building the content of each line and the basics of ADVANCING; for full report structure (headings, LINAGE, page breaks) see Report Writing.
Imagine you are filling in a form: you write the title at the top, then one line per person, and you leave a blank line between sections. Print formatting is telling the computer exactly what to put in each line (names, numbers with commas and dollar signs) and whether to leave one blank line, two, or start a new page. The first character of each line is a secret instruction to the printer: "move down one line" or "move down two" or "go to the next page." The printer follows that and then prints the rest of the line.
A print line is usually a fixed-length record (e.g. 132 bytes for a wide printer). You define it in the FD or in working storage and build it before writing. To align columns you either define group items at specific positions or use reference modification. For example, if the name should start at column 1 and the amount at column 41, you can define a layout with FILLER and named fields at those positions, or use MOVE name TO report-line(1:30) and MOVE edited-amount TO report-line(41:12). Keeping positions in constants or a copybook helps when you change column layout later.
12345678910111201 REPORT-LINE. 05 RL-CTL PIC X(1). *> ASA control (space, 0, -, +, 1) 05 RL-NAME PIC X(30). *> cols 2-31 05 FILLER PIC X(9) VALUE SPACES. 05 RL-AMOUNT PIC ZZ,ZZZ,ZZ9.99. *> cols 41-52, edited 05 FILLER PIC X(80) VALUE SPACES. *> Build line: single space, name, then edited amount MOVE SPACE TO RL-CTL MOVE CUST-NAME TO RL-NAME MOVE WS-AMOUNT TO RL-AMOUNT WRITE REPORT-REC FROM REPORT-LINE AFTER ADVANCING 1 LINE
On many mainframe printers, the first character of each record is not printed; it is the ASA (American Standards Association) carriage control character. The device uses it to decide how many lines to advance before printing the rest of the record. If you send the record to a dataset that is printed with a driver that interprets ASA, the first byte is consumed and the rest of the line is printed at the new position.
| Character | Action | Typical use |
|---|---|---|
| Space (blank) | Advance 1 line, then print. | Normal single-spaced lines. |
| 0 | Advance 2 lines, then print. | Double space between lines. |
| - (minus) | Advance 3 lines, then print. | Triple space; leave two blank lines. |
| + (plus) | No advance; print over current line. | Overstrike (e.g. bold by printing twice). |
| 1 | Advance to top of next page, then print. | New page; first line on next page. |
Space (blank) is the usual choice for normal single-spaced lines. Use 0 for double space and - for triple space when you want gaps between sections. Plus (+) means no advance: the line is printed on top of the current line (overstrike). One (1) ejects to the next page and then prints, so the record becomes the first line on the new page. Some environments use different conventions or omit ASA; check your runtime and printer setup. When browsing the dataset in an editor, the first column will show these characters; they may not appear on the physical print if the device strips them.
Internal numeric fields use PICTUREs like 9(7)V99 or S9(5). For printed output you want readable format: no leading zeros (use Z), optional dollar sign ($), commas (,) and a decimal point (.). You define a separate receiving field with an edited PICTURE and MOVE the numeric value to it; the MOVE does the conversion and editing. The result is then placed into the report line (or is the report line).
12345601 WS-AMOUNT PIC S9(7)V99. 01 WS-EDITED PIC +++,+++,++9.99. MOVE 1234567.89 TO WS-AMOUNT MOVE WS-AMOUNT TO WS-EDITED *> Result: +1,234,567.89 MOVE WS-EDITED TO RL-AMOUNT *> into report line
For sequential report files you use WRITE with BEFORE or AFTER ADVANCING to control vertical position. AFTER ADVANCING 1 LINE advances one line and then writes the record; that is the normal way to print one line per WRITE. AFTER ADVANCING n LINES (or identifier LINES) skips n lines before writing. AFTER ADVANCING PAGE ejects to the next page and then writes (good for the first line on a new page, e.g. a heading). BEFORE ADVANCING PAGE writes the record and then ejects (good for the last line on the current page). ADVANCING is only valid for sequential (and line-sequential) files, not VSAM.
| Form | Effect | Typical use |
|---|---|---|
| AFTER ADVANCING 1 LINE | Advance one line, then write record. | Each WRITE on next line. |
| AFTER ADVANCING n LINES | Advance n lines, then write. | Skip lines or leave gaps. |
| AFTER ADVANCING PAGE | Eject to next page, then write. | First line on new page (e.g. heading). |
| BEFORE ADVANCING PAGE | Write record, then eject. | Last line on page, then new page. |
Traditional mainframe printers use 132-column lines. Your report record is often PIC X(132) or a structure that totals 132 bytes. The first byte is ASA; the remaining 131 are visible. Define the layout so that each field starts and ends at known positions. For example, columns 1–30 for name, 31–39 blank, 40–52 for amount. Use FILLER PIC X(n) for gaps. When you MOVE a value into a field that is shorter than the source, data is truncated; when the source is shorter, the rest of the field is often space-filled (depending on the type of move). For edited numeric fields, the PICTURE length determines how many characters are produced (e.g. ZZ,ZZZ,ZZ9.99 is 12 characters including comma and period). Ensure the report line is long enough so that no data overflows.
ADVANCING is a COBOL WRITE option: it tells the runtime how to advance the logical position (line or page) when the record is written. ASA is a convention for the first byte of the record: the device (or print driver) interprets that byte and may advance the paper or form accordingly. In some setups both are used: you use WRITE AFTER ADVANCING 1 LINE for normal flow, and still set the first byte to space so that if the file is printed elsewhere, the control character is correct. In other setups only one of the two is relevant (e.g. only ADVANCING, or only ASA). Check your environment.
1. The first byte of a print record is often used for:
2. To get a number to print with commas and no leading zeros you use:
3. WRITE ... AFTER ADVANCING 1 LINE means: