COBOL Tutorial: What is, History, Install, Program Example

What is COBOL?

COBOL is a programming language that is mainly focused on solving a business problem. Full form of COBOL is Common Business-Oriented Language. It is primarily used in company and government business, finance, and administrative systems. This language also used as a solution to many data processing problems.

It is developed by CODASYL (Conference on Data Systems Languages). It is used as a language in the Mainframe System.

In this basic COBOL tutorial, you will learn:

Features of COBOL

Here, are some most important features of the COBOL programming language:

History of COBOL

Here, are important landmarks from the history of COBOL:

Installing COBOL on Windows

Below given are by following a few simple steps to Install Hercules emulator

There are various types of mainframe emulators used for Windows. You can use them to write and do the simple COBOL programs.

Hercules is one of the popular COBOL emulators which can easily installed on Windows. Hercules is an open-source tool. It works on the latest 64-bit z/Architecture.

Step 1) Visit www.hercules-390.eu website. You will see the following link.

Step 2) In the Dialog box click on Run button

Step 3) In the next screen, click on the Next button.

Step 4) In Public License agreement screen,

  1. Select the radio button accept the term the Licence Agreement
  2. Click on Next Button

Step 5) In the next screen, click on Install button.

Step 6) Click on Install button

Step 7) Click on the finish button.

Step 8) In the start menu, click on the Hercules CMD prompt.

Step 9) You can see the command prompt.

Structure of the COBOL program

The organization of a COBOL program is hierarchical. It's not necessarily needed for all of the components to be present for the hierarchical relationship to exist.

COBOL Programming structure

Here, are various components of the COBOL program:

Divisions

A division is a block of code, which usually contains one or more sections. It starts where the division name is encountered. It ends with the beginning of the next division.

Sections

Sections are the logical subdivision of the program logic. It is the collection of paragraphs.

Paragraphs

Paragraphs are the portion of a selection which is a user-defined or predefined name which should be followed by a period. This section includes zero or more sentences.

Sentences

Sentences are a combination of single or multiple statements. They should occur only in the procedure division. A sentence in COBOL language must end with a period(.).

Statements

These are the meaningful COBOL statements which perform some processing.

Characters

These are the lowest in the hierarchy which cannot be divided.

Types of Divisions

Various divisions in COBOL program structure are as follows:

Identification Division

Environment Division

It helps you to identify input and output files to the program.

Configuration section:

This section gives information regarding the system on which the program is written and run.

This section has two paragraphs:

Source computer – Complete program

Object computer – Execute the program.

Input-Output sections:

It has four sections:

Procedure Division:

COBOL coding rules

Here, are some most important coding rules while working with COBOL:

The standard form of Cobol program:

Program Syntax Rules of COBOL

Here, some important syntax rules of COBOL:

Variables in COBOL

In COBOL variable is a named location in memory into which a program can put data and from which it can retrieve data. A data-name or identity. It is the name used to identify the area of memory that is reserved for the variable.

Variables must be described in terms of their size and type. Every variable used in a COBOL program should have encryption in the DATA DIVISION.

Rules for declaring variables in COBOL:

If Else Statements

In COBOL, If else statement is used for conditional branching

The relational operators and some spelled out phrases can be used

If x < y - this can be written as if x is less than y

<, >, =,>=,<= are the available relational operators

NOT, AND, OR are logical operators used in COBOL

Greater than, less than, equal to are the spelled out phrases

If x is less than y then 
Do the first action 
Else
Do the second action 
End-if.

To check an alpha number variable for what type of data it holds, we can use if x is number, if x is alphabetic, conditions. It is based on T or F value.

You can use if-then-else if for multi-level conditions

Evaluate X
When 1 perform action1
When 2 perform action2
When 3 perform action3
When others perform action4
End-evaluate

If no condition is matched, then the other clause is executed. This is quite similar to the switch statements in other languages.

Example of COBOL

Example 1 - Hello World!

IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
PROCEDURE DIVISION.
DISPLAY 'Hello, world.'
STOP RUN.

Advantages of COBOL

Here, are important cons/benefits of using COBOL language:

Disadvantages of COBOL

Here, are some cons/disadvantages of using COBOL:

Summary:

 

YOU MIGHT LIKE: