A Fresh and Modern Look at All Things Mainframe

Main menu

Monthly Archives: September 2012

I’ll start this off by saying that I’m not an application developer, or even a serious programmer. My major isn’t computer science or software engineering. To be honest, before coming to RIT, I wasn’t even sure that I was going to enjoy programming. It’s one of the reasons that I elected to be an Applied Networking and Systems Administration major instead of an Information Security and Forensics major. I thought that security would entail more programming than I would enjoy. Then I discovered my affinity for programming, began learning languages on my own, applied for a double major in security, and took a mainframe class. And now, here I am trying to learn some COBOL.

Whenever I get into a discussion with a fellow geek, we inevitably start talking about programming languages. After listing the languages we know, the conversation usually goes something like this:Me: “Yeah, I’m trying to pick up some COBOL here and there during my limited free time.”Them: “Ha! Why? Nobody uses COBOL anymore.”Cue my defensive spiel on why COBOL is a valuable language to learn and how the modern business world practically runs on it. A lot of people will tell you that learning COBOL is a futile, even useless effort. So let’s look at some facts about this “dead” language:

We interact with COBOL every single day. It is used in more than 90% of financial transactions worldwide.

“There are over 200 billion lines of COBOL code in use around the world. Placed end to end, these lines would stretch from Earth to Mars.”

Over ¾ of business data is processed by COBOL programs.

There were over 12 million COBOL programs in 1999, compared with 375,000 C/C++ programs.

These facts, reported by Bleum, a Chinese outsourcing company, tell the tale of a very vibrant, useful, and important language that has become solidly ingrained in the fabric of global business. Geeks spend plenty of time picking up new languages for fun, often just because of a passing interest or a smug desire to say that they’ve written a program in a language that no one has ever heard of. It’s about time we start encouraging programmers, both new and veteran, to learn a language that makes the gears of our modern, global economy turn.

This tutorial is primarily written for those who, like me, have a passing interest in picking up some COBOL here and there. I’m not doing any serious projects in COBOL, but I enjoy reading about the language and trying out examples that I find. This tutorial is especially geared towards those without access to a mainframe to code on. For newbies like us, I recommend a few things, each of which I will discuss further:

Some sort of virtual machine environment (I use VMware Fusion on my Mac, but Virtualbox is an excellent free alternative).

Some sort of *nix operating system. I personally recommend Ubuntu, because it makes installing the OpenCOBOL compiler easy. I believe that OpenCOBOL will run under Cygwin on Windows, but let’s just use a *nix OS.

The OpenCOBOL compiler. I explain how to install it on Ubuntu during this tutorial (it’s very easy).

I’m going to assume that you have a fully updated version of Ubuntu installed, either on a physical machine or in a virtual machine. Luckily, Ubuntu makes installing the OpenCOBOL compiler very easy. Simply open up the Ubuntu Software Center, type in “OpenCOBOL,” and install the compiler. I’ve always been partial to Ubuntu, and the ability to install OpenCOBOL from the Ubuntu Software Center makes it particularly appealing for those who are looking to hit the ground running with some basic COBOL development.

Once you’ve got the compiler installed, it’s time to start coding. We’re just going to do a basic “Hello World” to ensure that the compiler actually works. You can use the vim text editor from within the command line (you may have to install it with the “sudo apt-get install vim” command), or you can use Ubuntu’s GUI text edit program. Both allow for syntax highlighting of COBOL code.

Below is the code for our basic program. Note that there are a 7 spaces before each statement (the statements under the PROCEDURE DIVISION have 8 spaces before them, to assist with readability). It is also very important that these are spaces, NOT tabs. Type the code below into your text editor, and save the file as “hello.cob”

IDENTIFICATION DIVISION.

PROGRAM-ID. HELLOWORLD.

PROCEDURE DIVISION.

DISPLAY ‘HELLO WORLD’.

STOP RUN.

The code for our Hello World program. Note that there are 7 spaces before each statement.

Once we have typed our code, we can compile it with the OpenCOBOL compiler. To compile a regular COBOL program, we use the command “cobc –x” Note that the “-x” flag is VERY IMPORTANT because it tells the compiler to build an executable program. If you fail to use it, you will get segmentation faults when trying to run your program, as I discovered (and subsequently tried to troubleshoot for hours). During compilation, you may receive errors from the gcc compiler (OpenCOBOL translates COBOL code into C, and then uses a C compiler to generate the executable). For my basic development, none of these errors has caused any problems. However, I have not experimented substantially with COBOL development, and I do now know if there is a risk of more serious issues as programs increase in complexity. To run the program, use the “./hello” command. It should successfully output “HELLO WORLD.”

Now that we have worked through creating a basic COBOL program, I would like to discuss Murach’s Mainframe COBOL. Murach’s approach in this text is superb, both for experienced programmers and newbies alike. Murach uses a “paired pages” approach, where the left page includes an explanation of important details and the right page has examples or quick summarizations of the material. This allows you to tailor the book to your learning style, and enables a new COBOL programmer like myself to quickly develop a working knowledge of the language. I’ve only made it four chapters in, but I have found the book to be easy to read and would highly recommend it for anyone hoping to learn COBOL.

The average COBOL programmer is 55 years old. We undoubtedly have a serious shortage of COBOL programmers, and few schools are actually teaching this important language. After my initial experiments with the language, I really believe that more people should be learning it. The syntax isn’t difficult, and I found the often rigid syntax requirements to be refreshing and sensible. There’s also a certain amount of nostalgic joy that accompanies COBOL. Viewing COBOL examples and trying them out is a great way to see how the classic reliability that was built into the mainframe platform holds incredible relevance in today’s modern computing atmosphere. This joy follows a revelation that I think many mainframers, new and old, have experienced: the powerful reliability and beautiful simplicity of yesterday’s technologies are still unbelievably relevant for the systems of tomorrow.