COBOL Std 2 Source-Code Layout
Jump to navigation
Jump to search
2. Source-Code Layout
2.1 Column Format
All programs use fixed-format COBOL unless the project explicitly adopts free-format (cobc -free). In fixed format:
| Columns | Area | Rule |
|---|---|---|
| 1–6 | Sequence | Leave blank or use numeric sequence; never use for logic. |
| 7 | Indicator | Asterisk (*) = full-line comment. Hyphen (-) = continuation. Blank = code.
|
| 8–11 | Area A | Division / section / paragraph headers; 01 and 77 level items; FD entries. |
| 12–72 | Area B | All other data definitions and procedural statements. |
2.2 Indentation
Indent subordinate levels by 4 spaces relative to their parent. Do not use tab characters.
<syntaxhighlight lang="cobol">
01 WS-CUSTOMER-RECORD.
05 WS-CUST-ID PIC X(6).
05 WS-CUST-NAME PIC X(40).
05 WS-CUST-BALANCE PIC S9(9)V99 COMP-3.
</syntaxhighlight>
Nested IF / EVALUATE constructs add 4 spaces per level:
<syntaxhighlight lang="cobol">
EVALUATE TRUE
WHEN dal-method-ok
PERFORM R080-PROCESS-RECORD
WHEN OTHER
PERFORM E000-HANDLE-ERROR
END-EVALUATE
</syntaxhighlight>
2.3 Line Length
Keep all code within columns 8–72 (Area A/B combined). Comments may use columns 8–72 as well. Do not rely on the reference area (73–80).
2.4 Blank Lines and Section Separators
- One blank comment line before every paragraph header.
- Three asterisk-border comment lines before every major section (see §3).
- Use the compiler directive
/(slash in column 7) to eject to a new listing page between major sections.