COBOL Std 2 Source-Code Layout: Difference between revisions

From Webhuis wiki
Jump to navigation Jump to search
(Created page with "== 2. Source-Code Layout == === 2.1 Column Format === All programs use fixed-format COBOL unless the project explicitly adopts free-format (<code>cobc -free</code>). In fixed format: {| class="wikitable" style="width:100%" ! Columns !! Area !! Rule |- | 1–6 || Sequence || Leave blank or use numeric sequence; never use for logic. |- | 7 || Indicator || Asterisk (<code>*</code>) = full-line comment. Hyphen (<code>-</code>) = continuation. Blank = code. |- | 8–11 ||...")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 52: Line 52:


----
----
''[[COBOL Programming Standard|← Back to index]]''
''[[Cobol programming standards|← Back to index]]''

Latest revision as of 11:10, 25 March 2026

2. Source-Code Layout[edit]

2.1 Column Format[edit]

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[edit]

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[edit]

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[edit]

  • 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.


← Back to index