COBOL GnuCOBOL 3.2.0 ·
✓ verified by execution on 2026-08-16
If you are coming to COBOL from Python, JavaScript, or PHP, you are used to interpreted languages. In an interpreted language, a program called an interpreter reads your code line by line and executes it immediately. If there is a typo on line 100, the program will run perfectly for 99 lines before suddenly crashing.
COBOL is fundamentally different. It is a compiled language.
The Two-Step Process
A COBOL program cannot be run directly. It must first be processed by a compiler—a separate piece of software that translates your human-readable source code into binary machine code that the processor can understand natively.
Compilation: The compiler reads the entire program, checks the syntax, and generates a binary executable (often called a load module or object module). If there is even one syntax error, the compiler stops and generates no executable.
Execution: The operating system runs the generated executable file.
This means a COBOL program will never crash halfway through because of a simple typo—the compiler catches those upfront.
How We Run Code Here
Because COBOL requires a compiler, this course uses the open-source GnuCOBOL compiler behind the scenes.
When you see a program block, imagine that we are running the cobc (COBOL compiler) command to turn the text into an executable, and then immediately running that executable to produce the output.
Interpreted language developers often get tripped up by the compilation step. For example, in a script like Python, you cannot call a function before you define it—the interpreter will crash. But because a COBOL compiler reads the entire file before creating the executable, it already knows about every paragraph before the program even begins running!
Predict the outputcobol
Read the code. What exactly will it print? Commit to an answer before you look.
IDENTIFICATION DIVISION. PROGRAM-ID. RESOLVE-TEST. PROCEDURE DIVISION. PERFORM LATER-STEP. DISPLAY "First step complete.". STOP RUN. LATER-STEP. DISPLAY "Running the later step!".
Output
Running the later step!
First step complete.
You predicted
If you try to remove the PROGRAM-ID or make a typo, the system will show you a compilation error rather than execution output. This strictness is exactly what you want when dealing with enterprise financial systems!
Under the Hood of GnuCOBOL
When you compile with GnuCOBOL, it actually does something quite clever: it translates your COBOL source code into C code first, and then uses a standard C compiler (like GCC) to turn that into the final binary.
cobol✓ verified output
IDENTIFICATION DIVISION. PROGRAM-ID. COMP-STEP. PROCEDURE DIVISION. DISPLAY "Step 1: cobc translates this to C.". DISPLAY "Step 2: A C compiler creates an executable.". DISPLAY "Step 3: The executable is run.". STOP RUN.
Output
Step 1: cobc translates this to C.
Step 2: A C compiler creates an executable.
Step 3: The executable is run.
Your output
You can compile directly to an executable using the -x flag (cobc -x program.cob), or stop at the object file stage using -c (cobc -c program.cob). In large enterprise systems, you’ll often compile dozens of COBOL files into object modules, and then link them all together into one giant application.
But for this course, all you need to know is that behind every piece of output, a compiler successfully verified every single line of your code!
Check yourself
Why doesn't COBOL run directly from the source code like JavaScript?
Reveal answer
Because it is a compiled language that must be translated into machine code first. — COBOL is a compiled language, meaning the entire program must be translated by a compiler into a binary executable before it can be run by the operating system.
What happens if a COBOL program has a syntax error?
Reveal answer
The compiler catches the error upfront and refuses to create an executable. — Unlike interpreted languages, compilers analyze the entire source file. If there is a syntax error, the compilation fails, and no executable is created.
Which of the following describes the output of the compilation process?
Reveal answer
An object module or load module executable — Compilers turn source code into machine-readable formats, like object modules or final executables (load modules), which the computer can execute directly.
Challenges
Challenge 1 +25 XP
This program is missing the statement required to cleanly terminate execution and return control to the operating system. Fix it so it compiles and runs correctly.
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 "I am compiled!\n"
Need a hint? (−25% XP)
Add 'STOP RUN.' at the end of the procedure division.
Show solution (0 XP)
IDENTIFICATION DIVISION.PROGRAM-ID. HELLO-COMPILER.PROCEDURE DIVISION. DISPLAY "I am compiled!". STOP RUN.
Challenge 2 +25 XP
This program will fail to compile because it's missing the PROGRAM-ID. Fix it by naming the program FIX-ME.
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 "I fixed the compile error!\n"
Need a hint? (−25% XP)
Add 'PROGRAM-ID. FIX-ME.' after the identification division.
Show solution (0 XP)
IDENTIFICATION DIVISION.PROGRAM-ID. FIX-ME.PROCEDURE DIVISION. DISPLAY "I fixed the compile error!". STOP RUN.