Beruflich Dokumente
Kultur Dokumente
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
Day 2:
Day 3:
Day 5,6,7:
Working on project
Pre-requisites
Programming Fundamentals.
MVS Operating system and its subsystem TSO.
Job Control Language to submit jobs to MVS.
Navigating through ISPF.
References
TITLE
COBOL
Programming
AUTHOR
PUBLISHER
M.K.Roy and
D. Ghosh
Dastidar
COBOL
Programming
Programming
with
Newcomer and
Lawrence
History of
COBOL
Early years.
ANS Versions of COBOL.
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
Business Oriented Language.
Standard Language.
Robust Language.
Structured Programming Language.
English-like Language.
SENTENCES
DIVISIONS
STATEMENTS
SECTIONS
PARAGRAPHS
RESERVED
WORDS
USER DEFINED
WORDS
CHARACTERS
Digits (0 to 9)
Special characters
b
/
;
<
$
.
>
// Optional
DATA DIVISION.
// Optional
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...
An exception to this is the PROGRAMID clause. Every COBOL program must
have a PROGRAM-ID. It is used to
enable the compiler to identify the
program.
There are several other informational
paragraphs in the IDENTIFICATION
DIVISION but we will ignore them for
the moment.
IDENTIFICATION DIVISION...
The IDENTIFICATION DIVISION has
the following structure
IDENTIFICATION DIVISION.
PROGRAM-ID. PGM-NAME.
[AUTHOR. YourName.]
IDENTIFICATION
IDENTIFICATIONDIVISION.
DIVISION.
PROGRAM-ID.
PROGRAM-ID.FIRSTPGM.
FIRSTPGM.
AUTHOR.
AUTHOR.Michael
MichaelCoughlan.
Coughlan.
IDENTIFICATION DIVISION...
The keywords IDENTIFICATION DIVISION
represent the division header and signal the
commencement of the program text.
The paragraph name PROGRAM-ID is a
keyword. It must be specified immediately after the
division header.
The program name can be up to 8 characters long
on MF(30 in case of windows).
IDENTIFICATION DIVISION...
Is used to identify the program to the computer.
Is the least significant DIVISION of a COBOL
program.
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
The ENVIRONMENT DIVISION is totally
optional unless you want to use files /
specify special devices to the compiler in
ENVIRONMENT
DIVISION.
ENVIRONMENT
DIVISION.
your
program.
CONFIGURATION
CONFIGURATIONSECTION.
SECTION.
IsSOURCE-COMPUTER.
VAX-6410.
used to indicate the Specific
Computers
SOURCE-COMPUTER.
VAX-6410.
OBJECT-COMPUTER.
IBM-ES9000.
OBJECT-COMPUTER.
IBM-ES9000.
used
to develop and execute
the program.
INPUT-OUTPUT
SECTION.
INPUT-OUTPUT
SECTION.
The
general
format
of ED is
FILE-CONTROL.
FILE-CONTROL.
SELECT
SELECTEMPL-FILE
EMPL-FILEASSIGN
ASSIGNTO
TO
DISC.
DISC.
......
DATA DIVISION
Is used to describe the structure of the fields,
records, files and temporary variables used for
calculations.
DATA DIVISION.
/ Optional entry
FILE SECTION.
FD filename
. . . . . . .
SD sortfile
. . . . . . .
WORKING-STORAGE SECTION.
. . . . . . .
PROCEDURE DIVISION
Is the most significant DIVISION of a
COBOL program.
Includes statements and sentences
necessary for reading input, processing it
and writing the output. These are the
instructions that are executed by the
computer at the RUN TIME.
PROCEDURE DIVISION
The PROCEDURE DIVISION is where
all the data described in the DATA
DIVISION is processed and produced
desired results. It is here that the
programmer describes his algorithm.
The PROCEDURE DIVISION is
hierarchical in structure and consists of
Sections, Paragraphs, Sentences and
Statements.
PROCEDURE DIVISION...
Only the Section is optional. There must
be at least one paragraph, sentence and
statement in the PROCEDURE
DIVISION .
In the PROCEDURE DIVISION,
paragraph and section names are chosen
by the programmer.
The names used should reflect the
processing being done in the paragraph or
section.
Sections
A SECTION is a block of code made up of one
or more paragraphs.
A SECTION begins with the section-name and
ends where next section name is encountered or
where the program text ends.
A SECTION name consists of a name devised
by the programmer or defined by the language
followed by the word SECTION followed by a
full stop.
U0000-SELECT-USER-RECORDS SECTION.
FILE SECTION.
s
Each section consists of one or more paragraphs.
A PARAGRAPH is a block of code made up of
one or more sentences.
A PARAGRAPH begins with the paragraphname and ends with the next paragraph or section
name or the end of the program text.
The paragraph-name consists of a name devised
by the programmer or defined by the language
followed by a full stop.
P0000-PRINT-FINAL-TOTALS.
PROGRAM-ID.
Statements
A PARAGRAPH consists of one or more sentences.
A SENTENCE consists of one or more statements and is terminated by
a full stop.
MOVE .21 TO VAT-RATE
COMPUTE VAT-AMOUNT = PRODUCT-COST * VAT-RATE.
DISPLAY "Enter Name " WITH NO ADVANCING
ACCEPT STUDENT-NAME
DISPLAY "Name Entered was " STUDENT-NAME.
A STATEMENT consists of a COBOL verb and an operand or
operands.
SUBTRACT T-TAX FROM GROSS-PAY GIVING NET-PAY
READ STUDENT-FILE
AT END SET END-OF-FILE TO TRUE
END-READ
directive
$ SET SOURCEFORMAT"FREE" frees us
from
all formatting restrictions.
$ SET SOURCEFORMAT"FREE"
$ SET SOURCEFORMAT"FREE"
IDENTIFICATION
IDENTIFICATIONDIVISION.
DIVISION.
PROGRAM-ID.
PROGRAM-ID. ProgramFragment.
ProgramFragment.
**This
Thisisisaacomment.
comment.ItItstarts
starts
**with
withan
anasterisk
asteriskinincolumn
column11
* Area A
/
7
2
Area B
8
0
I
D
E
N
T
I
F
I
C
A
T
I
O
N
A
R
E
A
Literals
Literals are symbols whose value does not
change
in a program.
There are 3 types of literals namely
(1) Numeric literals.
(2) Non-numeric literals.
(3) Figurative constants.
Literals
Numeric literals
Are formed using digits only.
May include a sign which must be the extreme
left character.
There must not be any blank between the sign
and
the first digit.
May include a decimal point which can not be
the
right most character.
Can have at most 18 digits.
Literals
Non-numeric literals
Are used display headings or messages.
Are a sequence of characters (except quotes)
from
the COBOL character set enclosed within
quotes.
May contain up to 160 characters including
spaces.
Literals
Figurative
constants
Figurative constants
Meaning
ZERO(S) or ZEROES
SPACE(S)
HIGH-VALUE(S)
LOW-VALUE(S)
QUOTE(S)
Data names
Are named memory locations.
Must be described in the DATA DIVISION
before they can be used in the PROCEDURE
DIVISION.
Can be of elementary or group type.
Can be subscripted.
Are user defined words.
Purpose
Record description and independent items
Fields within records and sub items
66
RENAMES clause
77
Independent items
88
Condition names
Meaning
Numeric
Alphabetic
Alphanumeric
Decimal Point
Sign bit
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
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
Items/Records
WORKING-STORAGE
WORKING-STORAGE SECTION.
SECTION.
01
STUDENT-DETAILS.
01 STUDENT-DETAILS.
02
02 STUDENT-NAME.
STUDENT-NAME.
03
PIC
03 SURNAME
SURNAME
PIC X(008).
X(008).
03
PIC
03 INITIALS
INITIALS
PIC X(002).
X(002).
02
STUDENT-ID
PIC
9(007).
02 STUDENT-ID
PIC 9(007).
02
COURSE-CODE
PIC
02 COURSE-CODE
PIC X(004).
X(004).
02
PIC
02 GRANT
GRANT
PIC 9(004).
9(004).
02
GENDER
PIC
X(001).
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
SURNAME
STUDENT-ID
INITIALS
PICX(004).
9(007).
PIC
PIC
X(004).
PIC 9(004).
PIC
9(004).
PIC X(001).
PIC X(001).
05 COURSE-CODE
STUDENT-ID
05
05
COURSE-CODE
05 GRANT
05
GRANT
05 GENDER
05 GENDER
PICX(004).
9(007).
PIC
PIC
X(004).
PIC 9(004).
PIC
9(004).
PIC X(001).
PIC X(001).
Break
Meaning
Zero suppression
Check protection
Comma insertion
Meaning
Dollar sign insertion
CR
Credit symbol
DB
Debit symbol
Blank insertion
Slash insertion
Examples
(1) DISPLAY The sum is SUM.
Arithmetic Verbs
ADD
SUBTRACT
MULTIPLY
DIVIDE
COMPUTE
ADD Verb
Syntax-1
ADD { identifier-1, literal-1 } [ , identifier-2,
literal-2 ] . . . TO identifier-3 [ , identifier-4 ] . . .
Syntax-2
ADD { identifier-1, literal-1 } { identifier-2, literal2 } [ identifier-3, literal-3 ] GIVING identifier-4 . . .
ADD Verb
Examples
(1) ADD NUM-1 TO NUM-2.
(2) ADD NUM-1, NUM-2 TO NUM-3.
(3) ADD 12, NUM-1, NUM-2 TO NUM-3, NUM-4.
(4) ADD NUM-1, NUM-2 GIVING NUM-3.
(5) ADD 12, NUM-1 GIVING NUM-2, NUM-3.
ADD
Examples
Before
Before
After
After
Before
Before
After
After
Before
Before
After
After
Before
Before
After
After
ADD
ADD Cash
Cash TO
TO Total.
Total.
33
1000
1000
3
1003
ADD
ADD Cash,
Cash, 20
20 TO
TO Total,
Total, Wage.
Wage.
1000
1000123 100
100
333
1023
ADD
ADD Cash,
Cash, Total
TotalGIVING
GIVINGResult.
Result.
1000
1000
0015
333 1000
10030015
ADD
ADDMales
MalesTO
TOFemales
FemalesGIVING
GIVING TotalStudents.
TotalStudents.
1500
0625
2125
1500
0625
1234
1500
0625
1234
SUBTRACT Verb
Syntax
SUBTRACT { identifier-1, literal-1 } [ identifier-2,
literal-2 ] . . . FROM identifier-3 [ , identifier-4 ]
[ , GIVING identifier-5 [ , identifier-6 ] . . . ]
SUBTRACT Verb
Examples
(1) SUBTRACT NUM-1 FROM NUM-2.
(2) SUBTRACT NUM-1, NUM-2 FROM NUM-3.
(3) SUBTRACT 5, NUM-1 FROM NUM-2, NUM-3.
(4) SUBTRACT 12 FROM NUM-1 GIVING NUM2.
(5) SUBTRACT NUM-1 FROM NUM-2 GIVING
NUM-3.
SUBTRACT Examples
Before
Before
After
After
Before
Before
After
After
Before
Before
After
After
SUBTRACT
SUBTRACT Tax
Tax FROM
FROMGrossPay,
GrossPay,Total.
Total.
120
4000
9120
120
4000
9120
120
3880 9000
SUBTRACT
SUBTRACT Tax,
Tax,80
80FROM
FROMTotal.
Total.
100
300 480
100
100
480
750
1000
0250
SUBTRACT
SUBTRACT Tax
Tax FROM
FROMGrossPay
GrossPayGIVING
GIVINGNetPay.
NetPay.
750
1000
0012
750
1000
0012
MULTIPLY Verb
Syntax
MULTIPLY { identifier-1, literal-1 } BY identifier-2
MULTIPLY Verb
Examples
(1) MULTIPLY NUM-1 BY NUM-2.
(2) MULTIPLY NUM-1 BY NUM-2 GIVING
NUM-3.
(3) MULTIPLY 5 BY NUM-1 GIVING NUM-2.
(4) MULTIPLY NUM-1 BY NUM-2 GIVING
NUM-4, NUM-5.
DIVIDE Verb
Syntax-1
DIVIDE { identifier-1, literal-1 } INTO identifier-2
[ , identifier-2 ] . . . [ GIVING identifier-4
[ , identifier-5 ] . . . ] ..
Syntax-2
DIVIDE { identifier-1, literal-1 } BY { identifier-2,
literal-2 } GIVING identifier-3 [ , identifier-4 ].
DIVIDE Verb
Syntax-3
DIVIDE { identifier-1, literal-1 } { INTO , BY }
{ identifier-2, literal-2 } GIVING identifier-3
REMAINDER identifier-4 .
DIVIDE Verb
Examples
(1) DIVIDE 5 INTO NUM-1.
(2) DIVIDE 6 INTO NUM-1 GIVING NUM-2,
NUM-3.
(3) DIVIDE NUM-1 BY 3 GIVING NUM-2, NUM-3.
(4) DIVIDE NUM-1 BY NUM-2 GIVING NUM-3.
(5) DIVIDE NUM-1 BY NUM-2 GIVING NUM-3
REMAINDER NUM-4.
Subs
Subs
15.50
15.50
15.50
100
3550
Before
Before
After
After
Before
Before
After
After
Members
Members TotalSubs
TotalSubs
100
100
1550.00
0123.45
0123.45
1250
MULTIPLY
MULTIPLY10
10BY
BYMagnitude,
Magnitude, Size.
Size.
355
125
355
125
9234.55
100
92.35
DIVIDE
DIVIDE Total
Total BY
BY Members
MembersGIVING
GIVINGAverage
Average ROUNDED.
ROUNDED.
9234.55
100
1234.56
9234.55
100
1234.56
ROUNDED Option
Syntax
Arithmetic statement [ ROUNDED ].
Examples
(1) ADD NUM-1, NUM-2, NUM-3 GIVING NUM-4
ROUNDED.
(2) DIVIDE NUM-1 BY NUM-2 GIVING NUM-3
ROUNDED.
The ROUNDED
option
Receiving Field Actual Result Truncated Result Rounded Result
PIC 9(3)V9.
123.25
123.2
123.3
PIC 9(3).
123.25
123
123
Examples
(1) ADD NUM-1, NUM-2, NUM-3 TO NUM-4 ON SIZE
ERROR PERFORM 900-EXIT-PARA.
(2). DIVIDE NUM-1 BY NUM-2 ON SIZE ERROR
PERFORM 800-ERROR-PARA.
Actual Result
245.96
1245.9
PIC 9(3).
124
PIC 9(3).
1246
124.45
124.45
3124.45
SIZE ERROR
Yes
Yes
No
Yes
Yes
No
Yes
COMPUTE Verb
Syntax
COMPUTE identifier-1 . . . [ ROUNDED ]
= algebraic expression [ ON SIZE ERROR ]
imperative statement.
Example
COMPUTE VOLUME = ( 4 / 3) * ( 22 / 7 ) * R ** 3.
Note: If the ROUNDED and ON SIZE ERROR both
appear, then the ROUNDED option should precede the
ON SIZE ERROR.
The
COMPUTE
NOT ON SIZE ERROR
Precedence
Precedence Rules.
Rules.
1.
1.
2.
2.
3.
3.
Before
Before
After
After
****
**
//
++
--
== POWER
POWER
== MULTIPLY
MULTIPLY
== DIVIDE
DIVIDE
== ADD
ADD
== SUBTRACT
SUBTRACT
NNNN
xx
++
--
Compute
ComputeIrishPrice
IrishPrice==SterlingPrice
SterlingPrice//Rate
Rate ** 100.
100.
1000.50
156.25
87
1000.50
156.25
87
179.59
156.25
87
Review
Features of COBOL.
General Coding and Format rules.
Language Fundamentals.
Input and Output verbs.
Arithmetic verbs.
Review questions
If an entry must begin in area A ,it must begin in
Column number 8,9,10,11
Review questions
A numeric literal in COBOL can have at most18 digits
A Non numeric literal can have maximum
160 characters including spaces
Indicate True or False
False
A 01 level entry cannot have a picture class
In COBOL a data name must contain at least 8
characters False
A COBOL sentence consists of one or more than one
statement the last of which is terminated by a period
True
Any
Questions ????
Thank you