You are on page 1of 37

Contents

Ú Introduction
Ú Structure of COBOL
Ú Character set of COBOL
Ú Literals
Ú Overview of Structure
1.Identification division
2.Environment division
3.Data division
4.Procedure division
Ú Picture clause
Ú Statement
- Accept
- DisplaY
- Open
- Close
- Read
- Write
Ú Arithmetic Operations

o Add verb
o Subtract verb
o Multiply verb
o Divide verb
Ú Compute Statement
Ú Move Statement
Ú Go To Statement
Ú IF Statement
Ú Occurs Clause
Introduction
‡ COBOL is one such a high level language which has been
invented to serve as a common link between man and
machine.
‡ COBOL was developed in u  by the Conference on Data
Systems Languages (CODASYL). COBOL was developed
within a six month period, and yet is still in use over 40
years later.
‡ COBOL stands for Common Business Oriented Language.
Structure Of COBOL
‡ Every COBOL program consists of 4 major
parts called divisions.
Divisions V SectionV ParagraphV Sentence V
Statement
‡ The COBOL defines the following 4 fixed
divisions.
IDENTIFICATION DIVISION
ENVIRONMENT DIVISION
DATA DIVISION &
PROCEDURE DIVISION
Character set
à   
  à
Digits V 0 to 9
Alphabets V A,B,C«««.Z
Special characters V +,-,*,/,,,.,µ,;, <,>,
=,$,(,),
Arithmetic symbols V +,-,*,/
Punctuation symbols V ´,.,;
Relational symbols V >,<,=
Literals
‡ During execution, value does not
change - constant
‡ In COBOL,these constants are called
  It can be classified into
Numeric literal
Non-numeric literal
Figurative literal
Numeric literal

˜    


‡ It is coined by 10 numeric digits.
‡ It will be treated as +ve,if no sign symbol is
present.
‡ No other special characters or alphabets are
allowed.
‡ More than one decimal point is strictly not
allowed.
‡ Maximum no of characters allowed is 78.
‡ Embedding blank spaces are not allowed.
Non-numeric literal
˜     

‡ It is composed of valid COBOL characters.


‡ It should be enclosed within quoted
symbols.
‡ The space character is also counted as a
character.
‡ Maximum no of characters is 120 is
allowed.
Figurative constant
‡ COBOL provides a special type of
constant called Figurative constant.
‡ This have fixed meanings and also
represent a fixed value.
‡ Quoted symbols are not allowed here.
‡ All the figurative constants are also
available in singular & plural forms.
List of figurative
constants are given below
ï     


 



 
 





 




  




IDENTIFICATION
DIVISION
‡ The IDENTIFICATION DIVISION is the
first division to be coded in a COBOL
program.
‡ It is used to identify the program and also
gives some information about tat program.
‡ It is used for documentation purposes.
‡ It is composed of paragraphs and not
division.
General form
IDENTIFICATION DIVISION.
PROGRAM-ID.program-name
[ AUTHOR. Entry.]
[INSTALLATION. Entry.]
[DATE-WRITTEN. Entry.]
[DATE-COMPILED. Entry.]
[SECURITY. Entry.]
ENVIRONMENT
DIVISION
‡ This is the second division of a COBOL
program.
‡ This gives specifications of the
configurations of the computers ,which are
used for compiling and creating the object
program.
‡ It also contains information about name of
the files used and I/P & o/p devices from
or to which these files can be selected.
‡ This is the most machine dependent
division.
‡ There are 2 fixed section in the
ENVIRONMENT DIVISON.They are
CONFIGURATION SECTION
INPUT-OUTPUT SECTION
General form
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. entry.
OBJECT-COMPUTER. entry.
[SPECIAL NAMES . Entry];
[INPUT-OUTPUT SECTION.
FILE-CONTROL. {entry}««..
[I-O-CONTROL. Entry].]
DATA DIVISION
‡ It is the third division of a COBOL
program.
‡ If any identifies are used in the
PROCEDURE DIVISION, they should
be defined in the DATA DIVISION.
‡ It also describes the length of the
record, data-name and its type.
Structure of DATA
DIVISION
DATA DIVISION.
[ FILE SECTION.
FD filename
file description entry
record description entry.]
[ SD sort file name entry]
[WORKING-STORAGE SECTION.
[77 level description entry
record description entry]..]
[LINKAGE SECTION.
[77 level description entry
record description entry]..]
[SCREENSECTION.entry.]
PROCEDURE DIVISION
‡ This is the last and fourth division in
a COBOL program.
‡ No COBOL program is complete in
nature without this division .
‡ There is no fixed section in the
division.
Picture clause
General form:
{PICTURE } [IS] character string.
{PIC}
character string- combination
of numeric, alphabetic, alphanumeric,
numeric edited, alphabet edited &
alphanumeric edited.
ACCEPT
‡ An input command.
‡ It is used to feed data into computer
system.
‡ General form: ACCEPT data-name.
Eg: ACCEPT NAME.
DISPLAY
‡ It is used to produce the output from the
computer system to the user.
‡ General form-
DISPLAY {data-name}.
{literal}
Eg: DISPLAY A .
OPEN
‡ General form-
OPEN {INPUT} filename1 [filename2]..
{OUTPUT}
{I-O}
{EXTEND}
Eg: OPEN I-O MARK-FILE.
CLOSE
‡ At the end of processing, it is
necessary to release these files, this
can be achieved by means of CLOSE
verb.
‡ General form-
CLOSE filename1.
Eg: CLOSE MASTER-FILE.
READ
‡ High volume of data can be used as input
data for a program through input files.
‡ These files should be opened before we
read data from it.
‡ General form-
READ filename [INTO identifier] AT END
imperative statement].
Eg: READ STUD-FILE INTO WS-STU-REC
AT END GO TO CLOSE-PARA.
WRITE
‡ This statement is used to transmit a
logical record of the DATA
DIVISION to the output device
mentioned in the ENVIRONMENT
DIVISION.
‡ General form- WRITE record-name.
Eg: WRITE RESULT-REC.
ADD
Eg:
‡ ADD A,B,C GIVING D
V D=A+B+C
‡ ADD A TO C
V C=C+A
‡ ADD A,5 TO C GIVING D
V D=(A+5)+C
SUBTRACT
Eg:
‡ SUBTRACT 5 FROM P
V P=P-5
‡ SUBTRACT TAX FROM SALARY
V SALARY=SALARY-TAX
‡ SUBTRACT A FROM B GIVING C
V C=B-A
MULTIPLY
Eg:
‡ MULTIPLY A BY B
V B=B*A
‡ MULTIPLY A BY B GIVING C
V C=A*B
DIVIDE
Eg:
‡ DIVIDE A INTO B GIVING C
V C=B/A
‡ DIVIDE A BY B GIVING C
V C=A/B
COMPUTE

General form:
COMPUTE identifier = expression
Eg:
COMPUTE A=B*C+D
MOVE STATEMENT
‡ General form:
MOVE {Identifier/literal} TO
identifier
Eg:
MOVE 10 TO A
V A=10
GO TO STATEMENT
‡ This is an un-conditional statement, which
specifies the transfer of control from one
statement to a desired statement,
unconditionally.
Eg: GO TO OPEN-PARA.
GO TO DEPENDING ON is conditional
goto statement.
Eg: GO TO para-1 DEPENDING ON A.
IF STATEMENT
GENERAL FORM-
IF condition {statement1}
ELSE { statement2}
Relational operators are also used in
IF statement in condition.
Some other statement are also there.
They are PERFORM,SORT,MERGE
OCCURS CLAUSE
‡ It is used only in the DATA DIVISION
and that too only with the level numbers
02 to 49.
‡ This is only an optional clause, but
facilitates the programmer to describe
the similar data items in a simple way
‡ [OCCURS integer TIMES]
Eg: Level-no data-name OCCURS integer
TIMES

You might also like