Upload
tesundarram
View
244
Download
0
Embed Size (px)
Citation preview
8/6/2019 Cobol Session1
1/44
8/6/2019 Cobol Session1
2/44
2
Abbreviation ofCOmmon Business Oriented Language
One of the oldest computer languages in use (Was developed in late 1950s)
Mainly Used for Information processing in BusinessApplications
Used for generating reports through Batch Processing
Batch processing is also known as periodical processing
Batch Processing Examples: Generation of Utility Bills, Payroll Processing etc.
Also used in Online applications under CICS environment.
Online Processing Examples: Railway/Airline Reservation System, Online
Banking etc.
What is COBOL?
8/6/2019 Cobol Session1
3/44
3
High Level Language
English-like constructs
Self-documenting Language
File handling capability
Easy to write
Available across several platforms
Largely Machine independent
Advantages ofCobol
8/6/2019 Cobol Session1
4/44
4
COBOL was Developed In 1959 By AGroup Called CODASYL (COnference on
DAta SYstems Language).
LaterANSI standards were introduced
COBOL 68
COBOL 74
COBOL 85
COBOL 2003 ( Enterprise COBOL )
History ofCobol
8/6/2019 Cobol Session1
5/44
5
Future ofCobol
COBOL will remain an important language in future also Billions of lines of COBOL source are currently in use with millions added each
year
1000s of COBOL programmers retire every year
There is a continuous requirement of TRAINED man power in COBOL for
Maintenance and Development of COBOL based applications.
8/6/2019 Cobol Session1
6/44
6
Features Of COBOL
Oriented towardsbusiness applications
English-like
Self-Documenting
Machine independent
Easy to Learn / Read / Write / Test
I/O operations easily designated
Structured Programming Support
8/6/2019 Cobol Session1
7/44
7
COBOL 74 STD.
OS/VS COBOL VS COBOL II COBOL/370 COBOL FOR MVS & VM
COBOL 85 STD.
DBCS,IMPROVED
CICS
INTERFACE,
31 BIT
ADDRESSING ,
SAA SUPPORT,
ETC.
COBOL 74 STD.
COBOL 85 STD.
DBCS,IMPROVED
CICS
INTERFACE,
31 BIT
ADDRESSING,
SAA SUPPORT,
ETC.
COBOL 74 STD. COBOL 74 STD.
COBOL 85 STD.
DBCS,IMPROVED
CICS
INTERFACE,
31 BIT
ADDRESSING,
SAA SUPPORT,
ETC.
INTRINSICFUNCTIONS,
SUPPORT FOR
LANGUAGE
ENVIRONMENT
INTRINSICFUNCTIONS,
SUPPORT FOR
LANGUAGE
ENVIRONMENT
EXTENSIONS
FOR OOCOBOL,
C INTEROP.
IBM's latest host COBOL compiler
COMPARISON OF IBM COBOL
COMPILERS
8/6/2019 Cobol Session1
8/44
8
Application Development Cycle
- For writing a COBOL program you have to be provided with program
specification by your BUSINESSANALYST
- ANALYST studies a customers requirement for an application package and
prepares an over all design and finally comes out with a detailed specification for
every program to be developed under an application
- The specification will contain the details of INPUT/OUTPUT file descriptions,OUTPUT report layouts and descriptions, Processing logic and rules, Calculation
methods, etc.
- A Programmer/ Developer writes the code for each module. And tests each
module after development.
- A Testerprepares a plan for testing and also prepares a set of Test data to test
and ensure that the programs work as intended by the designer and customer
8/6/2019 Cobol Session1
9/44
9
BusinessAnalyst
System Analyst
Programmer Tester
End User
8/6/2019 Cobol Session1
10/44
10
ACOBOL PRO
GRA
M IS DIVIDED IN
TO
Divisions
Sections
Paragraphs
Sentences
Statements
Words
Characters
Components of a COBOL program
8/6/2019 Cobol Session1
11/44
11
| | | | |
| | | | |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 || 71 | 72 |
|---------- ------| |------ ---|------------------------------ ------------------|1
2
3 4
Columns
1. Sequence NumberArea
2. Indicator Area
3. Area A or Margin A
4. Area B or Margin B
COBOL Coding Format
IndicatorArea Characters
a. * (Asterisk) Comment
b. / (Slash) - Comment + page feed
c. - (Hyphen) - String Continuation
8/6/2019 Cobol Session1
12/44
12
Sequence NumberArea:
Columns 1 6 - Line numbers. Each line of code may have a 6 digit
line number. Line numbers to be in ascending order
IndicatorArea
* in column 7 Line treated as a comment ; Shown in the source listing
/ in column 7 Line treated as a comment ; Source listing begins a
new page before printing the line
- ( hyphen ) in column 7 Line treated as continuation ofprevious line
Except when non-numeric literals are continued, all trailing spaces on
the preceding line and all leading spaces on the continuation line, are
ignored
Source Coding Rules
8/6/2019 Cobol Session1
13/44
13
Source Coding Rules (contd.)
Area A
AreaA (columns 8 thru 11)
AreaA Reserved for DIVISION, SECTION & PARAGRAPH headers, File
description entry indicators (FD & SD), level numbers 01 and 77.
Comment lines also accepted, provided column 7 contains an * or /.
Area B
Area B (Columns 12 72 )
Reserved for Filenames associated with FD or SD indicators and the
SELECT clause of Input-Output Section.Level nos. 02 to 49 and 66 and 88
Descriptive clauses and/or data descriptions that make up specific
paragraph entries. Continuation lines, provided column 7 contains a -
(hyphen).
it
8/6/2019 Cobol Session1
14/44
FOUR DIVISIONS OFCOBOL
14
DIVISION
S/SECTION
S identify various parts of a COBOL program.
File declarations, descriptions, temporary variables, processing logic,
communication with otherprograms etc., are handled by various DIVISONS/
SECTIONS of a COBOL program.
There are four DIVISIONS in all.
IDENTIFICATION DIVISION. ( MANDATORY )
ENVIRONMENT DIVISION. ( OPTIONAL )
DATA DIVISION. ( OPTIONAL )
PROCEDURE DIVISION. ( MANDATORY )
8/6/2019 Cobol Session1
15/44
FUNCTIONS OF THE FOUR DIVISIONS.
15
The IDENTIFICATION DIVISION is used to specify the name of program
and programmer.
The ENVIRONMENT DIVISION is used to define the data sets that are used
by a program and links the data sets to the corresponding DD names of JCL
The DATADIVISION is used to provide the complete descriptions of data
sets including record description and field description and working storage
variables.
The PROCEDURE DIVISION contains executable instructions ( statements
containing VERBS ) to process the data contained in DATADIVISION.
COBOL provides a means for specifying sequence, selection and iteration
constructs to code yourprocessing logic.
8/6/2019 Cobol Session1
16/44
16
COBOL coding lines start in MarginA or Margin B
DIVISION, SECTION, PARAGRAPH names start in Margin A
FD entries,01,77 level entries, Procedure division paragraph names start in
Margin A
STATEMENTS, 02-49, 66, 88 level entries start in Margin B
Procedure division sentences, statements start in Margin B
COBOL coding rules
8/6/2019 Cobol Session1
17/44
17
1 2 3 4 5 6 7
123456789012345678901234567890123456789012345678901234567890123456789012
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE1.
AUTHOR. SRG.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 NUM1 PIC 9 VALUE ZEROS.
77 NUM2 PIC 9 VALUE ZEROS.
77 RESULT PIC 99 VALUE ZEROS.
77 WS-NAME PIC X(10) VALUE ARICH INFOTECHS.
PROCEDURE DIVISION.
CALC-RTN1.
ACCEPT NUM1.
ACCEPT NUM2.
MULTIPLY NUM1 BY NUM2GIVING RESULT.
DISPLA
Y "RESULT IS = ", RESULT.STOP RUN.
Sample COBOL program
8/6/2019 Cobol Session1
18/44
What is COBOL and where it is used?
What are the advantages of COBOL?
Who is a Business Analyst?
How is a COBOL Program classified into?
How many divisions are available in COBOL? Name them.
18
Recap!!!!!!
8/6/2019 Cobol Session1
19/44
19
Identification Division
- THE SMALLEST- USED TO IDENTIFY THE PROGRAM AND AUTHOR
- NO SECTIONS
- CONTAINS ONLY PARAGRAPHS
IDENTIFICATION DIVISION
PROGRAM-ID. TEST123.
AUTHOR. TESM.
INSTALLATION. ARICH INFOTECH.
DATE-WRITTEN. 17-01-2010.
DATE-COMPILED. 18-01-2010.
- PROGRAM-ID is the only required Paragraph for this division.
- Program name can be only 8 characters
- All other entries are optional and for documentation purposes only
8/6/2019 Cobol Session1
20/44
20
N I N N I I I N
his follows the identification division.
his is the most hardware dependent division. he computer and other device requirements are described in this
section.
It has two sections.
N I N N I I I N.
C NFIGU ATI N CTI N.U C -C PUTER. 390. (where the program is compiled)
OBJECT-COMPUTER. DECALPHA. (where the program is executed)
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT employee-master ASSIGN TO DD1
organization is sequential.
I-O-CONTROL.
SPECIAL-NAMES.
CURRENCY SIGN IS literal-1.
DECIMAL POINT IS COMMA.
8/6/2019 Cobol Session1
21/44
21
DATA DIVISION
- Has TWO sections FILE SECTION and WORKING-STORAGE SECTION
File Section.
- Describes the characteristics of FILES used in the program RECORD SIZE,
BLOCK SIZE, FORMAT ETC
- IT CONTIANS RECORD STRUCTURE AND FIELD DESCRIPTION entries.
Working-Storage Section.
- Declare temporary memory variables used in the program.
- In essence, the contents of FILE SECTION
variables are stored in thedevices like hard disk/printer where as the contents of WORKING-STORAGE
section are in RAM buffers and are lost once the program is terminated
8/6/2019 Cobol Session1
22/44
22
DATA DIVISION
DA
TA
DIVISIONHA
SF
ou
r SEC
TIONS
FILE SECTION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
LOCAL-STORAGE SECTION.
REPORT SECTION
SCREEN SECTION.
The last 2 sections are not supported in IBM MAINFRAME COBOL
SCREEN SECTION REQUIREMENTSARE TAKEN CARE BY THE OLTP
SOFTWARE CICS
8/6/2019 Cobol Session1
23/44
DATADIVISION
23
The DATADIVISION has the following structure
DATA DIVISION.
FILE SECTION.
.. FILE SECTION ENTRIES ..
WORKING-STORAGE SECTION.
TEMPORARY MEMEORY VARIABLES,GROUPAND
ELEMENTARY ITEMS..
EXAMPLE:
IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE1.
AUTHOR. SRG.
DATA DIVISION.WORKING-STORAGE SECTION.
01 Num1 PIC 9 VALUE ZEROS.
01 Num2 PIC 9 VALUE ZEROS.
01 Result PIC 99 VALUE ZEROS.
8/6/2019 Cobol Session1
24/44
24
Let us start with working-storage section
VARIABLES can be declared in WS section.
Variables are also known as data items or identifiers.
A data item starts with a level number followed by its name, PIC clause andoptionally VALUE and other clauses
A variable name can be maximum of30 chars consisting ofA-Z, 0-9, and
hyphen
No other special characters, no blanks are allowed.
Must have at least one Alphabet
VARIABLES
8/6/2019 Cobol Session1
25/44
25
DATA ITEMS / VARIABLES
DA
TA
ITEMS CAN
BE ELEMEN
TA
RY ORG
ROUP ITEMS
ELEMENTARY ITEM IS ONE THAT IS NOT FURTHER SUBDIVIDED
A SET OF RELATED ELEMENTARY ITEMS IS CALLED AGROUP ITEM
01 LEVEL IS USED FOR DECLARINGGROUP ITEMS
ELEMENTARY ITEMS WHICHARE NOT PART OF ANY GROUP IS
CALLED INDEPENDENT ELEMENTARY ITEMS
Generally Independent elementary items are declared in WS
with level number 77
Independent elementary items can also be declared with level number
01 from COBOL-85 version
8/6/2019 Cobol Session1
26/44
26
DATA ITEMS / VARIABLES (Contd.)
01 AND 77 LEVEL ITEM NAMES MUST BE UNIQUE
01 LEVEL IS ALSO USED FOR DECLARINGGROUP ITEMS ,
IN WHICH CASE IT MAY HAVE SUB LEVEL ITEMS WITH LEVELNUMBERS
02-49
02-49 LEVEL DATA ITEMS MAY have duplicates
01 77 levels are used in MARGIN-A where as other levels in MARGIN-B
8/6/2019 Cobol Session1
27/44
27
Example Code
01 REC1.
05 ID-FIELD1 PIC XX.
05 AMOUNT PIC 9(5)V99.
05 DESCRIPTION PIC X(40).
01 PRINT-REC1.
05 ID-FIELD PIC XX VALUE SPACES.
05 AMOUNT PIC ZZ,ZZ9.99.
05 DESCRIPTION PIC X(40) VALUE SPACES.
PROCEDURE DIVISION.
..
SET-PRINT.
MOVE CORRESPONDING REC1 TO PRINT-REC1.
8/6/2019 Cobol Session1
28/44
28
COBOL Data Types
There are THREE basic data types in COBOL
Numeric, Alphabetic, Alphanumeric
The contents in ALPHANUMERIC items are left justified
The contents in NUMERIC items are right justified
Poor in type Checking
8/6/2019 Cobol Session1
29/44
29
Declare Variables in WS
Variables are declared with a level number, user defined name and PIC clauseWORKING-STORAGE SECTION.
77 WS-NAME PIC X(15) VALUE ARICH INFOTECH.
77 WS-CTR1 PIC 9(6) VALUE 1234. 001234
77 WS-CTR2
PIC 9(4) V
ALUE ZERO.
77 WS-LINE PIC X(10) VALUE ALL -. ------------
77 WS-ADDR PIC X(10) VALUE SPACES.
77 WS-AMT PIC 9(4)v9(3) value 12.56. 0012560
Level number 77 indicates the item is independent data item
PIC means PICTURE Clause indicating the type and size of the item
Type can be X A 9 indicating alphanumeric, alphabetic, Numeric items
8/6/2019 Cobol Session1
30/44
30
Declare Variables in WS (contd.)
VALUE indicates the initial contents of the variable
The constants are three types in COBOL
STRING CONSTANT, NUMERIC CONSTANT, FIGURATIVE CONSTANT
Though the initial values are called constants, the contents canbe modified latein the program.
The max size of X and A is 32000 chars without value clause and 180 with VALUE
clause.
The maximum for numeric data itemmax allowed is 18 digits but mainframe
COBOL allows up to 31 digits. You have to set the compiler option
PARM.COBOL=ARITH(EXTEND)
8/6/2019 Cobol Session1
31/44
31
More examples
77 WS-CTR2 PIC 9(5) VALUE 123. ( STOREDAS 00123 )77 EMP-NAME PIC A(15) VALUE ARICH INFOTECH .
01 EMP-ADDRESS PIC X(12) VALUE 45, I STREET.
01 WS-GRP.
02 WS-EC PIC 9(3).
02 WS-EN PIC X(12).
02
WS-DOB.03 WS-DD PIC 9(2).
03 WS-MM PIC 9(2).
03 WS-YY PIC 9(2).
01 WS-GRP.
05 WS-EC PIC 9(3).
05 WS-EN PIC X(12).
05 WS-DOB.
10 WS-DD PIC 9(2).
10 WS-MM PIC 9(2).
10 WS-YY PIC 9(2).
8/6/2019 Cobol Session1
32/44
32
Figurative Constants
COBOL provides special types of constants called Figurative Constants.
They are:
SPACE or SPACES
ZERO or ZEROS or ZEROES equivalent to 0
HIGH-VALUE or HIGH-VALUES equal to Max Value
This consists of All bits on condition in a variable. Represents a non-
standard, non-printable character used to specify the highest value in the
computers collating sequence.
LOW-VALUE or LOW-VALUES equal to Min Value
8/6/2019 Cobol Session1
33/44
8/6/2019 Cobol Session1
34/44
34
EXAMPLE PROCEDURE DIVISION STATEMENT
IDENTIFICATION DIVISION.
PROGRAM-ID. PRG1.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 WS-NAME PIC X(10) VALUE ARICH INFOTECH.
PROCEDURE DIVISION.
DISPLAY HELLO WS-NAME.
STOP RUN.
Note: DISPLAY statement IN MAIN FRAME COBOL CANNOT
control the LINE or COLUMN position of the SCREEN
8/6/2019 Cobol Session1
35/44
35
You have to use multiple display statements to show the contents onseparate lines
000100 IDENTIFICATION DIVISION.
200 PROGRAM-ID. PRG1.
300 DATADIVISION.
400 WORKING-STORAGE SECTION.500 77 WS-NAME PIC X(10) VALUE ARICH INFOTECH.
600 PROCEDURE DIVISION.
700 DISPLAY HELLO
800 DISPLAY WS-NAME.
900 DISPLAY HOW ARE YOU?.
1000 STOP RUN.
8/6/2019 Cobol Session1
36/44
36
Procedu
re to compile and
execu
te aC
OBOL program
1. Allocate two PDS
2. Enter your COBOL program as a member of PDS
3
. Create a JCL nam
ed COMPLIN
K as follows, inA
RICH03
.COBOL.PDSand submit
//ARICH56R JOB NOTIFY=ARICH03,CLASS=M
// JCLLIB ORDER=(ZOS.PROCLIB)
//S1 EXEC PROC=IGYWCL,MEM=PRG1
//COBOL.SYSIN DD DSN=ARICH03.COBOL.PDS(&MEM),DISP=SHR
//LKED.SYSLMOD DD DSN=ARICH03.LOAD.PDS(&MEM),DISP=SHR
//
8/6/2019 Cobol Session1
37/44
HOW TO EXECUTE YOUR LOAD MODULE?
CREATE A JCL NAMED RUNJCL AS FOLLOWS IN ARICH03.COBOL.PDS
AND SUBMIT
//ARICH03R JOB NOTIFY=&SYSUID,CLASS=M
//JOBLIB DD DSN=ARICH03.LOAD.PDS,DISP=SHR
//S1 EXEC PGM=PRG1
//SYSPRINT DD SYSOUT=*//SYSIN DD *
..
/*
//
==================================================================
NOTE: //GO.SYSIN DD * is to be used for giving the input when we use IGYWCLG
37
8/6/2019 Cobol Session1
38/44
IDENTIFICATION DIVISION.
PROGRAM-ID. PRG1.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 WS-NAME PIC X(10).
77 WS-NUM PIC 9(5).
PROCEDURE DIVISION.
ACCEPT WS-NAME.
DISPLAY WS-NAME.
ACCEPT WS-NUM.DISPLAY WS-NUM.
STOP RUN.
38
ACCEPT
8/6/2019 Cobol Session1
39/44
39
EXAMPLE: 1
IDENTIFICATION DIVISION.
PROGRAM-ID. EX1.
DATADIVISION.
WORKING-STORAGE SECTION.
77NA
ME PIC X(15).01 AGE PIC 9(2).
PROCEDURE DIVISION.
PARA-1.
ACCEPT NAME.
ACCEPT AGE.
DISPLAY HELLO " NAME.
DISPLAY YOUR AGE IS " AGE.
STOP RUN.
8/6/2019 Cobol Session1
40/44
8/6/2019 Cobol Session1
41/44
41
ACCEPT can be used to capture system registers like DATE, TIME etc.
IDENTIFICATION DIVISION.
PROGRAM-ID. PRG1.
DATADIVISION.
WORKING-STORAGE SECTION.
77 WS-DATE PIC 9(8).PROCEDURE DIVISION.
ACCEPT WS-DATE
FROM DATE YYYYMMDD.
DISPLAY WS-DATE.
STOP RUN.
8/6/2019 Cobol Session1
42/44
42
IDENTIFICATION DIVISION.PROGRAM-ID. PRG1.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 WS-TIME PIC 9(8) VALUE 0.
PROCEDURE DIVISION.
ACCEPT WS-TIME FROM TIME.DISPLAY WS-TIME.
STOP RUN.
8/6/2019 Cobol Session1
43/44
8/6/2019 Cobol Session1
44/44
RECAP!!!!!
What is the purpose of using theEnvironment Division?
What are the different section available inData Division.
What is the purpose of a Display statement?
When do you use an ACCEPT keyword?
List out atleast five different Reserved wordsthat you have come across so far.
44