COBOL GnuCOBOL 3.2.0 ·
✓ verified by execution on 2026-08-16
The technology industry moves incredibly fast. Frameworks come and go, and entire programming languages rise and fall within a decade. So why, over 60 years after its invention, is COBOL still actively running?
It’s a common misconception that COBOL is an obsolete relic. The reality is that COBOL powers massive mainframe operations, processing trillions of dollars in daily financial transactions globally.
Even the simplest Hello World program in COBOL requires structural divisions, a nod to its enterprise design.
cobol✓ verified output
IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. PROCEDURE DIVISION. DISPLAY "This is a sample program that displays ""Hello, world!""". STOP RUN.
Output
This is a sample program that displays "Hello, world!"
Your output
The Business Case for COBOL
When you swipe your credit card, file an insurance claim, or check your bank balance, there is a very high probability that a COBOL program on a mainframe processes that transaction.
cobol✓ verified output
IDENTIFICATION DIVISION. PROGRAM-ID. MAINFRAME. PROCEDURE DIVISION. DISPLAY "COBOL programs that are portable to actual mainframe". STOP RUN.
Output
COBOL programs that are portable to actual mainframe
Your output
Mainframes are massive, incredibly reliable computers designed for extremely high-volume input/output operations. COBOL was designed specifically for this environment. It is not meant for building sleek web interfaces; it is meant for reading millions of records, processing them reliably, and writing them out.
Exact Precision Math
One of the biggest reasons financial institutions still rely on COBOL is how it handles numbers. Most modern languages (like Python or JavaScript) use floating-point numbers, which can lead to rounding errors when dealing with money (e.g., 0.1 + 0.2 = 0.30000000000000004).
COBOL doesn’t use floating-point math for money. It natively uses fixed-point decimal arithmetic via PICTURE (or PIC) clauses, completely avoiding those rounding errors.
Let’s look at how COBOL formats a large financial figure without losing any precision.
Predict the outputcobol
Read the code. What exactly will it print? Commit to an answer before you look.
IDENTIFICATION DIVISION. PROGRAM-ID. MATH. DATA DIVISION. WORKING-STORAGE SECTION. 01 TOTAL-AMOUNT PIC 9(9)V99 VALUE 123456789.99. 01 FORMATTED-OUT PIC $$$,$$$,$$$,$$9.99. PROCEDURE DIVISION. MOVE TOTAL-AMOUNT TO FORMATTED-OUT. DISPLAY FORMATTED-OUT. STOP RUN.
Output
$123,456,789.99
You predicted
Did you notice how we just moved a number to FORMATTED-OUT, and COBOL automatically applied the dollar signs, commas, and decimal points? This built-in formatting capability was designed specifically for printing financial reports.
Batch Processing
A massive amount of COBOL code doesn’t run interactively (where a user types something and waits for a response). Instead, it runs as batch jobs.
In a batch process, data is collected over a period of time (like a day’s worth of bank deposits) and processed all at once, usually overnight. These programs often read from files or directly from standard input.
cobol✓ verified output
IDENTIFICATION DIVISION. PROGRAM-ID. STDIN-TEST. PROCEDURE DIVISION. DISPLAY "The special input name - takes input from stdin". STOP RUN.
Output
The special input name - takes input from stdin
Your output
Modern Integration
Another misconception is that COBOL is isolated from modern technology. In reality, mainframe COBOL is routinely exposed via modern APIs, connects to massive DB2 relational databases, and interoperates with cloud services.
Modern compilers like GnuCOBOL even integrate closely with C! Behind the scenes, GnuCOBOL translates your COBOL code into C files before producing a native executable.
cobol✓ verified output
IDENTIFICATION DIVISION. PROGRAM-ID. COMP-TO-C. PROCEDURE DIVISION. DISPLAY "COBOL source files are translated into C files". STOP RUN.
Output
COBOL source files are translated into C files
Your output
You can even run the compiler in a compile-only mode, separating translation from object generation.
cobol✓ verified output
IDENTIFICATION DIVISION. PROGRAM-ID. COMP-ONLY. PROCEDURE DIVISION. DISPLAY "Compile only. Translated C files are compiled by the". STOP RUN.
Output
Compile only. Translated C files are compiled by the
Your output
The Scale of Legacy
The sheer volume of existing COBOL code is staggering. There are estimated to be over 200 billion lines of COBOL in production today. Rewriting these systems in a newer language is incredibly expensive and highly risky. When a system perfectly handles millions of critical transactions every day, the business incentive is to maintain it, not replace it.
To help visualize where COBOL fits into the modern architecture, consider this diagram:
The next time you see a job posting for a “Mainframe Developer”, you’ll know that they are looking for someone to maintain the very foundation of the modern financial system.
Check yourself
Why do financial institutions still prefer COBOL over many modern languages?
Reveal answer
Because COBOL natively uses fixed-point decimal arithmetic, preventing floating-point rounding errors. — COBOL's PICTURE clauses handle exact decimal representation natively, entirely avoiding the rounding errors found in floating-point math common in other languages.
What is a primary characteristic of a batch process in a COBOL mainframe environment?
Reveal answer
It is an unattended job that processes large datasets sequentially. — Most COBOL programs execute as unattended batch jobs, processing vast datasets sequentially on mainframes.
Which of the following is true about how modern GnuCOBOL produces an executable?
Reveal answer
It translates the COBOL source code into C files before compiling them. — Modern compilers like GnuCOBOL translate COBOL source code into C files before producing a native executable.
Challenges
Challenge 1 +25 XP
Modify the FORMATTED-OUT variable to also include a leading dollar sign in the output.
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.
Write a program that simply outputs 'Mainframes power the world'.
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 "Mainframes power the world\n"
Need a hint? (−25% XP)
Put the exact string inside the DISPLAY statement.
Show solution (0 XP)
IDENTIFICATION DIVISION.PROGRAM-ID. MAINFRAME.PROCEDURE DIVISION. DISPLAY "Mainframes power the world". STOP RUN.