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:

What is COBOL? Features of COBOL History of COBOL How to Install COBOL on Windows 10 COBOL Program Structure Types of Divisions COBOL coding rules The standard form of Cobol program Program Syntax Rules of COBOL Variables in COBOL If Else Statements: Example of COBOL Advantages of COBOL Disadvantages of COBOL Top COBOL Interview Questions and Answers

Features of COBOL

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

Allows you to handle a considerable volume of data due to its advanced file managing capability. Logical structure in COBOL is easier to read and modify. It can be executed and compiled on machines like IBM, personal computers, etc. Testing and debugging tools are always accessible on all platforms of the computer. Therefore, it is a robust programming language. You can easily debug in COBOL as it has different divisions. COBOL was designed for business-oriented applications. It can handle large volumes of data due to its advanced file handling capabilities.

History of COBOL

Here, are important landmarks from the history of COBOL:

COBOL was first designed in 1959 by CODASYL. In late 1962, IBM announced that COBOL is going to be their primary development language. COBOL edition 1965 introduces the facilities for handling mass storage files and tables In 1968, COBOL was recognized and approved by ANSI standard language for standard commercial use. By 1970, COBOL had become the widely used programming language in the world. In 1982, ISO installed then-SC5’s first Working Group: WG4 COBOL In 1985, the ISO working group 4 was accepted this version of the ANSI proposed standard. In 2002, first Object-Oriented COBOL was released which could be encapsulated, as a part of COBOL. In 2012, Computerworld surveys found out that over 60% of organizations still using COBOL. In COBOL 2014 includes features like Method overloading, Dynamic capacity tables, etc.

How to Install COBOL on Windows 10

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) Install Hercules Visit www.hercules-390.eu website. You will see the following link.

Step 2) Click on Run button In the Dialog box click on Run button

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

Step 4) Accept the Licence Agreement In Public License agreement screen,

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

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

Step 6) Click on Install button Click Install to begin the installation

Step 7) Click on the finish button Click the finish button to exit the setup wizard.

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

Step 9) Type ‘hercules’ to start the emulator You can see the command prompt.

COBOL Program Structure

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.

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 Data Division Procedure Division

Identification Division

The programmer and compiler can use this division to recognize the program. The only compulsory division is Program ID. It identifies the name of the program which contains characters.

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:

This section gives detail related to files which are used in the program.

It has four sections:

File section – Allows you to define the record structure of the file. Working storage section: This section helps you to declare the temp variables and file structures. Local-storage section: This section is the same as the local working storage section. The key difference between the two is that variables must be initialized every time when the program starts execution. Linkage section: This section describes the data names received from the external storage.

Procedure Division:

This division is used for including the logic of the program. Procedure division also includes executable statements which are defined in the data division.

COBOL coding rules

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

The first six character positions are allocated for sequence numbers. The seventh character position is reserved for the continuation character, or for an asterisk which denotes a comment line. The actual real program text starts with column 8. The fourth positions from 8 to 11 are known as Area A, and positions from 12 to 72 are called Area B.

The standard form of Cobol program:

There are 80 characters on each line. Columns(l-6): It indicates the sequence Column 7: This position contains the indicator^,/,-) Columns(8-ll): It denotes the Area A. Columns(12-72): It denotes the Area B. Columns(72-80): Use for Identification.

Program Syntax Rules of COBOL

Here, some important syntax rules of COBOL:

COBOL has syntax, which is very similar to the English language, that was designed to be self-documenting and very readable. Example: y = x; is represented with: MOVE x TO y It is not a case sensitive language. It has more than 300 reserved words Complex conditions can be “abbreviated” by removing repeated variables and conditions. For example: IS a GREATER THAN x AND y GREATER THAN OR EQUALS To It lacks big size standard library, as it has only 43 statements, 87 functions, and just one class.

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:

Variables should be declared in working-storage section Variables can be arrays, records, file descriptor records, etc. The name of a variable may have alphanumeric, with its first character as an alphabet. Only allowed special character used and can have the only hyphen in it which must be embedded 9 represents only single-digit number.

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 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 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!

Advantages of COBOL

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

You can use COBOL as a self-documenting language. COBOL language can handle massive data processing. It is one of the primarily used high-level programming languages. Fully compatible with its past versions. COBOL language can handle massive data processing. Resolution of bugs is easier as it has an effective error message system. COBOL is also widely used as a self-documenting language. In COBOL, all the instructions can be coded in simple English words.

Disadvantages of COBOL

Here, are some cons/disadvantages of using COBOL:

It has very wordy syntax COBOL has the most rigid format It is not designed to handle scientific applications The time needed to compile a COBOL program is quite greater than machine-oriented programming languages.

Summary:

COBOL is a programming language that is mainly focused on solving a business problem. COBOL stands for Common Business-Oriented Language It allows you to handle a considerable volume of data due to its advanced file managing capability. COBOL was first designed in 1959 by CODASYL The programming structure of the COBOL consists of 1) Division, 2) Paragraph 3) Section 4) Sentences 5) Characters Four types of division in COBOL are 1)Identification 2)Environment 3) Data 4) Procedure In COBOL program there are 80 characters on each line The syntax of COBOL is very similar to the English language, that was designed to be self-documenting and very readable. COBOL variable is a named location in memory into which a program can put data and from which it can retrieve data. In COBOL, If else statement is used for conditional branching The biggest advantage of COBOL is that you can use it as a self-documenting language. The main drawback of COBOL is that it has a most rigid format