COBOL is an acronym of Common Business Oriented Language. COBOL is a high-level language. It was developed by CODASYL Committee (Conference on Data Systems Language) in the early 1960s. COBOL was mainly developed for business, finance, and administrative system. It was mainly utilized in banking systems, Insurance applications, and government bodies. COBOL has primarily used language in the mainframe systems.
- Cobol Programming Language Main Features
- Programming Basics
- 3 Main Concepts for Programming
- COBOL Program Architecture
- Types of Divisions
- COBOL Coding Rules
- Program Syntax Rules of COBOL
- Variables in COBOL
- Reserved and Defined Words
- Divisions Explained
Who is the audience of this article?
The programmers who want to learn COBOL Programming for use in Banking, Insurance, and Government sectors. Even the audiences who want to have crust knowledge of mainframe or a beginner.
What is Mainframe?
Cobol Programming Language Main Features
- It can handle a huge amount of data thanks to filing managing.
- It has a human-like logical structure easier to read and modify.
- You can find testing and debugging tools throughout many platforms.
- You can easily debug in COBOL as it has different divisions.
- COBOL has the capability to handle business data efficiently because it was designed for business-oriented applications.
In this section, we will learn basic programming in general, and particularly COBOL programming. Here we will pass through some simple COBOL programs by using the main programming.
Please don’t worry if you don’t understand all the above terms at this level. You will be an expert soon.
A program is a collection of statements written in a language the computer understands.
A computer executes program statements one after another in sequence until it reaches the end of the program unless some statement in the program alters the order of execution.
Computer Scientists have shown that any program can be written using the three main programming constructs; Sequences, Iterations, and Selection.
3 Main Concepts for Programming
Any program consists of three main things:
- The computer statements needed to do the job
- Declarations for the data items that the computer statements need.
- A plan, or algorithm, that arranges the computer statements in the program so that the computer executes them in the correct order.
COBOL Program Architecture
COBOL Program is organized in hierarchical. It is not mandatory to add all components in all programs.
COBOL Programming structure
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. Normally, a period follows it. This section itself includes zero or more sentences.
These elements represent a combination of single or multiple statements. They can only take place in the procedure division.
These are organized structures of COBOL programming language. They also take part in the processing.
Types of Divisions
Various divisions in COBOL program structure are as follows:
- Identification Division
- Environment Division
- Data Division
- Procedure Division
- Programmers and compilers will be using this division for program recognition.
- The program ID division is uniquely compulsory.
- This is the identification of the name of the program containing characters.
COBOL Coding Rules
Here, are some most important coding rules while working with COBOL:
- The sequence numbers represent the first six character positions.
- The asterisk (the continuation character) is located in the seventh character position.
- Column 8 is where the real program text starts.
- The fourth positions from 8 to 11 are known as Area A, and positions from 12 to 72 are called Area B.
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.
- 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 represents a certain location in memory where data is stored and fetched by the program. The location name identifies 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 are required to be declared in the working-storage section. They might 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 a single-digit number.
A reserved word represents a character-string with a pre-arranged meaning in a COBOL source program.
There are several types of reserved words in COBOL.
1) Keywords: they appear in uppercase. ADD, READ, etc.
2) Optional Words: they improve readability. GIVING, AFTER, etc.
3) Figurative constants: they refer to constant values. ZEROES, SPACES, etc.
They are constructed and used by the application programmer. They are normally used To-define paragraph names, SECTION names, file names, temporary variables
The following are the rules for forming user-defined words.
The length may be up to 30 characters.
- Only letters, digits, and hyphen (-) are allowed.
- Embedded blanks are not allowed.
- At least one character must be alphabetic.
- Cannot be COBOL reserved words.
- May not begin or end with a hyphen.
The most basic and indivisible unit of the COBOL language is the character. The COBOL character set includes 78 characters that can be classified as letters of the alphabet, digits, and special characters.
As the name suggests the ‘Identification Division’ identifies the program to the programmer and the compiler. Most of the entries in the Identification Division are directed at the programmer and are treated by the compiler as comments. The paragraphs of the Identification Division are:
- DATE WRITTEN
- DATE COMPILED
An exception to this is the Program-ID clause. Every COBOL program must have a PROGRAM-ID. It is used to enable the compiler to identify the program.
There are several other informational paragraphs in the Identification Division but we will ignore them for the moment.
The Environment Division is an optional division and includes two sections namely CONFIGURATION SECTION and INPUT-OUTPUT SECTION. Most of the entries in this division are machine-dependent and hence readers are advised to consult system manuals for this implementation-specific information.
The Configuration Section includes two paragraphs which are the SOURCE-COMPUTER paragraph and OBJECT-COMPUTER paragraph.
- The Source-Computer paragraph denotes the computer where the source program will be compiled.
- Object-Computer paragraph denotes the computer where the object program is designated.
The Input-Output Section consists of two paragraphs namely File Control paragraph and I-O CONTROL paragraph. In the FILE CONTROL paragraph, a file name is selected for each file to be used in the program and assigned to a device.