Your first COBOL program

The source file

COBOL traditionally uses fixed format: columns 1-6 are sequence numbers, column 7 is the indicator area, and code starts at column 8. GnuCOBOL also accepts free format with the -free flag, which this course uses.

IDENTIFICATION DIVISION. PROGRAM-ID. HELLO. PROCEDURE DIVISION. DISPLAY "Hello from COBOL". STOP RUN.

Compile it

Compile the file with the -x flag so you get an executable, then run it:

cobc -x -free -o hello hello.cob

./hello

Run it

The terminal prints the greeting and exits cleanly:

Hello from COBOL

Anatomy

IDENTIFICATION DIVISION names the program. PROCEDURE DIVISION holds the logic. DISPLAY writes a line to the screen, and STOP RUN ends the program. The four-division structure never changes, from a five-line greeting to a million-line banking system.

The code on this page was run with GnuCOBOL 3.2.0 on Alpine Linux 3.24.3 (x86_64) in a Docker container.

Article author: Arthur Isaev