Академический Документы
Профессиональный Документы
Культура Документы
BUSINESS ORIENTED
LANGUAGE)
Overview
COBOL
Fundamentals DAY1
Day
1:
Introduction to COBOL
Evolution, Features & Language Fundamentals
Program Structure
Data description entry
Session Plan
M.K.Roy
Nancy
Newcomer
References
History of COBOL
What
Which
So
COBOL
DIVISIONS
SECTIONS
PARAGRAPHS
SENTENCES
STATEMENTS
FROM
GROSSCHARACTERS
PAY GIVING NET-PAY
Character
Meaning
Space
+
Plus sign
Asterisk
Equal sign
Currency sign1
Comma
Semicolon
"
Quotation mark2
Left parenthesis
Right parenthesis
>
Greater than
<
Less than
Colon
'
Apostrophe
A-Z
Alphabet (uppercase)
a-z
Alphabet (lowercase)
0-9
Numeric characters
IDENTIFICATION DIVISION
Compiler takes this as
Program Identifier.
PROGRAM-ID comes
immediately after ID
Division.
IDENTIFICATION
IDENTIFICATIONDIVISION.
DIVISION.
PROGRAM-ID.
PROG1.
PROGRAM-ID.
PROG1.
AUTHOR.
R.R.
AUTHOR.
R.R.BHATT.
BHATT.
INSTALLATION.
ABC
CORP.
INSTALLATION.
ABC CORP.
DATE-WRITTEN.
01-JAN-2005.
DATE-WRITTEN.
01-JAN-2005. OPTIONAL
DATE-COMPILED.
01-JAN-2005.
DATE-COMPILED.
01-JAN-2005.
SECURITY.
HIGH.
SECURITY.
HIGH.
ENVIRONMENT DIVISION
ENVIRONMENT DIVISION
CONFIGURATION SECTION
INPUT-OUTPUTT SECTION
Identifies the
computer used for
compiling of programs
Identifies the
resources used for
executing the program
DATA DIVISION
The DATA DIVISION is used to describe the data structures used in the
program.
The
FILE SECTION
WORKING-STORAGE SECTION
LINKAGE SECTION
REPORT SECTION
two most commonly used components (sections) are
a) WORKING-STORAGE SECTION
Internal data structures are defined here.
b) FILE SECTION
File I/O buffer areas are defined here.
DATA DIVISION.
FILE SECTION.
FD INVENTORY-FILE
RECORD CONTAINS 78 CHARACTERS.
01 INVENTORY-REC.
05 IF-PART-NUMBER
05
05 IF-WHSE-LOCS.
10 IF-MAIN-LOC
10 IF-ALT-LOC
05
FD PRINT-FILE.
01 PRINT-REC.
05
05 P-PART-NUMBER
05
05 P-MAIN-LOC
05
05 P-ALT-LOC
WORKING-STORAGE SECTION.
01 FLAGS.
05 F-MORE-RECORDS
DATA DIVISION
PIC X(09).
PIC X(24).
PIC X(06).
PIC X(06).
PIC X(33).
PIC
PIC
PIC
PIC
PIC
PIC
X(10).
X(09).
X(05).
X(06).
X(05).
X(06).
Sections
Paragraphs
Sentences
StatementsDIVISION ..
PROCEDURE
Section
PROCEDURE DIVISION.
0001-ACCOUNT-SECTION.
Paragraph
A PARAGRAPH
comprises of one or
more sentences
001-ACCOUNT-READ-PARA.
READ ACC-FILE AT END
MOVE Y TO EOF.
MOVE TAX-REDUCT TO TAX-AMOUNT
001-ACCOUNT-VALIDATE-PARA.
ADD AMOUNT TO TOT-AMOUNT.
ACCEPT EMPLOYEE-SALARY
DISPLAY Current Employee Salary
EMPLOYEE-SALARY.
001-EXIT-PARA.
STOP RUN.
Sentences
A SENTENCE is a
combination of one or
more statements and is
terminated by a full
stop.
statement
PROCEDURE DIVISION
A STATEMENT is a
combination of a
COBOL verb and one
or more operands.
IDENTIFICATION
IDENTIFICATIONDIVISION.
DIVISION.
PROGRAM-ID.
PROGRAM-ID. FIRSTPG.
FIRSTPG.
PROCEDURE
PROCEDUREDIVISION.
DIVISION.
A0000-MAIN-PARA.
A0000-MAIN-PARA.
DISPLAY
DISPLAY-------------------------------.
-------------------------------.
DISPLAY
DISPLAY WELCOME
WELCOMETO
TOCOBOL.
COBOL.
DISPLAY
--------------------------------.
DISPLAY --------------------------------.
STOP
STOPRUN.
RUN.
Column
numbers
8 9 10
Area A
11
12
72
Area B
80
I
D
E
N
T
I
F
I
C
A
T
I
O
N
A
R
E
A
AREA A
AREA B
*) Between Column 8 to 11
*) Division, Section, Paragraph
names, FD entries & 01
level entries must start in
Area A
*) Between Column 12 to 72
*) All Sentences & Statements
start in Area B
Each
( A)
Numeric( 9)
Alphanumeric (X)
Edited numeric ( Z, $)
Edited alphanumeric(/,-)
Are
Must
Can
be of elementary or group
type.
Can
Are
Data names
Can
be at most 30 characters in
length.
Only
Blanks
May
Should
All
DATA DIVISION.
01 WS-EMPL-NO PIC X(10) VALUE 1001.
Data Name
Picture Clause
Clause
Level number
Level Number
01
02 to 49
Purpose
66
RENAMES clause
77
Independent items
Code
PICTURE
clause
Piture Clause
Meaning
Numeric
Alphabetic
Alphanumeric
Implicit Decimal
Sign bit
Some examples
PICTURE
PICTURE
PICTURE
PICTURE
99.99
PICTURE
999
S999
XXXX
99V99
S9V9
Recurring
Abbreviating recurring
symbols
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Num1
PIC 999
VALUE ZEROS.
01 VatRate
PIC V99
VALUE .18.
01 StudentName
PIC X(10) VALUE SPACES.
DATA
Declaring
DATA in COBOL
Num1 VatRate
Num1 VatRate
000
000
.18
.18
StudentName
StudentName
VALUE clause
Is an optional clause.
Literals
Literals
Figurative constants
Meaning
ZERO(S) or ZEROES
SPACE(S)
HIGH-VALUE(S)
LOW-VALUE(S)
QUOTE(S)
01
01 StudentName
StudentName
PIC
PIC X(10)
X(10) VALUE
VALUE "MIKE".
"MIKE".
MOVE
MOVE ALL
ALL "-"
"-" TO
TO StudentName.
StudentName.
StudentName
M I K E
01
01 StudentName
StudentName
PIC
PIC X(10)
X(10) VALUE
VALUE "MIKE".
"MIKE".
MOVE
MOVE ALL
ALL "-"
"-" TO
TO StudentName.
StudentName.
StudentName
- - - - - - - - - -
WORKING-STORAGE SECTION.
SECTION.
01WORKING-STORAGE
EMPLOYEE-DETAILS
PIC X(30).
01 EMPLOYEE-DETAILS PIC X(30).
01 EMPLOYEE-DETAILS.
0105EMPLOYEE-DETAILS.
EMP-NUM
PIC 9(4).
EMP-NUM PIC
PICX(10).
9(4).
0505EMP-NAME
EMP-NAME PIC
PICX(4).
X(10).
0505EMP-DEPT
05
EMP-DEPT
PIC
X(4).
05 EMP-LOC
PIC X(12).
05 EMP-LOC
PIC X(12).
WORKING-STORAGE SECTION.
SECTION.
01WORKING-STORAGE
EMPLOYEE-DETAILS
PIC X(20).
01 EMPLOYEE-DETAILS PIC X(20).
01 EMPLOYEE-DETAILS.
0105EMPLOYEE-DETAILS.
EMP-NUM
PIC 9(4).
EMP-NUM PIC
PICX(10).
9(4).
0505EMP-NAME
05
EMP-NAME
PIC
X(10).
05 EMP-DEPT PIC X(4).
05
EMP-DEPT
PIC
X(4).
05 EMP-LOC
PIC X(12).
05 EMP-LOC
PIC X(12).
Group item
Sub-Items
123456789012345678901234567890
1234JyothiS
E&R Bangalore
2234Archana
E&R Marathi
9999Bhushan
E&R C++
(cols)
Value
WORKING-STORAGE SECTION.
SECTION.
01WORKING-STORAGE
EMPLOYEE-DETAILS
PIC X(30). 1234JyothiS
01 EMPLOYEE-DETAILS PIC X(30). 1234JyothiS
E&R Bangalore
E&R Bangalore
Value
1234JyothiS
1234JyothiS
1234
1234
JyothiS
JyothiS
E&R
E&R
Bangalore
Bangalore
E&R Bangalore
E&R Bangalore
WORKING-STORAGE SECTION.
01WORKING-STORAGE
POLICY-DETAILS.SECTION.
0105POLICY-DETAILS.
POLICY-NO.
05 10
POLICY-NO.
POLICY-TYP PIC X(4).
POLICY-TYP PIC
PICX(2).
X(4).
1010POLICY-LOC
10
POLICY-LOC
PIC
X(2).
10 POLICY-ID
PIC X(5).
10
POLICY-ID
PIC
X(5).
05 POLICY-TYPE
PIC X(10).
05
POLICY-TYPE
PIC
X(10).
05 POLICY-EXPDT PIC X(10).
05 POLICY-EXPDT PIC X(10).
In COBOL, Level
numbers are used to
express data hierarchy.
The higher the level
number, the lower the
item is in the hierarchy.
So Group items contain
sets of elementary
items with lower level
numbers. At the lowest
level the data is
DATA
completely atomic.
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.
ds
WORKING-STORAGE SECTION.
WORKING-STORAGE
01
StudentDetailsSECTION. PIC X(26).
01 StudentDetails
PIC X(26).
StudentDetails
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
ds
WORKING-STORAGE SECTION.
WORKING-STORAGE
SECTION.
01
StudentDetails.
01 02
StudentDetails.
StudentName
02
StudentName
02 StudentId
02 CourseCode
StudentId
02
02
CourseCode
02 Grant
02 Gender
Grant
02
02 Gender
PIC X(10).
PIC9(7).
X(10).
PIC
PICX(4).
9(7).
PIC
PIC
X(4).
PIC 9(4).
PICX.
9(4).
PIC
PIC X.
StudentDetails
H EN N E S S Y RM 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F
StudentName
StudentId
CourseCode Grant
Gender
ds
WORKING-STORAGE SECTION.
WORKING-STORAGE
SECTION.
01
StudentDetails.
01 02
StudentDetails.
StudentName.
02 03
StudentName.
Surname
03Initials
Surname
03
03
Initials
02 StudentId
02 CourseCode
StudentId
02
02
CourseCode
02 Grant
02 Gender
Grant
02
02 Gender
PIC X(8).
PICXX.
X(8).
PIC
PIC
XX.
PIC 9(7).
PICX(4).
9(7).
PIC
PIC
X(4).
PIC 9(4).
PICX.
9(4).
PIC
PIC X.
StudentDetails
H EN N E S S Y RM 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F
StudentName
Surname
StudentId
Initials
CourseCode Grant
Gender
MOVE VERB
Overview
The MOVE
Verb
Identifier
Literal
MOVE
TO Identifier ...
MOVE
MOVE
MOVE
MOVE
When
Data
MOVE
MOVE RYAN
RYAN TO
TO Surname.
Surname.
MOVE
FITZPATRICK
MOVE FITZPATRICK TO
TO Surname.
Surname.
01 Surname
PIC X(8).
C O U G H L A N
Data
MOVE
MOVE RYAN
RYAN TO
TO Surname.
Surname.
MOVE
FITZPATRICK
MOVE FITZPATRICK TO
TO Surname.
Surname.
01 Surname
R Y
A N
PIC X(8).
Data
MOVE
MOVE RYAN
RYAN TO
TO Surname.
Surname.
MOVE
FITZPATRICK
MOVE FITZPATRICK TO
TO Surname.
Surname.
01 Surname
F I T
Z P
PIC X(8).
A T R I C K
MOVEing to a
numeric item.
When
When
01 GrossPay
PIC 9(4)V99.
GrossPay
0 0 0 0 0 0
GrossPay
0 0 1 2
4 0
GrossPay
0 1
2 3
4 5 6
01 CountyPop
01 Price
PIC 999.
PIC 999V99.
CountyPop
1 2 3 4
CountyPop
0 1
1 5 4
Price
MOVE 154 TO Price.
2 4
0 0
3 5 5 2
7 5
Price
Before
After
WS00-OUT1
0000
WS00-OUT1
3456
WS00-OUT2
000000
WS00-OUT2
345678
Before
WS00-OUT3
000000
After
WS00-OUT3
Before
WS00-OUT4
After
00000000
WS00-OUT4
12345678
123456
MOVE .. example
****************************
Output SPOOL
WS00-OUT1 : HARAYANA
WS00-OUT2 : HARAYANA
****************************
DISPLAY
Verb
Identifier
Literal
DISPLAY
Identifier
...
Literal
The
The ACCEPT
verb
Format 1. ACCEPT Identifier FROM Mnemonic - name
DATE
DAY
01
CurrentDate
CurrentDate
*01
YYMMDD
PIC
PIC 9(6).
9(6).
01
DayOfYear
DayOfYear
*01
YYDDD
PIC
PIC 9(5).
9(5).
01
Day0fWeek
Day0fWeek
*01
D (1=Monday)
PIC
PIC 9.
9.
01
CurrentTime
CurrentTime
*01
HHMMSSss
s = S/100
PIC
PIC 9(8).
9(8).
* YYMMDD
* YYDDD
* D (1=Monday)
* HHMMSSss
s = S/100
IDENTIFICATION DIVISION.
PROGRAM-ID.
AcceptAndDisplay.
IDENTIFICATION
DIVISION.
AUTHOR.
Michael
Coughlan.
PROGRAM-ID.
AcceptAndDisplay.
AUTHOR. Michael Coughlan.
DATA DIVISION.
WORKING-STORAGE
DATA DIVISION. SECTION.
01WORKING-STORAGE
StudentDetails.SECTION.
StudentName.
0102StudentDetails.
Surname
PIC X(8).
02 03StudentName.
0303Initials
PIC
Surname
PICXX.
X(8).
02 StudentId
PIC
03 Initials
PIC9(7).
XX.
0202 CourseCode
PIC
StudentId
PICX(4).
9(7).
0202 Grant
PIC
CourseCode
PIC9(4).
X(4).
0202 Gender
PIC
Grant
PICX.9(4).
02 Gender
PIC X.
01 CurrentDate.
CurrentYear
PIC 99.
0102CurrentDate.
0202 CurrentMonth
PIC
CurrentYear
PIC99.
99.
0202 CurrentDay
PIC
CurrentMonth
PIC99.
99.
02 CurrentDay
PIC 99.
01 DayOfYear.
FILLER
PIC 99.
0102DayOfYear.
0202 YearDay
PIC
FILLER
PIC9(3).
99.
02 YearDay
PIC 9(3).
01 CurrentTime.
CurrentHour
PIC 99.
0102CurrentTime.
0202 CurrentMinute
PIC
CurrentHour
PIC99.
99.
0202 FILLER
CurrentMinute PIC
PIC9(4).
99.
02 FILLER
PIC 9(4).
PROCEDURE DIVISION.
PROCEDURE DIVISION.
Begin.
Begin.
DISPLAY "Enter student details using template below".
DISPLAY"NNNNNNNNNNSSSSSSSCCCCGGGGS
"Enter student details using template below".
DISPLAY
".
DISPLAYStudentDetails.
"NNNNNNNNNNSSSSSSSCCCCGGGGS
".
ACCEPT
ACCEPT CurrentDate
StudentDetails.
ACCEPT
FROM DATE.
ACCEPT DayOfYear
CurrentDate
ACCEPT
FROMFROM
DAY.DATE.
ACCEPT CurrentTime
DayOfYear FROM
ACCEPT
FROM DAY.
TIME.
ACCEPT "Name
CurrentTime
FROM TIME.
DISPLAY
is ", Initials
SPACE Surname.
DISPLAY"Date
"Nameisis" ",
Initials SPACE
SPACE CurrentMonth
Surname.
DISPLAY
CurrentDay
SPACE CurrentYear.
DISPLAY"Today
"Date is
is day
" CurrentDay
CurrentMonth
SPACE CurrentYear.
DISPLAY
" YearDay SPACE
" of the
year".
DISPLAY
DISPLAY"The
"Today
timeisisday
" CurrentHour
" YearDay " ":"
of the
CurrentMinute.
year".
DISPLAY
STOP
RUN. "The time is " CurrentHour ":" CurrentMinute.
STOP RUN.