Cobol: Common Business Oriented Language
Cobol: Common Business Oriented Language
COBOL is designed for developing business, typically file-oriented, applications, and is not designed for
writing systems programs.
COBOL was developed in 1959 by the Conference on Data Systems Languages (CODASYL) and was
released as COBOL-60 for application development.
It was then standardized by American National Standards Institute (ANSI) and released as COBOL-68,
COBOL-74 and COBOL-85 with several enhancements to core language.
First Object-oriented COBOL released in 2002 and then continue to evolve as ANSI/ISO standard
COBOL.
COBOL 2014 includes features like Method overloading, Dynamic capacity tables and so on.
COBOL - Features
It is Business Oriented Language designed to provide excellent facilities for storage, retrieval and
maintenance of large volumes of data in files with high-level facilities like sorting, merging, searching and
printing of reports.
Self documentary feature made it easy to read and modify the code.
Testing and debugging tools are available with extensive features across all application development
platforms made it as a robust programming language.
Very wordy, follow a rigid format, not designed for scientific applications
COBOL – Program Structure
COBOL programs are hierarchical in structure. Each element of the hierarchy consists of one or more
subordinate elements. The levels of hierarchy are Divisions, Sections, Paragraphs, Sentences and
Statements.
At the top of the COBOL hierarchy are the four divisions. The sequence in which they are specified is fixed,
and must follow the order:
- IDENTIFICATION DIVISION supplies information about the program to the programmer and the
compiler.
- ENVIRONMENT DIVISION is used to describe the environment in which the program will run.
- DATA DIVISION provides descriptions of the data-items processed by the program.
- PROCEDURE DIVISION contains the code used to manipulate the data described in the DATA
DIVISION.
Some COBOL compilers require that all the divisions be present in a program while others only require
IDENTIFICATION DIVISION and PROCEDURE DIVISION.
COBOL – Program Structure
COBOL – Program Structure
COBOL – Coding Rules
Alphabets of a language define symbols to be used for constructing words and sentences in that language.
COBOL contain 51 symbols or characters as its alphabets.
LETTERS A to Z, a to z
DIGITS 0 to 9
PUNCTUATION CHARACTERS , ; . ‘ ( ) BLANK/SPACE
SPECIAL CHARACTERS +-*/=><$
Letters, digits and hyphen (-) are used for constructing words
+ - * / are used for arithmetic operations
> < = are used for comparison operations
0 9 B Z CR $ * + - are used for defining format or PICTURE Clause of data elements
COBOL – Words and Literals
A COBOL word is a character-string that forms a user-defined word, a system-name, or a reserved word.
The maximum size of a COBOL user-defined word is 30 characters.
A reserved word is a character-string with a predefined meaning in a COBOL source unit. They form the
vocabulary of COBOL. Use of these words for any other purpose is prohibited in the interest of program
readability.
COBOL – Words and Literals
Constant is a form of data that remains unchanged during the execution of a program. These are available
in COBOL as Literals (numeric and non-numeric) and Figurative Constants.
Numeric literals composed of digits, decimal point and symbols +/- for +ve/-ve sign of a number. The
decimal point may appear only once and not at the end. +/- may appear only at the beginning. 1 to 18 digits
are allowed in a numeric literal.
Non-numeric literal is a string of characters except quotation marks, enclosed by quotation marks. All
spaces enclosed in quotation marks are included as a part of the literal. 1 to 120 characters length
permissible for a non-numeric literal.
Figurative constants are reserved words that name and refer to specific constant values.
ZERO, ZEROS, ZEROES
SPACE, SPACES
HIGH-VALUE, HIGH-VALUES
LOW-VALUE, LOW-VALUES
QUOTE, QUOTES
ALL literal
COBOL – Program Structure Contd..,
COBOL program divided into four divisions (identification, environment, data and procedure). Each division
has a well-defined purpose and they appear in a fixed order. First three are declarative in nature and
contain description of environment and data.
Procedure division contains executable actions. COBOL has pre-defined sections for the first three divisions
with fixed names and purpose.
General rules:
Division, Section and Paragraph names must start in Margin ‘A’. Division, Section names must be
followed by the reserved words DIVISION and SECTION and end with full stop. Nothing else
allowed on these lines.
Paragraph names should end with full stops.
Sentences and entries must be written in Margin ‘B’ from any position and end with full stops. The
must begin on new lines.
Arithmetic operators must be preceded and followed by at least one blank.
Two consecutive words are separated by a punctuation symbol (blank).
COBOL – IDENTIFICATION DIVISION
The IDENTIFICATION DIVISION must be the first division in each COBOL source program. It is used to
identify the program through a series of paragraphs divided into a header and no. of paragraphs.
PROGRAM-ID. Program-name.
AUTHOR. Comment.
INSTALLATION. Comment.
DATE-WRITTEN. Comment.
DATE-COMPILED. Comment.
SECURITY. Comment.
COBOL – IDENTIFICATION DIVISION
The PROGRAM-ID paragraph specifies the name by which the program is known and assigns selected
program attributes to that program. It is required and must be the first paragraph in the IDENTIFICATION
DIVISION.
program-name
A user-defined word or alphanumeric literal, but not a figurative constant, that identifies your
program.
The optional paragraphs are:
AUTHOR
Name of the author of the program.
INSTALLATION
Name of the company or location.
DATE-WRITTEN
Date the program was written.
DATE-COMPILED
The DATE-COMPILED paragraph provides the compilation date in the source listing.
SECURITY
Level of confidentiality of the program.
COBOL – ENVIRONMENT DIVISION
Environment division specifies computer system resources to be used by a program. This is the only
division which contains machine-dependent specifications and is required to be modified while changing the
computer for program execution.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. Computer-name.
OBJECT-COMPUTER. Computer-name.
[SPECIAL-NAMES. Renaming-system-names.
INPUT-OUTPUT SECTION.
FILE-CONTROL. File-specification-entries.
I-O-CONTROL. Special-facilities.]
COBOL – ENVIRONMENT DIVISION
The FILE-CONTROL paragraph associates each file in the COBOL program with an external data set, and
specifies file organization, access mode, and other information.
The I-O-CONTROL paragraph of the input-output section specifies when checkpoints are to be taken and
the storage areas to be shared by different files. This paragraph is optional in a COBOL program.
COBOL – DATA DIVISION
Every data name used in the procedure division must be declared in the Data division of the program. The
declarations, besides associating names, specify characteristics of data which decided their storage
representation and permissible usage.
Data division has four sections. Depending on the use of data item, it should be defined in appropriate
section.
DATA DIVISION.
FILE SECTION.
file definition(s)
WORKING-STORAGE SECTION.
elementary and group item definition(s)
LINKAGE SECTION.
elementary and group item definition(s)
None of the sections are mandatory. Program may use some or all of these sections in the above order.
COBOL – PROCEDURE DIVISION
Procedure division contains executable statements. Within the PROCEDURE DIVISION, a procedure
consists of a section or a group of sections, and a paragraph or group of paragraphs.