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:
- What is COBOL?
- Features of COBOL
- History of COBOL
- Installing COBOL on Windows
- Structure of the COBOL program
- 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
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.
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.
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,
- Select the radio button accept the term the Licence Agreement
- 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.
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:
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 are the logical subdivision of the program logic. It is the collection of 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 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(.).
These are the meaningful COBOL statements which perform some processing.
These are the lowest in the hierarchy which cannot be divided.
Various divisions in COBOL program structure are as follows:
- Identification Division
- Environment Division
- Data Division
- Procedure 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.
It helps you to identify input and output files to the program.
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.
- 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.
- This division is used for including the logic of the program.
- Procedure division also includes executable statements which are defined in the data division.
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.
- 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.
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.
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.
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 1 - Hello World!
IDENTIFICATION DIVISION. PROGRAM-ID. HELLO-WORLD. PROCEDURE DIVISION. DISPLAY 'Hello, world.' STOP RUN.
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.
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.
- 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