Coding Format: Fixed & Free
Traditional COBOL is laid out for 80-column punched cards:
5.1 Fixed (reference) format
Traditional COBOL is laid out for 80-column punched cards:
Sequence number area Optional line numbers (ignored by modern compilers) blank = code; * = comment; / = comment + page eject in listing; - = continuation of a literal; D = debugging line
Division, section, and paragraph headers; level numbers 01, 77; FD, SD, RD; END PROGRAM
Statements, clauses, subordinate level numbers (05, 10…), continuation text
Ignored (historically: program name on each card) Rules of thumb:
Start headers at column 8 (7 spaces), statements at column 12 (11 spaces).
Nothing past column 72 — text in columns 73–80 is silently ignored, which causes subtle bugs.
COBOL is case-insensitive for keywords and names (move = MOVE); literals keep their case.
Columns: 1-6 7 8-11 12-72 73-80
Sequence Indicator Area A Area B Identification
number area (ignored)
1 2 3 4 5 6 7
1234567890123456789012345678901234567890123456789012345678901234567890123
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. COLUMNS.
000300*THIS IS A COMMENT LINE (ASTERISK IN COLUMN 7)
000400 PROCEDURE DIVISION.
000500 MAIN-PARA.
000600 DISPLAY "AREA B STARTS AT COLUMN 12".
000700 STOP RUN.5.2 Continuation lines
A long alphanumeric literal can be continued with a hyphen in column 7. The continued literal resumes after a quote in Area B:
The first line's literal runs through column 72 exactly (any spaces up to column 72 would become part of the value); the continuation line has - in column 7 and the literal resumes after the opening quote. Easier and clearer: concatenate with & (COBOL 2002, supported by GnuCOBOL and IBM):
01 WS-LONG PIC X(60) VALUE "THIS LITERAL IS CONTINUED ONTO TH
- "E NEXT LINE".01 WS-LONG-TEXT PIC X(80) VALUE "THIS IS A VERY LONG "
& "LITERAL ON TWO LINES".5.3 Free format
COBOL 2002 introduced free-format source: no column restrictions, *> starts a comment anywhere, lines up to 255+ characters (implementation-dependent).
You can also switch format inside a source file with a compiler directive (starting in column 8 or later in fixed format):
IBM note: mainframe shops use fixed format almost universally; check your Enterprise COBOL release documentation before relying on free-format directives. The *> floating comment is widely supported in fixed format too (GnuCOBOL and Enterprise COBOL 6.x).
*> hello-free.cob -- compile with: cobc -x -free hello-free.cob
identification division.
program-id. hello-free.
procedure division.
display "Free-format COBOL!" *> inline comment
stop run.>>SOURCE FORMAT IS FREE