Sitemap
DataDrivenInvestor

empowerment through data, knowledge, and expertise. Join DDI community at https://join.datadriveninvestor.com

About Cobol

3 min readJan 26, 2021

--

Press enter or click to view image in full size

Cobol is one of the oldest existing programming languages. It is short for Common Business Oriented Language. The US Department of Defense created it in 1959 in an initiative to create a portable programming language, a language that can be used on multiple computing platforms, for data processing.

It is verbose and has 300 reserved words (300 words you cannot use as variable names), but it is both readable and self-documenting thanks to its English-like syntax.

Unfortunately, Cobol’s use is on the decline. Its experienced programmers are retiring, and young programmers don’t want to learn Cobol. Instead, they learn new technologies.

However, despite all of that, Cobol is still largely used in the banking sector and other industries. Every day, 220 billion lines of Cobol code are used in production, handling $3 trillion.

Now, let’s look at a Hello World Program in Cobol:

Press enter or click to view image in full size
Hello World program in COBOL

It might look a bit odd at first, but the whole code will make sense once it’s explained.

First of all, a Cobol code line spans over 80 characters maximum. We can also see that the code starts at the 8th column. Anything before that is not code.
A Cobol program is divided into four main parts:
IDENTIFICATION DIVISION
ENVIRONMENT DIVISION
DATA DIVISION
PROCEDURE DIVISION

Let’s analyze this Hello World program line by line:

IDENTIFICATION DIVISION.

This division must be present in any standard Cobol program. It identifies it by supplying its name. As you can see, you have the PROGRAM-ID, which must be the same as the name of the file containing the source code. In our case, it’s ‘HELLO’.
You can also have the author’s name and the date the program was written, although they are not mandatory.

Get Jad Mogaizel’s stories in your inbox

Join Medium for free to get updates from this writer.

Then you have three asterisks followed by dashes or a sentence. These are comments. Any line that has an asterisk at the 9th column is a comment.

ENVIRONMENT DIVISION.

This division lets you specify the source-computer (The system used to compile the program) and object-computer (The system used to execute the program), and the input and output files’ association with external media.

DATA DIVISION.

This is the division where you declare your variables. That’s right, in Cobol, you declare all your variables in one allocated space at the very beginning of the program.

PROCEDURE DIVISION.

This is where all the magic happens: where you code your algorithm.

We can see DISPLAY ‘HELLO WORLD’, which tells the program to print ‘HELLO WORLD’ to the screen. It is the equivalent of console.log in Javascript or System.out.println in Java.

Then, the ‘GOBACK.’ instruction tells the program to stop. You could have also used ‘STOP RUN.’ here. Notice there are full stops after these keywords and the names of the four main parts. After these specific instructions, you need a full stop.

Here you go!

You have analyzed and understood your first Cobol program.

Keep in mind we could have gone much more in-depth in a Cobol program’s structure and different elements but have started with a simple one on purpose.

--

--