COBOL for Fun and Profit

May 4, 2019
two minutes.

I’m lucky enough to have worked in many different areas of the IT industry and several times I’ve crossed paths with COBOL both in the public and the financial sectors. There is no doubt that, in spite of the total absence of COBOL from Stack Overflow’s annual Developer Survey, it’s still very much alive, and it’s behind a staggering amount of the systems that our society relies on - banking, insurance and central government, to name a few.

After seeing an article come up again on the subject it got me thinking about its title caption: how long can it be maintained? Or, more concretely, can I compile and run a COBOL program on my laptop? I’d only ever see it running on Mainframes behind green-screen terminals and choose-your-own-adventure-style TSO screens. Well, it turns out the answer is YES, and in fact it’s very simple. This is how I did it.

GnuCOBOL

GnuCOBOL compiles COBOL to executable binaries. It actually does this by transpiling to C but that doesn’t really concern me.

First we need to install the compiler. You can just do:

> brew install gnu-cobol

Seriously, it’s that easy.

Now, to edit our COBOL programs do we have to resort to some archaic editor? Well, not unless you think VS Code is archaic. It has a COBOL Plugin with syntax highlighting and autocomplete.

COBOL in VS Code

This is a basic “Hello World!” program for COBOL taken from the article:

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. HELLO-WORLD.
000300 PROCEDURE DIVISION.
000400      DISPLAY 'Hello, world!'.
000500      STOP RUN.

We can now compile it to a executable binary and run it directly:

> cobc -x hello.cob
> ./hello
Hello, world!

Mission completed. Really much simpler that I had expected.

So, if we can take COBOL and compile it to native binaries then couldn’t we take, for example, existing CICS transactions written for standard mainframes and deploy them as services, for example, in a serverless environment?

So in answer to the question: how long can it be maintained?, based on what I’ve seen the answer is probably, for better or worse, indefinitely.

COBOL for Fun and Profit - May 4, 2019 - John Hearn