COBOL is abbrevation for 'Common Business Oriented Language'. It was introduced since 1959 (61 Years Ago). COBOL was designed by CODASYL. It was created as part of a US Department of Defense effort to create a portable programming language for data processing. In the late 1950s, computer users and manufacturers were becoming concerned about the rising cost of programming. A 1959 survey had found that in any data processing installation, the programming cost US$800,000 on average and that translating programs to run on new hardware would cost $600,000. At a time when new programming languages were proliferating at an ever-increasing rate, the same survey suggested that if a common business-oriented language were used, conversion would be far cheaper and faster.
- In 1959, COBOL was developed by CODASYL (Conference on Data Systems Language).
- COBOL-61 was released in 1961 with some revisions.
- In 1968, COBOL was approved by ANSI as a standard language for commercial use (COBOL-68).
- It was again revised in 1974 and 1985 to develop subsequent versions named COBOL-74 and COBOL-85 respectively.
- In 2002, Object-Oriented COBOL was released, which could use encapsulated objects as a normal part of COBOL programming.
Most of the system in US like Financial System, Social Security Administration, Department of Defense, Internal Revenue Service, the Majority of State Financial / Unemployment Systems and Numerous other Critical Systems is developed using COBOL.
I think that's enough introduction about COBOL background and history. Let's start the real code.
To run COBOL on your local machine. You need GNU-COBOL. In this article I'll be showing how to install it on Mac OS. First you need homebrew installed. After that you can just execute
brew install gnu-cobol
To check whether the installation succeed or not, try run this command.
it should shown something like this
cobc (GnuCOBOL) 2.2.0 Copyright (C) 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart Built Apr 29 2020 00:06:51 Packaged Sep 06 2017 18:48:43 UTC C version "4.2.1 Compatible Apple LLVM 11.0.3 (clang-122.214.171.124)"
Using Visual Studio Code you can just go to Extension Marketplace and install COBOL Plugin. The extension provide Syntax highlighting for COBOL, JCL, PL/I and MF directive files, this help us a lot understanding COBOL program.
Let's write some code below.
IDENTIFICATION DIVISION. PROGRAM-ID. hello. AUTHOR. KELVIN. PROCEDURE DIVISION. DISPLAY "Hello World". STOP RUN.
and to run it
cobc -x hello.cob ./hello
The output should looks like this.
Yes, this is your Hello World program using COBOL :).
A brief introduction of these image is given below −
- Sections are the logical subdivision of program logic. A section is a collection of paragraphs.
- Paragraphs are the subdivision of a section or division. It is either a user-defined or a predefined name followed by a period, and consists of zero or more sentences/entries.
- Sentences are the combination of one or more statements. Sentences appear only in the Procedure division. A sentence must end with a period.
- Statements are meaningful COBOL statements that perform some processing.
- Characters are the lowest in the hierarchy and cannot be divisible.
First and only the mandatory division of every COBOL program. The programmer and the compiler use this division to identify the program. In this division, PROGRAM-ID is the only mandatory paragraph. PROGRAM-ID specifies the program name that can consist 1 to 30 characters.
IDENTIFICATION DIVISION. PROGRAM-ID. hello.
In short, procedure division is used to include the logic of the program. It consists of executable statements that written by the progammer.
There must be at least one statement in the procedure division. The last statement to end the execution in this division is either STOP RUN or EXIT PROGRAM.
PROCEDURE DIVISION. DISPLAY "Hello World". STOP RUN.
I've only tried wrote simple program in COBOL and saw other people code on internet. But here's few things i found compare to language that i used nowadays.
A lot of reserved words, COBOL has over 300 keywords while Python only has 33 keywords. This lead to long list of reserved words to memorize.
Invent the wheel. Because there's no library concept in COBOL most of time you need to write your own libraries to do something you want. Also because of this everything is implemented as a keyword. for example when you want to support XML they introduce keywords like PARSE and RENDER.
Over-verbose syntax, when COBOL designed this kind of syntax was intended to make the code itself self documenting by using english like syntax so it readable for non-tecnical person but it ends up unmaintainable and uncomfortable for real programmer.
Less code to type, because a lot of reserved words, you only wrote data you're going to need and logic you're going to execute.
Performance. For many years COBOL compilers have been producing very high performance executables. Only native C and native Assembler beat COBOL on an IBM mainframe.