100% found this document useful (1 vote)
74 views17 pages

Cobol: Common Business Oriented Language

COBOL is a computer programming language used for developing business applications. It was developed in 1959 and has since seen several updates to its standard. COBOL uses a hierarchical structure with four main divisions - Identification, Environment, Data, and Procedure. The Identification division provides metadata about the program. The Environment division specifies system requirements. The Data division defines data used in the program. The Procedure division contains executable code that manipulates the data.

Uploaded by

C Srinivas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
74 views17 pages

Cobol: Common Business Oriented Language

COBOL is a computer programming language used for developing business applications. It was developed in 1959 and has since seen several updates to its standard. COBOL uses a hierarchical structure with four main divisions - Identification, Environment, Data, and Procedure. The Identification division provides metadata about the program. The Environment division specifies system requirements. The Data division defines data used in the program. The Procedure division contains executable code that manipulates the data.

Uploaded by

C Srinivas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

COBOL

Common Business Oriented


Language
COBOL - History

 COBOL, COommon Business-Oriented Language" is a computer programming language used in


business, finance and administrative systems for companies and government.

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

 It can run on any machine and largely machine independent language.

 Testing and debugging tools are available with extensive features across all application development
platforms made it as a robust programming language.

 Simple, Portable and Maintainable

 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

 There are 80 characters on each line.


 Columns(1-6): Sequence number area
 Column 7: Comment/Continuation area
 Columns(8-11): Margin or Area ‘A’
 Columns(12-72): Margin or Area ‘B’
 Columns(73-80): Identification area.

 An entry that must begin in Margin ‘A’


may overflow into Margin ‘B’
 If an entry is to begin in Margin ‘B’, it may
begin anywhere from 12th to 72nd column
 Compiler ignores anything given in
sequence number area and identification
area, except program list information.
COBOL – Character Set

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.

The following rules apply for all COBOL words:

 Letters, digits and hyphen are allowed in a word


 Hyphen cannot appear as the first or last character in words
 user-defined words must contain at least one alphabetic character
 Reserved word cannot be used as a user-defined word or as a system-name

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.

The header is in Margin ‘A’ entry and is always


IDENTIFICATION DIVISION.

The paragraphs have pre-assigned names and they will be


Paragraph-name. entry

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.

Overall structure of Environment division is as below:

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

CONFIGURATION SECTION to specify the following items:


 Computer for compiling the program (in the SOURCE-COMPUTER paragraph)
 Computer for running the program (in the OBJECT-COMPUTER paragraph)
 Special items such as the currency sign and symbolic characters (in the SPECIAL-NAMES
paragraph)
 CURRENCY SIGN IS ‘literal’
 DECIMAL POINT IS COMMA
 PRINTER IS PRN

FILE-CONTROL and I-O-CONTROL paragraphs of the INPUT-OUTPUT SECTION used to:


 Identify and describe the characteristics of the files in the program.
 Associate your files with the external QSAM, VSAM, or HFS (hierarchical file system) data sets where
they physically reside.

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.

You might also like