The Four Divisions

COBOL GnuCOBOL 3.2.0 Β· βœ“ verified by execution on 2026-08-16

A COBOL program is structured exactly like a book. Where a book has chapters, COBOL has Divisions. Every single line of code you write belongs inside one of these divisions, and they must always appear in the exact same order.

There are exactly four divisions:

  1. IDENTIFICATION DIVISION: Who wrote this program and what is it called?
  2. ENVIRONMENT DIVISION: What hardware and files does it connect to?
  3. DATA DIVISION: What variables and memory does it use?
  4. PROCEDURE DIVISION: What actions does it perform?
IDENTIFICATION DIVISION ENVIRONMENT DIVISION DATA DIVISION PROCEDURE DIVISION

Here is what a program looks like with all four divisions properly structured:

cobol βœ“ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. HELLO-DIVISIONS.

       ENVIRONMENT DIVISION.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 GREETING-MSG PIC X(20) VALUE 'Four divisions work!'.

       PROCEDURE DIVISION.
           DISPLAY GREETING-MSG
           STOP RUN.
Output
Four divisions work!

Let’s look at each division closely.

The IDENTIFICATION DIVISION

The very first line of any COBOL program must declare the IDENTIFICATION DIVISION. Its primary job is to provide a name for the program using the PROGRAM-ID paragraph.

What happens if we forget to provide the PROGRAM-ID? The compiler literally does not know how to name the compiled binary and will immediately throw a compile error.

cobol βœ“ verified output
       PROCEDURE DIVISION.
           DISPLAY 'Where am I now?'.
           STOP RUN.
This example raises an error (on purpose)
PROGRAM-ID header missing
PROGRAM-ID header missing

But what if we skip the ENVIRONMENT and DATA divisions? See if you can predict what the compiler will do:

Predict the output cobol

Read the code. What exactly will it print? Commit to an answer before you look.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. MISSING-DIVISIONS.
       PROCEDURE DIVISION.
           DISPLAY 'I still' ' work!'.
           STOP RUN.
Output
I still work!

The ENVIRONMENT DIVISION

In the mainframe era, COBOL programs were deeply tied to the physical hardware they ran on. The ENVIRONMENT DIVISION was used to specify whether the code was compiled on an IBM System/360 or an NCR machine, and it mapped physical tape drives to logical files.

Today, on modern systems, this division is mostly used for file routing.

cobol βœ“ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. ENV-DIV.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SOURCE-COMPUTER. x86-64.
       PROCEDURE DIVISION.
           DISPLAY 'Environment parsed'.
           STOP RUN.
Output
Environment parsed

The DATA DIVISION

Unlike languages such as Python or JavaScript where you can create a variable right before you use it, COBOL is completely rigid. All variables must be declared upfront inside the DATA DIVISION.

The memory is typically laid out inside a specific section called the WORKING-STORAGE SECTION.

cobol βœ“ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. DATA-DIV.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 MY-VAR PIC X(5) VALUE 'Data!'.
       PROCEDURE DIVISION.
           DISPLAY MY-VAR.
           STOP RUN.
Output
Data!

Order Matters

You cannot shuffle the chapters of a book and expect it to make sense, and the same goes for COBOL. The compiler expects the divisions in a strict, unyielding order: IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE.

Try compiling a program where we placed the DATA DIVISION after the PROCEDURE DIVISION:

cobol βœ“ verified output
       IDENTIFICATION DIVISION.
       PROGRAM-ID. WRONG-ORDER.

       PROCEDURE DIVISION.
           DISPLAY 'This will fail.'
           STOP RUN.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 MSG PIC X(10) VALUE 'Hi'.
This example raises an error (on purpose)
syntax error
syntax error

The compiler hits the DATA DIVISION header while it is currently parsing instructions and throws a syntax error.

Optional Divisions

While the structure is rigid, you do not have to write divisions you do not need. If your program doesn’t map any physical files and doesn’t use any variables, you can simply omit the ENVIRONMENT and DATA divisions completely.

cobol βœ“ verified output
       PROGRAM-ID. MISSING-IDENT.
       PROCEDURE DIVISION.
           DISPLAY 'Where am I?'.
           STOP RUN.
Output
Where am I?

Only the PROGRAM-ID and the PROCEDURE DIVISION are strictly mandatory for a minimal program to compile and run.

Check yourself

What is the absolute minimum requirement to create a valid, runnable COBOL program?

Reveal answer

Only the IDENTIFICATION DIVISION and the PROCEDURE DIVISION are required. β€” Only IDENTIFICATION (to provide the PROGRAM-ID) and PROCEDURE (to execute code) are strictly required for a minimal program. The ENVIRONMENT and DATA divisions are optional.

Where must you declare all variables in a COBOL program?

Reveal answer

In the DATA DIVISION under the WORKING-STORAGE SECTION. β€” All variables must be declared in the DATA DIVISION. You cannot declare them inline inside the PROCEDURE DIVISION.

What happens if you place the DATA DIVISION before the ENVIRONMENT DIVISION?

Reveal answer

The program will fail to compile with a syntax error. β€” Divisions must appear in strict order: IDENTIFICATION, ENVIRONMENT, DATA, and PROCEDURE. Changing this order causes a compile error.

Challenges

Challenge 1 +20 XP

This COBOL program has its divisions out of order and will not compile. Fix the order so it runs successfully.

cobol βœ“ solution verified at build time

COBOL has no in-browser runtime, so this one is pen-and-paper: work out what the fixed code should be, then open the solution and compare. The expected output below is real β€” it came from compiling the solution with GnuCOBOL when this page was built.

  • Test 1 β€” expects "Correct order! \n"
Need a hint? (βˆ’25% XP)

The order must be IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE.

Show solution (0 XP)
       IDENTIFICATION DIVISION.
       PROGRAM-ID. FIX-ME.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 MSG PIC X(15) VALUE 'Correct order!'.

       PROCEDURE DIVISION.
           DISPLAY MSG.
           STOP RUN.

🐞 Bug Hunt +20 XP

Find the bug! This program is trying to use a variable, but something is missing.

This code runs. It just does the wrong thing. Read it, find the defect, fix it β€” the tests below decide when you are right.

cobol βœ“ solution verified at build time

COBOL has no in-browser runtime, so this one is pen-and-paper: work out what the fixed code should be, then open the solution and compare. The expected output below is real β€” it came from compiling the solution with GnuCOBOL when this page was built.

  • Test 1 β€” expects "Hello COBOL \n"
Need a hint? (βˆ’25% XP)

Where must variables be declared? You need a specific division for data.

Show solution (0 XP)
       IDENTIFICATION DIVISION.
       PROGRAM-ID. BUG-HUNT.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 MY-NAME PIC X(10) VALUE 'COBOL'.

       PROCEDURE DIVISION.
           DISPLAY 'Hello ' MY-NAME.
           STOP RUN.