COBOL GnuCOBOL 3.2.0 ·
✓ verified by execution on 2026-08-16
What is COBOL?
COBOL (Common Business-Oriented Language) was created in 1959. You might wonder why a language from the punch-card era is still relevant today. The answer is simple: scale and reliability. COBOL runs the core backend systems of the world’s financial, government, and insurance infrastructure. If you swipe a credit card or receive a payroll deposit, a COBOL program likely processed it.
Let’s look at a basic COBOL program that outputs a greeting to the console.
A COBOL program is structured hierarchically. Every program is split into DIVISIONS, which are the highest level of organization.
Why the Rigid Structure?
COBOL was designed in 1959 with a specific goal: business managers, not just mathematicians, needed to be able to read the code. The language designers modeled COBOL after business English, complete with divisions, sections, paragraphs, and sentences.
They also enforced a strict separation of concerns. The ENVIRONMENT DIVISION maps the code to the specific mainframe hardware. The DATA DIVISION describes the memory layout. The PROCEDURE DIVISION contains the actual logic. This meant a system administrator could configure the environment, a data clerk could define the file layouts, and a programmer could write the logic—all without stepping on each other’s toes.
The Misconception of Interleaved Code
A modern programmer coming from Python or JavaScript expects to write a script from top to bottom, declaring variables and writing logic wherever they are needed.
This intuition fails in COBOL. The language strictly forbids executable statements outside the PROCEDURE DIVISION, and it forbids data declarations outside the DATA DIVISION. You cannot declare a quick temporary variable in the middle of a loop. Everything must be declared upfront in its proper division.
The Boundary
This massive, rigid structure feels like complete overkill for a simple “Hello World” script. And it is. The boundary where this strict structural rule begins to pay off is at scale. When you are processing millions of credit card transactions in a million-line codebase maintained by dozens of teams over fifty years, the strict separation of hardware, data, and logic prevents catastrophic spaghetti code.
For a minimal program that only outputs text, you only need the IDENTIFICATION DIVISION and the PROCEDURE DIVISION.
Outputting Text
The DISPLAY verb is used to write text to the standard output. You can display multiple literal strings at once, and multiple DISPLAY statements execute in sequence.
Notice the periods (.) at the end of the PROGRAM-ID and STOP RUN lines, but not at the end of the first DISPLAY statement.
COBOL uses periods to end a sentence, which can contain multiple statements. A period prematurely ends the current sentence, which can change the logic of your code.
Can you predict the output of the following program if we omit the period until the very end?
Predict the outputcobol
Read the code. What exactly will it print? Commit to an answer before you look.
The STOP RUN verb tells the COBOL program to terminate and return control to the operating system. While modern compilers like GnuCOBOL will implicitly exit at the end of the source file, it’s best practice to explicitly state when your program should halt.
Which COBOL division is required to name the program?
Reveal answer
IDENTIFICATION DIVISION — The IDENTIFICATION DIVISION is mandatory and must contain the PROGRAM-ID paragraph.
How does a modern COBOL program know where to start executing?
Reveal answer
It starts at the first line of the PROCEDURE DIVISION — Execution starts automatically at the first line of the PROCEDURE DIVISION. There is no required entry point function like main().
Are periods required at the end of every line in COBOL?
Reveal answer
No, only division headers, paragraphs, and the end of a sentence need a period — Statements within a sentence do not need periods. Only the end of the sentence, paragraphs, and division headers require them.
Challenges
Challenge 1 +15 XP
Write a COBOL program that displays 'GREETINGS PROFESSOR FALKEN'.
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 "GREETINGS PROFESSOR FALKEN"
Need a hint? (−25% XP)
Use the DISPLAY verb followed by the string in double quotes.
Show solution (0 XP)
IDENTIFICATION DIVISION.PROGRAM-ID. WOPR.PROCEDURE DIVISION. DISPLAY "GREETINGS PROFESSOR FALKEN". STOP RUN.
Challenge 2 +15 XP
Display three separate lines: 'Line 1', 'Line 2', and 'Line 3'.
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 "Line 1\nLine 2\nLine 3"
Need a hint? (−25% XP)
You can use multiple DISPLAY statements in sequence.