- COBOL is a high-level programming language first developed by the CODASYL Committee (Conference on Data Systems Languages) in 1960.
- Currently responsibility for developing new COBOL standards has been assumed by the American National Standards Institute (ANSI).
- Three ANSI standards for COBOL have been produced: in 1968, 1974 and 1985
- The word COBOL is an acronym that stands for COmmon Business OrientedLanguage
- COBOL is designed for developing business, typically file-oriented, applications. It is not designed for writing systems programs.
- Advantages of Using COBOL
- COBOL is self-documenting
- COBOL is simple
- COBOL is non-proprietary (portable)
- COBOL is Maintainable
- Sequence
- Selection
- Iteration
- It’s the language used to explain the syntax of cobol verbs etc .
- As per this notation
- Words in uppercase are reserved words.
- When underlined they are mandatory.
- When not underlined they are "noise" words, used for readability only, and are optional.
- Words in mixed case represent names that must be devised by the programmer (like data item names).
- When material is enclosed in curly braces { }, a choice must be made from the options within the braces. If there is only one option then that item in mandatory.
- Material enclosed in square brackets [ ], indicates that the material is optional, and may be included or omitted as required.
- The ellipsis symbol ... (three dots), indicates that the preceding syntax element may be repeated at the programmer's discretion.
- Example:
- We must start a COMPUTE statement with the keyword COMPUTE.
- We must follow the keyword with the name(s) of the numeric data item (or items - note the ellipsis symbol (...)) to be used to receive the result of the expression.
- The #i suffix at the end of word Result tells us that a numeric identifier/data item must be used.
- Since the ellipsis symbol is placed outside the curly brackets we can interpret this to mean that each result field can have its own ROUNDED phase. In other words we could have a COMPUTE statement like -
- The square brackets after the Arithmetic Expression indicate that the next items are optional but if used we must choose between the ON SIZE ERROR or NOT ON SIZE ERROR phrases.
- Because the END-COMPUTE is contained within the square brackets it must only be used when a SIZE ERROR or NOT SIZE ERROR phrase is used.
- The first six character positions are reserved for sequence numbers.
- The seventh character position is reserved for the continuation character, or for an asterisk that denotes a comment line.
- The actual program text starts in column 8.
- The four positions from 8 to 11 are known as Area A, and positions from 12 to 72 are Area B.
- When a COBOL compiler recognizes the two areas, all division names, section names, paragraph names, FD entries and 01 level numbers must start in Area A. All other sentences must start in Area B.
- They must contain at least one character, but not more than 30 characters.
- They must contain at least one alphabetic character.
- They must not begin or end with a hyphen.
- They must be constructed from the characters A to Z, the numbers 0 to 9, and the hyphen.
- They must not contain spaces.
- Names are not case-sensitive: TotalPay is the same as totalpay, Totalpay orTOTALPAY.
- COBOL programs are hierarchical in structure.
- The hierarchy consists of Divisions, Sections, Paragraphs, Sentences and Statements.
- A Division may contain one or more Sections, a Section one or more Paragraphs, a Paragraph one or more Sentences and a Sentence one or more Statements
- Divisions
- Sections
- Paragraphs
- Sentences and statements
- At the top of the COBOL hierarchy are the four divisions.
- Although some of the divisions may be omitted, the sequence in which they are specified is fixed, and must follow the order below.
- IDENTIFICATION DIVISION. Contains program information
- ENVIRONMENT DIVISION. Contains environment information
- DATA DIVISION. Contains data descriptions
- PROCEDURE DIVISION. Contains the program algorithms
- The IDENTIFICATION DIVISION
- The IDENTIFICATION DIVISION supplies information about the program to the programmer and the compiler.
- Most entries in the IDENTIFICATION DIVISION are directed at the programmer. The compiler treats them as comments.
- The IDENTIFICATION DIVISION has the following structure:
- PROGRAM-ID is a paragraph name that must be specified immediately after the division header.
- NameOfProgram is a name devised by the programmer, and must satisfy the rules for user-defined names.
- The ENVIRONMENT DIVISION
- The ENVIRONMENT DIVISION is used to describe the environment in which the program will run.
- The purpose of the ENVIRONMENT DIVISION is to isolate in one place all aspects of the program that are dependant upon a specific computer, device or encoding sequence.The idea behind this is to make it easy to change the program when it has to run on a different computer or one with different peripheral devices.
- The DATA DIVISION
- As the name suggests, the DATA DIVISION provides descriptions of the data-items processed by the program.
- The DATA DIVISION has two main sections: the FILE SECTION and the WORKING-STORAGE SECTION.
- Additional sections, such as the LINKAGE SECTION (used in subprograms) and the REPORT SECTION (used in Report Writer based programs) may also be required.
- The FILE SECTION is used to describe most of the data that is sent to, or comes from, the computer's peripherals.
- The DATA DIVISION has the following structure and syntax:
- The PROCEDURE DIVISION
- The PROCEDURE DIVISION contains the code used to manipulate the data described in the DATA DIVISION
- The PROCEDURE DIVISION is hierarchical in structure and consists of sections, paragraphs, sentences and statements.
- Only the section is optional. There must be at least one paragraph, sentence and statement in the PROCEDURE DIVISION.
- Paragraph and section names in the PROCEDURE DIVISION are chosen by the programmer and must conform to the rules for user-defined names.
- Some COBOL compilers require that all the divisions be present in a program while others only require the IDENTIFICATION DIVISION and the PROCEDURE DIVISION
About COBOL:
COBOL
is a simple language (no pointers, no user defined functions, no user defined
types) with a limited scope of function.
The
COBOL standard does not belong to any particular vendor. The vendor
independent ANSI COBOL committee legislates formal, non-vendor-specific syntax
and semantic language standards.
COBOL
has a 30 year proven track record for application maintenance, enhancement and
production support at the enterprise level.
What is a Program?
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.
Any
program can be written using the three main programming constructs
What is COBOL MetaLanguage.
Apart from the above some more notations are used:
$i
|
uses an
alphanumeric data-item
|
$il
|
uses an
alphanumeric data-item or a string literal
|
#i
|
uses a numeric
data-item
|
#il
|
uses a numeric
data-item or numeric literal
|
$#i
|
uses a numeric or
an alphanumeric data-item
|
This
syntax diagram may be interpreted as follows;
COMPUTE Result1 ROUNDED, Result2 = ((9*9)+8)/5
COBOL coding rules
User defined Name Construction:
All user-defined
names, such as data names, paragraph names, section names condition names and
mnemonic names, must adhere to the following rules:
The structure of COBOL programs
A
division is a block of code, usually containing one or more sections, that
starts where the division name is encountered and ends with the beginning of
the next division or with the end of the program text.
A
section is a block of code usually containing one or more paragraphs.
A
section begins with the section name and ends where the next section name is
encountered or where the program text ends.
Section names are
devised by the programmer, or defined by the language. A section name is
followed by the word SECTION and a period.
A
paragraph is a block of code made up of one or more sentences.
A
paragraph begins with the paragraph name and ends with the next paragraph or
section name or the end of the program text.
A paragraph name is
devised by the programmer or defined by the language, and is followed by a
period.
A sentence consists
of one or more statements and is terminated by a period.
MOVE .21 TO VatRate
MOVE 1235.76 TO ProductCost
COMPUTE VatAmount =
ProductCost * VatRate.
A statement consists
of a COBOL verb and an operand or operands.
For
example:
SUBTRACT Tax FROM GrossPay GIVING NetPay
Different Divisions in COBOL program:
The PROGRAM-ID clause is an
exception to this rule. Every COBOL program must have a PROGRAM-ID because the name
specified after this clause is used by the linker when linking a number of
subprograms into one run unit, and by the CALL statement when
transferring control to a subprogram.
IDENTIFICATION DIVISION
PROGRAM-ID. NameOfProgram.
[AUTHOR. YourName.]
other entries here
Example:
Example
Program
*------------------------------------------------
IDENTIFICATION
DIVISION.
*------------------------------------------------
PROGRAM-ID. SequenceProgram.
*------------------------------------------------
* Purpose:
To
display the product of two values
*
Description: Read 2 input values
from the keyboard, compute
* the product and display the
result.
* Calling statement: None.
*
Arguments: None.
* Input
files: None.
* Output
files: None.
*
Programmer Sukul Mahadik.
*
Supervisor: None.
* Date
Written: 17, February 2012.
*------------------------------------------------------
DATA
DIVISION.
*------------------------------------------------------
WORKING-STORAGE
SECTION.
*------------------------------------------------------
*
WSXX-Miscellneous.
*------------------------------------------------------
01
WS01-NUM1
PIC
9.
01
WS02-NUM2
PIC
9.
01
WS03-RESULT
PIC
99.
*------------------------------------------------
PROCEDURE
DIVISION.
*------------------------------------------------
A-MAIN SECTION.(section
optional. Note that the name ends with a period)
*------------------------------------------------
A00.(paragraph
name. Atleast one paragraph is necessary. Ends with a paragraph)
ACCEPT WS01-NUM1
ACCEPT WS02-NUM2
MULTIPLY WS01-NUM1 BY WS02-NUM2 GIVING WS03-RESULT
DISPLAY ‘Result is = ‘, WS03-RESULT
STOP RUN.
.
No comments:
Post a Comment