COBOL is a modular programming language.
Modules can be:
main program (obligatory, this starts when a program starts)
subroutine (subprogram; the main program can call it, organized to have re-usability and simplicity)
utility module (contains routines as tools, re-usable between the main program and its subroutines)
library module (part of COBOL, organized into library packages; a program can call any routines from a library)
A COBOL program is hierarchical. Parts are:
DIVISION
SECTION
PARAGRAPH
SENTENCE
STATEMENT
WORD
Not all children must be present in a parent.
To define a program, only the IDENTIFICATION DIVISION is required.
To define a COBOL class or method, you need to define some divisions differently than you do for a program.
FIGURE OF COBOL HIERARCHY:
A division is the highest‑level structural unit of a COBOL program, grouping together a complete functional area such as environment description, data definitions, or executable logic.
Key characteristics:
only four exist, in order: IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE
must start in Area A
contains sections, paragraphs, and statements
only the IDENTIFICATION DIVISION is mandatory
Contains:
one or more SECTIONS (optional depending on division)
or directly PARAGRAPHS
EXAMPLE FOR DIVISION:
A section is a named subdivision within a division that groups logically related paragraphs or declarations.
Key characteristics:
optional in most divisions
must start in Area A
ends when the next section or division begins
used for organization and readability
Contains:
one or more PARAGRAPHS
or directly STATEMENTS (rare but allowed)
EXAMPLE FOR SECTION:
A paragraph is a named block of code or declarations that performs a specific task or contains a specific set of statements.
Key characteristics:
begins with a paragraph name followed by a period
can contain one or more sentences
often the unit executed by PERFORM
used heavily in PROCEDURE DIVISION
Contains:
one or more SENTENCES
or directly STATEMENTS
EXAMPLE FOR PARAGRAPH:
A sentence starts with the first word and ends with a period, forming a complete executable unit within a paragraph.
Key characteristics:
always ends with a period
groups statements into a logical execution block
a paragraph may contain multiple sentences
Contains:
one or more STATEMENTS
EXAMPLE FOR SENTENCE:
A statement is a single COBOL instruction composed of one or more words, defining a specific operation such as MOVE, IF, PERFORM, or CALL.
Key characteristics:
does not require a period (only sentences do)
represents the smallest executable instruction
can span multiple lines
Contains:
one or more WORDS
EXAMPLE FOR STATEMENT:
A word is the smallest lexical token in COBOL, representing:
identifier (e.g. CUSTOMER-NAME, TOTAL-AMOUNT, READ-PARA)
reserved word (keyword which is used by the language; e.g. MOVE, IF, DISPLAY, SECTION, IS, THROUGH)
literal (direct values, e.g. "hello", 123, "A", 1.23, 1,23)
figurative constant (e.g. ZERO, SPACES, HIGH-VALUE)
special character symbol (, ; . ( ) + - * / = <> )
Key characteristics:
separated by spaces or punctuation
case‑insensitive
includes identifiers, keywords, literals, and symbols
Contains:
characters only (no smaller COBOL unit exists)
In COBOL, using "-" mark between words is optional, which mean these are equal:
OBJECT-COMPUTER
OBJECT COMPUTER
EXAMPLE FOR WORD:
There are two source code styles:
fixed-format
free-format.
There are areas which define the physical placements of COBOL source code. This is part of the core rules of COBOL.
The classic COBOL source code is 80 character wide and divided to four areas:
Sequence Number Area
Indicator Area
Area A
Area B
Identification Area
If there is content after the Identification Area, the compiler ends with a fail.
FIGURE OF SOURCE CODE AREAS:
Sequence Number Area (columns 1–6):
in old times places used with the paper card reader machines
totally optional to show numbers in it but it must exist (e.g. as SPACE/blank characters)
the compiler ignores it
EXAMPLE FOR USING SEQUENCE NUMBER AREA:
Indicator Area (column 7):
the only character which carry special meaning
EXAMPLE FOR USING INDICATOR AREA:
Area A (columns 8–11) contains every COBOL element which starts a new logical unit such as:
DIVISION names
SECTION names
PARAGRAPH names
01‑level data definitions
FD, SD registrations
COPY könyvtárnevek (if they are in independent lines)
It is a strict rule that these key elements start in Area A.
EXAMPLE FOR USING OF AREA A:
Area B (columns 12–72) are for instructions and data definitions such as:
MOVE, ADD, IF, PERFORM etc.
02–49 level data definitions
VALUE clause
PROCEDURE DIVISION instructions
EXAMPLE FOR USING AREA B:
Columns 73–80 (Identification Area):
for old tape compatibility
the compiler ignores it
in many projects it is used for version numbers or notes, or left blank
EXAMPLE FOR FULL USAGE OF AREAS:
EXAMPLE FOR FULL USAGE OF AREAS WITHOUT LINE NUMBERS:
This format is recognized by the modern compilers:
IBM Enterprise COBOL 6+
GnuCOBOL 3+
Micro Focus
Properties:
there are no fixed columns and areas, a line can start anywhere
line length limit is lifted, line length is 250+ characters
The first line must be this:
>>SOURCE FORMAT FREE
The comment lines and inline comments are marked with this:
*>
The continuation line is marked with & or - at the end of the previous line
EXAMPLE FOR FIRST LINE, COMMENT AND CONTINUATION:
EXAMPLE FOR FREE FORMAT: