Anatomy of a COBOL file
COBOL (Common Business-Oriented Language) is one of the oldest high-level programming languages, designed for business, finance, and administrative systems.
File extensions: .cbl, .cob
Every part of the example below is labelled and explained. This page is one of 55 annotated tours on AnatomyOf, a free, open-source project by LunarWerx Studios.
What is inside a COBOL file
Identification Division
Identifies the program (name, author, etc.).
Every COBOL source unit opens with the IDENTIFICATION DIVISION, the mandatory first of the four divisions (IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE). It exists purely for bookkeeping: it names the program and can optionally record author, install date, and remarks, none of which affect runtime behavior. Historically this division carried paragraphs like AUTHOR. and DATE-WRITTEN. for shop documentation standards. Modern compilers still accept them but treat them as comments in all but name. The only clause with teeth is PROGRAM-ID.
PROGRAM-ID
Declares the program name used to call or link this unit.
The PROGRAM-ID. paragraph gives the compilation unit a name, which becomes the external entry point other programs use to CALL it, and often becomes the name of the compiled load module. Traditionally this name was limited to 8 characters to match old operating-system dataset naming rules, a legacy constraint that still shapes naming conventions in mainframe shops today. Because COBOL predates the idea of a single "main" function, PROGRAM-ID is the closest analogue: whatever name it declares is what a job control language (JCL) step or another COBOL program invokes to start execution here.
Environment Division
Specifies the computer environment (source/object computer, file assignments).
The ENVIRONMENT DIVISION is where COBOL admits that hardware exists. Its CONFIGURATION SECTION records the SOURCE-COMPUTER (where the program is compiled) and OBJECT-COMPUTER (where it runs), vestiges of an era when compiling and running happened on genuinely different machines. A larger INPUT-OUTPUT SECTION (not shown here) uses FILE-CONTROL to bind logical file names in the program to physical datasets or paths, decoupling the DATA DIVISION's view of a file from wherever the operating system actually stores it.
Data Division
Defines all data items processed by the program.
The DATA DIVISION is COBOL's answer to variable declarations: every piece of storage the program will touch (files, records, working variables, screen layouts) must be described here before PROCEDURE DIVISION can reference it. There is no equivalent to declaring a variable inline at first use. Its major sections include FILE SECTION (record layouts for files opened via FILE-CONTROL), WORKING-STORAGE SECTION (program variables), and LINKAGE SECTION (parameters passed in from a caller). Declaring data this exhaustively up front is part of why COBOL programs read as verbose but are famously expli
Working-Storage Section
Allocates memory for variables and constants that persist for the program's run.
Items declared in WORKING-STORAGE SECTION are allocated once and retain their values across the whole run (or, in a called subprogram, across calls unless it terminates), closer in spirit to static storage than to stack locals. Each item is a fixed-width field whose size is fully determined at compile time by its PICTURE clause. Because COBOL has no dynamic heap allocation in the C sense, WORKING-STORAGE is where nearly all of a traditional program's "variables" live, initialized with VALUE clauses rather than assignment statements executed at runtime.
Level Number & PICTURE Clause
Defines hierarchy (01, 05, ...) and data type/format (PIC X, PIC 9).
The level number (01, 05, 10, ...) establishes a data item's place in a hierarchy, letting a group item (like a customer record) contain elementary items (like name and balance) the way a struct contains fields. 01 always marks a top-level record or standalone item. Numbers need not be consecutive; the gaps conventionally leave room to insert fields later without renumbering everything. The PICTURE clause (abbreviated PIC) is COBOL's type system: X marks alphanumeric characters, 9 marks a numeric digit, and V marks an implied decimal point that consumes no storage. So PIC 9(5) is five digits a
Procedure Division
Contains the executable instructions (paragraphs, statements).
The PROCEDURE DIVISION is where the actual logic lives. Everything before it is declaration. It is organized into paragraphs (optionally grouped into sections), which are executed either by falling through from the previous paragraph or by explicit PERFORM, COBOL's primary mechanism for structured control transfer without an unstructured GOTO. A PROCEDURE DIVISION can also declare USING parameters when the program is meant to be CALLed as a subprogram, mirroring the parameter list a function would take in more modern languages.
Paragraph
A named section of code within the Procedure Division.
A paragraph is simply a user-defined name followed by a period, after which any number of statements run until the next paragraph header or end of division. There is no explicit "end paragraph" marker. Paragraphs are COBOL's original unit of reusable logic, invoked with PERFORM paragraph-name and returning control automatically when the paragraph finishes. Before structured programming conventions took hold, paragraphs were often chained with GO TO, producing famously tangled control flow; modern style favors PERFORM almost exclusively, and many shops ban GO TO outright in their coding standar
Statement / Sentence
An executable instruction, often starting with a verb (DISPLAY, MOVE, ADD).
COBOL statements read like stilted English sentences built around verbs: DISPLAY writes output, MOVE copies a value from one data item to another (COBOL's closest analogue to assignment), and ADD ... TO ... performs arithmetic in place. A sentence is one or more statements terminated by a period, though modern style favors scope terminators like END-IF over relying on the period's effect. This verb-first, prose-like syntax was a deliberate design goal from COBOL's 1959 CODASYL specification: management was meant to be able to read the code even without knowing how to write it.
Comment
An asterisk (*) in column 7 (or a leading *> in free-format) indicates a comment line.
In classic fixed-format COBOL, source lines are divided into columns with specific meaning: columns 1-6 are a sequence number area (a holdover from punch-card ordering), column 7 is an indicator area, and an asterisk there marks the entire line as a comment. Code proper starts in the "Area A/B" columns beyond that. Free-format COBOL (COBOL 2002 and later, widely supported by modern compilers like GnuCOBOL) relaxes these column rules and adds an inline *> comment marker that can start anywhere on a line, much like // in C-family languages.
Official COBOL site · All languages on AnatomyOf
The interactive tour needs JavaScript. Enable it to hover a callout and trace it into the code.