COBOL-85
For IBM Mainframe
System 390
Jyothi Sridhar Kini
E&R, Infosys
Mail-id: Jyothis@infosys.com
Phone: 52179
Course Plan
Day 1: Introduction to COBOL
Programming Fundamentals.
D. Ghosh
Dastidar
COBOL Nancy Stern and John Wiley & Sons Inc
Programming Robert Stern
Structured
COBOL
Any Time reference IBM manuals
Agenda for Day 1
Evolution and Features of COBOL.
Language Fundamentals.
Arithmetic verbs.
Early years.
Future of COBOL.
http://www.home.swbell.net/mck9/cobol/cobol.html
http://www.infogoal.com/cbd/cbdhome.html
History of
COBOL
1960 – COBOL (Common Business Oriented Language)
initial specifications presented by CODASYL (Conference
on Data System Languages)
1964 – revised to make COBOL more flexible
1968 – ANSI (American National Standards Institute)
developed American National Standard (ANS) COBOL
– Standardized form
– Attempted to overcome incompatibilities of different
versions of COBOL
1974 – ANSI published revised version of (ANS) COBOL
– Business applications needed to manipulate character as
well as numeric data
– String operations added
History of
COBOL
1985 – ANSI published another revised
version of COBOL
– Designed to take advantage of structured
programming techniques
– Logic errors reduced with END statements
– Case statement reduced nested IFs
– Less English-like
– Maintained readability and business orientation
– Compatible with previous versions
COBOL
COBOL is an acronym which stands for
COmmon Business Oriented Language.
The name indicates the target area of COBOL
applications.
COBOL is used for developing business,
typically file-oriented, applications.
It is not designed for writing systems programs.
You would not develop an operating system or a
compiler using COBOL.
COBOL is one of the oldest computer languages
in use (it was developed in late 1950s).
CODSYL
Nature of COBOL
Standard Language.
Robust Language.
English-like Language.
Structure of a COBOL program
PROGRAM SENTENCES
DIVISIONS STATEMENTS
PARAGRAPHS CHARACTERS
COBOL Character set
Digits (0 to 9)
Special characters
b - + *
/ = $ ,
; . “ ‘
< > ( )
The COBOL DIVISIONs
DIVISIONS are used to identify the principal
components of the program text. There are four
DIVISIONS in all.
IDENTIFICATION DIVISION.
PROCEDURE DIVISION.
IDENTIFICATION DIVISION
The purpose of the IDENTIFICATION
DIVISION is to provide information
about the program to the programmer
and to the compiler.
Most of the entries in the
IDENTIFICATION DIVISION are
directed at the programmer and are
treated by the compiler as comments.
IDENTIFICATION DIVISION...
IDENTIFICATION DIVISION.
PROGRAM-ID. FIRSTPGM.
AUTHOR. Michael Coughlan.
IDENTIFICATION DIVISION...
•The keywords IDENTIFICATION DIVISION
represent the division header and signal the
commencement of the program text.
IDENTIFICATION DIVISION.
PROGRAM-ID. Member-name. ( Max 8 chars, letters & digits only )
AUTHOR. / Optional entry
INSTALLATION. / Optional entry
DATE-WRITTEN. / Optional entry
DATE-COMPILED. / Optional entry
ENVIRONMENT DIVISION
IDENTIFICATION DIVISION.
PROGRAM-ID. SMALLPGM.
PROCEDURE DIVISION.
A0000-DISPLAY-PARA.
DISPLAY "I did it."
STOP RUN
.
- T
I
F
/ I
C
A
T
I
O
N
A
R
E
A
COBOL coding rules
Each line is considered to be made up of 80
columns.
Numeric
Alphanumeric
Edited numeric
Edited alphanumeric
Literals
Literals are symbols whose value does not
change
in a program.
Can be subscripted.
Rules for forming User-defined
words
Are used to form section, paragraph and data
names.
Can be at most 30 characters in length.
Code Meaning
9 Numeric
A Alphabetic
X Alphanumeric
V Decimal Point
S Sign bit
Description of data names
VALUE clause
Is used to assign an initial value to a
elementary data item.
Is an optional clause.
Group and elementary items
In COBOL the term “group item” is used to
describe a data item which has been further
subdivided.
– A Group item is declared using a level
number and a data name. It cannot have
a picture clause.
– Where a group item is the highest item in
a data hierarchy it is referred to as a
record and uses the level number 01.
Group and elementary items..
The term “elementary item” is used to describe
data items which are atomic, that is, not further
subdivided.
An elementary item declaration consists of;
• a level number,
• a data name
• picture clause.
An elementary item must have a picture clause.
Every group or elementary item declaration must
be followed by a full stop.
PICTURE Clauses for Group Items
Picture clauses are NOT specified for ‘group’
data items because the size of a group item is
the sum of the sizes of its subordinate,
elementary items and its type is always
assumed to be PIC X.
The type of a group items is always assumed to
be PIC X, because group items may have
several different data items and types
subordinate to them.
An X picture is the only one which could
support such collections.
Group Items/Records - Example
WORKING-STORAGE SECTION.
01 STUDENT-DETAILS PIC X(026).
STUDENT-DETAILS
H E N N E S S Y R M 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F
Group Items/Records - Example
WORKING-STORAGE SECTION.
01 STUDENT-DETAILS.
02 STUDENT-NAME PIC X(010).
02 STUDENT-ID PIC 9(007).
02 COURSE-CODE PIC X(004).
02 GRANT PIC 9(004).
02 GENDER PIC X(001).
STUDENT-DETAILS
H EN N E S S Y RM 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F
STUDENT-NAME STUDENT-ID COURSE-CODE GRANT GENDER
Items/Records
WORKING-STORAGE SECTION.
01 STUDENT-DETAILS.
02 STUDENT-NAME.
03 SURNAME PIC X(008).
03 INITIALS PIC X(002).
02 STUDENT-ID PIC 9(007).
02 COURSE-CODE PIC X(004).
02 GRANT PIC 9(004).
02 GENDER PIC X(001).
STUDENT-DETAILS
H EN N E S S Y RM 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F
STUDENT-NAME STUDENT-ID COURSE-CODE GRANT GENDER
SURNAME INITIALS
LEVEL Numbers & DATA
hierarchy
In COBOL, level numbers are used to decompose
a structure into it’s constituent parts.
In this hierarchical structure the higher the level
number, the lower the item is in the hierarchy. At
the lowest level the data is completely atomic.
The level numbers 01 through 49 are general level
numbers, but there are also special level numbers
such as 66, 77 and 88.
In a hierarchical data description what is important
01
is the relationship of the
STUDENT-DETAILS.
02 STUDENT-NAME. level numbers to one
01 STUDENT-DETAILS.
05 STUDENT-NAME.
03another, not
PICthe actual level 10numbers used.
03 SURNAME PIC X(008). 10 SURNAME PIC X(008).
INITIALS X(002). INITIALS PIC X(002).
02 STUDENT-ID PIC 9(007). 05 STUDENT-ID PIC 9(007).
02 COURSE-CODE PIC X(004). 05 COURSE-CODE PIC X(004).
02 GRANT PIC 9(004). 05 GRANT PIC 9(004).
02 GENDER PIC X(001). 05 GENDER PIC X(001).
Description of data names
Example
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-REGNO PIC X(5).
01 WS-NAME.
05 WS-FIRST-NAME PIC A(15).
05 WS-MID-NAME PIC A(15).
05 WS-LAST-NAME PIC A(10).
01 WS-AGE PIC 99V99.
01 WS-SCHOLARSHIP PIC 9(4) VALUE 1000.
Break
Edited picture symbols
Z Zero suppression
* Check protection
, Comma insertion
- Minus sign insertion
+ Plus or minus sign insertion
Edited picture symbols
Edit symbol Meaning
$ Dollar sign insertion
CR Credit symbol
DB Debit symbol
B Blank insertion
/ Slash insertion
. Decimal point insertion
Arithmetic Verbs.
Examples
(1) DISPLAY “The sum is ” SUM.
Arithmetic Verbs
ADD
SUBTRACT
MULTIPLY
DIVIDE
COMPUTE
ADD Verb
Syntax-1
Syntax-2
Syntax
Syntax
[ , identifier-5 ] . . . ]
MULTIPLY Verb
Examples
NUM-4, NUM-5.
DIVIDE Verb
Syntax-1
[ , identifier-5 ] . . . ] ..
Syntax-2
Syntax-3
REMAINDER identifier-4 .
DIVIDE Verb
Examples
REMAINDER NUM-4.
MULTIPLY and DIVIDE
MULTIPLY Subs BY Members GIVING TotalSubs
ON SIZE ERROR DISPLAY "TotalSubs too small"
END-MULTIPLY.
Subs Members TotalSubs
Before 15.50 100 0123.45
After 15.50 100 1550.00
Examples
(1) ADD NUM-1, NUM-2, NUM-3 GIVING NUM-4
ROUNDED.
Examples
(1) ADD NUM-1, NUM-2, NUM-3 TO NUM-4 ON SIZE
PERFORM 800-ERROR-PARA.
On size error option
Receiving Field Actual Result SIZE ERROR
PIC 9(3)V9. 245.96 Yes
PIC 9(3)V9. 1245.9 Yes
PIC 9(3). 124 No
PIC 9(3). 1246 Yes
PIC 9(3)V9 Not Rounded 124.45 Yes
PIC 9(3)V9 Rounded 124.45 No
PIC 9(3)V9 Rounded 3124.45 Yes
imperative statement.
Example
COMPUTE VOLUME = ( 4 / 3) * ( 22 / 7 ) * R ** 3.
Precedence Rules.
1. ** = POWER NN
2. * = MULTIPLY x
/ = DIVIDE ÷
3. + = ADD +
- = SUBTRACT -
Language Fundamentals.
Arithmetic verbs.
Review questions
If an entry must begin in area A ,it must begin in
Column number 8,9,10,11