Skip to content

A very short introduction to COBOL

New Course Coming Soon:

Get Really Good at Git

COBOL is one of those languages you keep hearing about, one of the remains of the past.

Turns out it’s the language that makes the world go around, in particular in banks and financial institutions. I read somewhere that over 70% of business transactions are made through programs written in COBOL.

There are various reasons for that. First, the language was designed for that use case.

After all, it’s called COmmon Business-Oriented Language.

Kind of boring, for a name. But it goes straight to the point.

Another reason is that it’s old. Designed in 1959, it’s been used from the start to make those systems, and no one is going to change those programs that run fine.

Those programs are so important that they are just being maintained and improved, but never rewritten from scratch.

Anyway, you can read about the history of COBOL on Wikipedia. The goal here is to make a quick introduction to the language, so the next time you hear COBOL, you know what it looks like.

Install the GNU COBOL compiler

Install gnu-cobol.

On a Mac, use Homebrew:

brew install gnu-cobol

or use any way you can install GNU commands on your Operating System (hint: Homebrew also works on Win/Linux)

Once this is done, you’ll have access to the cobc command.

This is the man page for it:

man cobc

Some instructions I found online involved installing an IDE (Integrated Development Environment) but you don’t need one to test things out.

Write your COBOL programs in a .cob file, and compile it using

cobc -x <filename>.cob

Write the COBOL Hello, World!

I created a hello.cob file and opened it in VS Code. Immediately a popup told me some extensions could help with .cob files. I’m impressed.

I’m going to install the first and most popular, named COBOL, to provide syntax highlighting.

Now add this code to the hello.cob file:

           DISPLAY "Hello, World!".
           STOP RUN.

Compile it from the command line:

cobc -x hello.cob

and then run the binary file generated:


This was simple.

Sum two numbers received from the user

Now create a sum.cob file:

       77 NUM_1 PIC 9(4).
       77 NUM_2 PIC 9(4).
       77 SOLVE_SUM PIC 9(4).
       DISPLAY "First number: ".
       ACCEPT NUM_1.
       DISPLAY "Second number: ".
       ACCEPT NUM_2.
       DISPLAY "Sum: " SOLVE_SUM.
       STOP RUN.

Compile it:

cobc -x sum.cob

Run it:


and you’ll be asked for 2 numbers, then the program calculates the sum:

Note that I have no idea how those programs run, the instructions meanings, but I just wanted to try it out.

I think this is all the COBOL I’ll ever write in my life.

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching Summer 2024. Join the waiting list!

Here is how can I help you: