Wednesday, February 17, 2010

1. Introduction

COBOL was developed in 1959 by a group called the CODASYL Committee. CODASYL is an abbreviation for Conference on Data Systems Languages. This committee included representatives from academia, user groups, and computer manufacturers. The ultimate objective of this committee was to develop a standard business-oriented language for which all major manufacturers would provide compilers. The Department of Defense convened this conference since it, as well as other government agencies, was particularly dissatisfied with the lack of standards in the computing field.

Features of COBOL

1. Business-Oriented Language
As a business-oriented language COBOL is designed specifically for commercial applications, such as payroll and inventory, that typically operate on a large volume of data.

2. A Standard Language
COBOL compilers are available for most computers. The same COBOL program may be compiled and run on a variety of different machines.
The universality of COBOL allows computer uses greater flexibility than they would have with many other languages. A company is free to acquire different brands of computers while using a single programming language. Similarly, conversion from one model computer to a more advanced or newer one presents no great problem as long as there is a COBOL compiler for each model.

3. An English-like Language
COBOL is an English-like language. All instructions can be coded using English words rather than complex codes. To add two numbers together, for example, we use the word ADD. Similarly, the rules for programming in COBOL conform to many of the rules for writing in English, making it a relatively simple language to learn.

4. Self Documenting
One advantage of COBOL computer programs is that they can be substantially self-documenting. Self-documentation is a characteristic of a language that allows a reader of a program to understand its function and follow its processing steps. The language instructions are very English-like, but the programmer has substantial choice as to whether to make a program self-documenting or obscure.



Structure of COBOL programs
COBOL programs are written according to a special structure which is organized into a hierarchy of parts.

A character is the lowest form in the program structure

A word is made up of one or more characters.

A clause consists of characters and words and is used to specify an attribute of an entry.

A statement is a syntactically valid combination of words and characters written in the PROCEDURE DIVISION of a COBOL program and beginning with a verb.

A sentence is a sequence of one or more statements, the last of which is terminated by a period followed by a space.

A paragraph consists of one or more sentences.

A section consists of one or more paragraphs.

A division consists of one or more paragraphs or sections. Every COBOL program consists of four divisions in the following order : IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION and PROCEDURE DIVISION.

COBOL Words
A sequence of continuous characters from the character set can form a word. There are two types of COBOL words, reserved words and user-defined words.

COBOL words are formed by using the following character set :

Digits 0-9
Letters A-Z
Space (blank)
Special characters ( ) . “ + - * / = $ , ; < >

Reserved words are words that are defined both syntactically and semantically by the COBOL language. The programmer cannot use any of these words except in the form specified by the language.

User-defined words (data names) are words supplied by the programmer in order to satisfy the format of a clause or statement in the language.

Rules for forming user-defined words

· 1 to 30 characters.
· Letters, digits, and hyphens (-) only.
· No embedded blanks.
· At least one alphabetic character.
· May not begin or end with a hyphen.
· No COBOL reserved words such as DATA, DIVISION, etc.

Valid datanames Invalid datanames
HOURS DISCOUNT-
SALES-TOTAL AUTHOR
SUBJECT1 BASIC+HRA
AMOUNT-OF-TRANSACTION-OUT 123

Divisions
· IDENTIFICATION DIVISION
The IDENTIFICATION DIVISION is the first division of a COBOL program. It supplies the information about the program to others who may read or use the program. The IDENTIFICATION DIVISION is divided into the following paragraphs :

PROGRAM-ID. Program-name.
Ø Used to specify the program name. Use names of eight characters or less, letter and digits only, because such names are accepted on all systems.

AUTHOR. author-name.
Ø Used to specify the programmer’s name.

DATE-WRITTEN. Date.
Ø Specify the date the program was coded.

DATE-COMPILED. Date.
Ø Can be coded with an actual date. But if it is coded without a date entry, the compiler itself will automatically fill in the actual date of compilation.


· ENVIRONMENT DIVISION
The ENVIRONMENT DIVISION is the only machine-dependent division of a COBOL program. It is composed of two sections :

CONFIGURATION SECTION.
SOURCE-COMPUTER. Computer.
Ø Computer used for compiling the program.
OBJECT-COMPUTER. Computer.
Ø Computer used for executing the program.


INPUT-OUTPUT SECTION.
Ø Supplies information concerning the input and output devices used. This section is required only if the program uses files or prints reports.
FILE-CONTROL.

· DATA DIVISION
The DATA DIVISION defines and describes fields, records, and files in storage. Commonly, it consists of the following sections :

FILE SECTION.
Ø Defines all input and output files.

WORKING-STORAGE SECTION.
Ø Reserves storage for fields not part of input or output but nonetheless required for processing. These include constants, end-of-file indicators, and work areas.

LINKAGE SECTION.
Ø Used to identify items that will be passed to the called program from the calling program and vice-versa.

· PROCEDURE DIVISION
The PROCEDURE DIVISION is divided into paragraphs. Each paragraph is an independent module or routine that includes a series of instructions designed to perform specific set of operations. Paragraph names are coined by the programmer following the rules for forming data-names.
A PROCEDURE DIVISION may also consist of several sections. A section may contain several paragraphs.

Coding a COBOL program
A COBOL program file will have an extension .CBL. A COBOL program needs to be coded following the below mentioned coding rules.
Columns
Use
Explanation
1-6
Sequence numbers or Page and Line numbers (optional)
Used for sequence-checking
7
Indicator column
Denotes
* comments
/ page break
- continue strings
8-11
Area A
DIVISION, SECTION, paragraph names and level 01, 77 entries
12-72
Area B
Statements and sentences
73-80
Comment
Ignored by the compiler
Note : Division, Section, Paragraph Names and Sentences must end with a period followed by at least one space.

A Sample COBOL Program – Eg. 1.1

IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE1.
AUTHOR. XYZ.
DATE-WRITTEN. 1-JUN-2000.
DATE-COMPILED.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-PC.
OBJECT-COMPUTER. IBM-PC.

DATA DIVISION.

PROCEDURE DIVISION.
0000-MAIN.
STOP RUN.

Back to COBOL Index

No comments: