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.

  1. Cobol Programming Language Main Features
  2. Programming Basics
  3. 3 Main Concepts for Programming
  4. COBOL Program Architecture
  5. Types of Divisions
  6. COBOL Coding Rules
  7. Program Syntax Rules of COBOL
  8. Variables in COBOL
  9. Reserved and Defined Words
  10. Characters
  11. Divisions Explained

Tutorial How to program in COBOL programming language

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?

A mainframe is an ultra-high-performance machine developed for heavy load, processor-intensive computing. They are mostly used by large businesses and for scientific purposes.

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.

Programming Basics

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.

  • Constructs
  • Sequences
  • Iterations
  • Selection

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.

This section introduces COBOL programming by writing some simple COBOL programs using these constructs.

3 Main Concepts for Programming

Any program consists of three main things:

  1. The computer statements needed to do the job
  2. Declarations for the data items that the computer statements need.
  3. 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:

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. Normally, a period follows it. This section itself includes zero or more sentences.

Sentences

These elements represent a combination of single or multiple statements. They can only take place in the procedure division.

Statements

These are organized structures of COBOL programming language. They also take part in the 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

  • 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.

Environment Division

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

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.

Reserved Words

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.

User-Defined Words

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.

  1. Only letters, digits, and hyphen (-) are allowed.
  2. Embedded blanks are not allowed.
  3. At least one character must be alphabetic.
  4. Cannot be COBOL reserved words.
  5. May not begin or end with a hyphen.

Characters

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.

Identification Division

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:

  1. PROGRAM-ID
  2. AUTHOR
  3. INSTALLATION
  4. DATE WRITTEN
  5. DATE COMPILED
  6. SECURITY

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.

Environment Division

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.

Configuration Section

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.

Input-Output Section

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.