Your First COBOL Program
With GnuCOBOL installed, you can write a complete, working COBOL program in under ten lines. Every runnable COBOL program needs, at minimum, an IDENTIFICATION DIVISION with a PROGRAM-ID, a PROCEDURE DIVISION with at least one statement, and a STOP RUN statement to terminate cleanly; the DATA DIVISION and ENVIRONMENT DIVISION are technically optional if the program neither declares variables nor touches files. The classic first program simply displays text to the console using the DISPLAY verb, which is COBOL's equivalent of print() in Python or System.out.println() in Java.
Cricket analogy: Just as a beginner's first net session is simply learning to hold the bat and play a forward defensive shot, a first COBOL program is just PROGRAM-ID, one DISPLAY statement, and STOP RUN, the minimal complete unit.
Writing and Compiling HELLO.cob
Save the program below as HELLO.cob (the .cob or .cbl extension is a convention GnuCOBOL recognizes, not strictly mandatory). Compile it with cobc -x -free -o hello HELLO.cob, where -x requests an executable, -free enables the beginner-friendly free-format source layout, and -o hello names the output binary. Running ./hello afterward executes the compiled program directly; on Windows via WSL or MinGW, the output binary would instead be hello.exe.
Cricket analogy: Just as nets practice must happen before a real match, compiling HELLO.cob with cobc -x -free -o hello HELLO.cob is the required 'practice run' step that turns readable source into an executable ready to run.
Common Beginner Mistakes
The most frequent early errors are: forgetting the trailing period after PROGRAM-ID or after a statement, which merges statements together in confusing ways; misplacing code in fixed-format Area A versus Area B when not using the -free flag; and forgetting STOP RUN, which in some environments causes the program to fall through into whatever paragraph happens to follow rather than terminating cleanly. Another very common mistake for beginners coming from other languages is expecting case sensitivity; COBOL keywords and most identifiers are traditionally case-insensitive, so DISPLAY, display, and Display are all treated identically by the compiler.
Cricket analogy: Just as forgetting to ground your bat behind the crease can get you run out unexpectedly, forgetting STOP RUN in COBOL can let execution fall through into the next paragraph instead of terminating cleanly.
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
PROCEDURE DIVISION.
DISPLAY "Hello, COBOL World!".
STOP RUN.Since COBOL is traditionally case-insensitive for keywords and identifiers, most shops adopt a style convention (commonly all-uppercase for reserved words and division/paragraph names) purely for readability, not because the compiler requires it.
Do not forget the final period after STOP RUN, and do not forget STOP RUN itself. Without it, in some runtime environments execution can 'fall through' past the end of PROCEDURE DIVISION into undefined behavior rather than exiting cleanly.
- A minimal runnable COBOL program needs only IDENTIFICATION DIVISION (with PROGRAM-ID), PROCEDURE DIVISION, and STOP RUN.
- DISPLAY is COBOL's console-output verb, comparable to print() in Python or println() in Java.
- Compile with cobc -x -free -o hello HELLO.cob, then run the result with ./hello.
- The -free flag enables beginner-friendly free-format source, skipping strict fixed-column rules.
- COBOL is traditionally case-insensitive for keywords and identifiers.
- Forgetting STOP RUN can let execution fall through into unrelated paragraphs rather than terminating cleanly.
- Forgetting a trailing period after a statement or PROGRAM-ID is one of the most common beginner compile errors.
Practice what you learned
1. What is the minimum set of divisions/statements a runnable COBOL program needs?
2. Which verb prints text to the console in COBOL?
3. What does the -free flag do when compiling with cobc?
4. What can happen if STOP RUN is omitted from a COBOL program?
5. Are COBOL keywords and identifiers case-sensitive?
Was this page helpful?
You May Also Like
Setting Up a COBOL Environment
How to install a free COBOL compiler like GnuCOBOL, choose an editor, and prepare your machine to write and run COBOL programs locally.
COBOL Program Structure
How a COBOL source file is organized into divisions, sections, paragraphs, and sentences, plus the classic fixed-format column layout.
The Four Divisions Explained
A detailed walkthrough of COBOL's four mandatory divisions — IDENTIFICATION, ENVIRONMENT, DATA, and PROCEDURE — and what belongs in each.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics