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.
- 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).
- A text editor. The one built into Ubuntu should suffice.
- Murach’s Mainframe COBOL is an excellent book for learning COBOL at your own pace.
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 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.