Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
OM Technologies
OM Technologies
OM Technologies
COBOL
COBOL stands for Common Business Oriented Language.
It is the primary programming language used for developing applications on Mainframe.
Even today, COBOL is treated as the BEST programming language for developing business
applications.
OM Technologies
OM Technologies
OM Technologies
OM Technologies
OM Technologies
OM Technologies
10
OM Technologies
11
OM Technologies
12
OM Technologies
Level Number
It is used to describe the data hierarchy.
We can use level numbers 01 to 49 and special level numbers 66, 77 and 88.
13
OM Technologies
14
OM Technologies
01 EMP-DET..
05 EMP-ID
PIC
05 EMP-NAME.
07 FN
PIC
07 MN
PIC
07 LN
PIC
05 EMP-SAL PIC
05 DEPT-ID
PIC
05 EMP-JOIN-DT.
09 YYYY.
11 CC PIC
11 YY PIC
09 MM
PIC
09 DD
PIC
VALUE
VALUE
VALUE
VALUE
VALUE
RAM.
PRASAD.
K.
25000.
D1.
X(2)
X(2)
X(2)
X(2)
VALUE
VALUE
VALUE
VALUE
20.
11.
02.
27.
15
OM Technologies
16
OM Technologies
17
OM Technologies
18
OM Technologies
19
OM Technologies
20
OM Technologies
21
OM Technologies
22
OM Technologies
23
OM Technologies
24
OM Technologies
25
OM Technologies
26
OM Technologies
27
OM Technologies
28
OM Technologies
PROCEDURE DIVISION.
STRING
FN DELIMITED BY ,
MN DELIMITED BY SPACE,
LN
INTO
FULL-NAME
WITH POINTER WS-PNT
END-STRING.
DISPLAY FULL-NAME.
We can get the count of characters passed to FULL-NAME by subtracting initial WS-PNT value from the
final WS-PNT value.
29
OM Technologies
PROCEDURE DIVISION.
UNSTRING FULL-NAME
DELIMITED BY SIZE
INTO FN,
MN,
LN
END-UNSTRING.
30
OM Technologies
31
OM Technologies
32
OM Technologies
33
OM Technologies
34
OM Technologies
35
OM Technologies
36
OM Technologies
37
OM Technologies
38
OM Technologies
39
OM Technologies
40
OM Technologies
41
OM Technologies
42
OM Technologies
43
OM Technologies
44
OM Technologies
45
OM Technologies
46
OM Technologies
47
OM Technologies
48
OM Technologies
49
OM Technologies
50
OM Technologies
51
OM Technologies
52
OM Technologies
JCL
Uses of JCL
It is used to compile & execute COBOL programs.
It is used to create & delete datasets (PDS & PS), GDGs and VSAM clusters.
It is used to copy data from one dataset to anther dataset.
It is used to sort & merge the file data.
Important statements in JCL
JCL has 3 important statements JOB, EXEC and DD statements
A JOB can have maximum 255 EXEC statements.
An EXEC statement can have maximum 255 DD statements.
Sample JCL
//FSS182EX
JOB
TYPRUN=SCAN,
//
//JOBLIB
DD
//STEP1
EXEC
2011
//STEPLIB
DD
//DISK1
DD
//DISK2
DD
//
//
//
//
//
//SYSPRINT
DD
//SYSOUT
DD
//SYSUDUMP DD
//SYSIN
DD
P111
JB
/*
//
(16/17
OPERANDS
72)
(73 - 80)
USER COMMENTS
53
OM Technologies
//JOBNAME
//
//STEPNAME
//DDNAME
JOB
Positional &
Keyword Parameters
EXEC
DD
JOB
DD
EXEC
EXEC
EXEC
STEPLIB
It specifies the load library in which ONLY a particular STEPs program load module is referred.
That is, STEPLIB is applicable to only a particular the step.
Sample JCL
//FSS182EX
JOB
A123, OMTECH, CLASS=A, MSGCLASS=A, MSGLEVEL=(1,1), PRTY=15,
//
NOTIFY=&SYSUID, REGION=6M, TIME=(30,10), COND=(4,LT),
//
TYPRUN=SCAN, RESTART=STEP2
//JOBLIB
DD
DSN=FSS182.OMT.LOADLIB1, DISP=SHR
//STEP1
EXEC PGM=PROG1, REGION=3K, TIME=(10,20), COND=(8,LE), PARM=23-07-2011
//STEP2
EXEC PGM=PROG2, REGION=3K, TIME=(10,20), COND=(8,LE), PARM=23-072011
//STEPLIB
DD
DSN=FSS182.OMT.LOADLIB2, DISP=SHR
//STEP3
EXEC PGM=PROG3, REGION=3K, TIME=(10,20), COND=(8,LE), PARM=23-072011
//
Note: When both JOBLIB and STEPLIB are specified, then first STEPLIB is referred and if load
module is not found, then JOBLIB is referred and if still not found, then System-defined load
libraries are referred and if still not found, abends with S806 abend code.
S806 No Active Load Module found.
POSITIONAL Parameters in JOB statement:
Accounting Information, Programmer Name.
CLASS, PRTY, MSGCLASS, MSGLEVEL, NOTIFY, TYPRUN, RESTART, REGION, COND, TIME.
54
OM Technologies
Accounting Information : It specifies the account code for which billing is done for executing
programs on
Mainframe. All the job information i.e., the CPU time consumed, amount charged, start date &
end date can be seen in JESMSGLG of SPOOL.
Programmer Name : It specifies the coder name who has written the JCL.
Example :
//FSS182EX JOB A123, OMTECH, CLASS=A, MSGCLASS=A, MSGLEVEL=(1,1)
//FSS182EX JOB , OMTECH, CLASS=A, MSGCLASS=A, MSGLEVEL=(1,1)
//FSS182EX JOB A123, ,CLASS=A, MSGCLASS=A, MSGLEVEL=(1,1)
//FSS182EX JOB , , CLASS=A, MSGCLASS=A, MSGLEVEL=(1,1)
CLASS It categorizes jobs based on factors like CPU consumption time and CPU resource
utilization.
Class can have the range of values A Z and 0 9.
Class=A
Job can take 5 min for execution.
Class=B
Job can take 10 min for execution.
Class=C
Job can take 1 hour for execution.
Class=0
Job can utilize maximum CPU resources.
Class=1
Job can utilize minimum CPU resources.
PRTY : It sets the priority for the job execution. PRTY has the range of values 0 to 15.
The highest the PRTY value, the first preference it is given for execution.
The Least the PRTY value, the least preference it is given for execution.
Note 1 : When two jobs are submitted, the job which is submitted first is executed first.
Note 2 : When two jobs are submitted at same time, the jobs are executed based on CLASS
parameter.
Note 3 : When two jobs are submitted at same time and with same CLASS parameter value, then
jobs are
executed based on PRTY value.
Note 4 : When two jobs are submitted at same time and with same CLASS and PRTY, then both
the jobs are
cancelled.
RESTART : It is used to start the job execution from a particular step(i.e., abended step).
Syntax : RESTART=STEP2
//FSS182EX
//
//STEP1
//STEP2
//STEP3
//
JOB
MSGCLASS : MSGCLASS specifies the output device to which messages need to be sent.
MSGCLASS can have a range of values A-Z. 0-9.
MSGCLASS=A
Printer
MSGCLASS=X
SPOOL
MSGCLASS=0
TOOL1 (Eg : JOBH)
55
OM Technologies
MSGCLASS=0
MSGLEVEL
TYPRUN
NOTIFY:
It specifies the USER ID to which the STATUS NOTIFICATION is sent about the successful or
unsuccessful execution of job.
Status Notification can be known by MaxCC.
When MaxCC = 0/4, it indicates successful execution of job.
Other than 0/4, it indicates unsuccessful execution of job.
NOTIFY=&SYSUID will substitute the USER ID with which User has logged in. So, the status
notification will be sent to the same User ID.
56
OM Technologies
Suppose User has logged in with FSS141 and specified NOTIFY=FSS142, then Status notification is
sent to FSS142 but the SPOOL information remains with FSS141.
REGION:
REGION parameter specifies the amount of workspace required for a job or steps execution.
REGION is specified in Kilo or Mega Bytes and in ODD quantities.
Eg : REGION=5M / 3K
Maximum REGION space can be allocated by specifying REGION=0K or 0M.
//JOB1 JOB
//JOBLIB
//STEP1 EXE C
//STEP2 EXE C
//STEP3 EXE C
A123,KEERTHI,CLASS=A,MSGCLASS=X,REGION=5M
DD
DSN=FSS046.KEERTHI.LOADLIB1,DISP=SHR
PGM=PROG1
PGM=PROG2,REGION=3K
PGM=PROG3
NOTE 1 : REGION specified in JOB is applicable by all the steps in the job.
NOTE 2 : REGION specified in STEP is applicable to only that particular step.
NOTE 3 : REGION specified in both JOB and STEP, then value specified in JOB overrides that of
STEP.
TIME
TIME parameter specifies the amount of time to be allocated for a job or steps execution.
TIME=(minutes,seconds)
TIME=(10,20)
TIME=10
TIME=(,20)
Maximum TIME can be allocated by specifying TIME=1440
TIME= NOLIMIT
TIME=MAX
//JOB1 JOB
//JOBLIB
//STEP1 EXE C
//STEP2 EXE C
//STEP3 EXE C
A123,KEERTHI,CLASS=A,MSGCLASS=X,TIME=(10,30)
DD
DSN=FSS046.KEERTHI.LOADLIB1,DISP=SHR
PGM=PROG1
PGM=PROG2,TIME=5
PGM=PROG3
NOTE 1 :
NOTE 2 :
NOTE 3 :
STEP.
COND
When a job is executed, all the steps execute irrespective of their previous sterps execute
successfully or unsuccessfully.
COND parameter is used to control the execution of steps.
When COND specified is false, the step executes.
When COND specified is true, the step is bypassed.
Note : COND is applicable for all the steps except the first step.
57
OM Technologies
//JOB1 JOB
//JOBLIB
//STEP1 EXE C
//STEP2 EXE C
//STEP3 EXE C
A123,KEERTHI,CLASS=A,MSGCLASS=X,COND=(4,LT)
DD
DSN=FSS046.KEERTHI.LOADLIB1,DISP=SHR
PGM=PROG1
PGM=PROG2,COND=(8,LE)
PGM=PROG3
NOTE 1 :
NOTE 2 :
NOTE 3 :
of
COND specified in JOB is applicable to all the steps except the first step.
COND specified in STEP is applicable to only that particular step.
COND specified in both JOB and STEP, then value specified in STEP overrides that
JOB.
Scenario 1: Never execute the step i.e., even the step executes successfully or unsuccessfully, do
not execute the step. So, the COND specified must be true for all return codes of previous step.
//JOB1 JOB
//JOBLIB
//STEP1 EXE C
//STEP2 EXE C
A123,KEERTHI,CLASS=A,MSGCLASS=X
DD
DSN=FSS046.KEERTHI.LOADLIB1,DISP=SHR
PGM=PROG1
PGM=PROG2,COND=( 0 , LE)
Or
//STEP2 EXE C PGM=PROG2,COND=( 4095 , GE)
Scenario 2: Always execute the step i.e., even the step executes successfully or unsuccessfully,
always execute the step. So, the COND specified must be false for all return codes of previous
step.
//JOB1 JOB
//JOBLIB
//STEP1 EXE C
//STEP2 EXE C
A123,KEERTHI,CLASS=A,MSGCLASS=X
DD
DSN=FSS046.KEERTHI.LOADLIB1,DISP=SHR
PGM=PROG1
PGM=PROG2,COND=( 0 , GT)
Or
//STEP2 EXE C PGM=PROG2,COND=( 4095 , LT)
Scenario 3:Execute the step ONLY when the previous step executes successfully.
So, the COND specified must be false for return codes 0 and 4 only.
//JOB1 JOB
//JOBLIB
//STEP1 EXE C
//STEP2 EXE C
A123,KEERTHI,CLASS=A,MSGCLASS=X
DD
DSN=FSS046.KEERTHI.LOADLIB1,DISP=SHR
PGM=PROG1
PGM=PROG2,COND=( 4 , LT)
OR
//STEP2 EXE C PGM=PROG2,COND=( 8 , LE)
Scenario 4:Execute the step ONLY when the previous step executes unsuccessfully.
58
OM Technologies
So, the COND specified must be false for return codes 8 to 4095.
//JOB1 JOB
//JOBLIB
//STEP1 EXE C
//STEP2 EXE C
A123,KEERTHI,CLASS=A,MSGCLASS=X
DD
DSN=FSS046.KEERTHI.LOADLIB1,DISP=SHR
PGM=PROG1
PGM=PROG2,COND=( 8 , GT)
OR
//STEP2 EXE C PGM=PROG2,COND=( 4 , GE)
EXEC Statement
Positional Parameters in EXEC statement :
PGM
Keyword Parameters in EXEC statement :
REGION
TIME
COND
PARM
PGM specifies the program name to be executed.
PARM parameter is used to pass the data from JCL to COBOL. We can pass a maximum of 100
characters only.
PARM parameter is specified in the EXEC statement as follows :
//STEP1
EXEC PGM=RPTPGM, PARM=23-07-2011
Data specified in PARM parameter is received into COBOL program as follows :
DATA DIVISION.
LINKAGE SECTION.
01 LS-PARM.
10 LS-PARM-LEN
PIC S9(4) COMP.
10 LS-PARM-TEXT
PIC X(100).
PROCEDURE DIVISION USING LS-PARM.
DISPLAY LS-PARM-TEXT.
Sample JCL
//FSS182EX JOB A123, OMTECH, CLASS=A, MSGCLASS=A, MSGLEVEL=(1,1), PRTY=15,
//
NOTIFY=&SYSUID, REGION=6M, TIME=(30,10), COND=(4,LT),
//
TYPRUN=SCAN, RESTART=STEP2
//JOBLIB
DD DSN=FSS182.OMT.LOADLIB1, DISP=SHR
//STEP1
EXEC PGM=RPTPGM, REGION=3K, TIME=(10,20), COND=(8,LE), PARM=23-07-2011
//STEPLIB
DD DSN=FSS182.OMT.LOADLIB2, DISP=SHR
//DISK1 DD DSN=FSS182.OMT.POL.FILE, DISP=SHR
//DISK2
DD DSN=FSS182.OMT.POL.RPT,
//
DISP=(NEW,CATLG,DELETE),
//
DCB=(LRECL=133, BLKSIZE=1330, RECFM=FB, DSORG=PS),
//
UNIT=DASD/TAPE, VOL-SER=V123,
//
SPACE=(TRK,(5,6,0),RLSE),
//
RETPD=1234 / EXPDT=12046
//SYSPRINT DD SYSOUT=*
//SYSOUT
DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSIN
DD *
P111
JB
/*
59
OM Technologies
//
DD Statement
DD statement specifies the characteristics of a dataset.
Keyword Parameters in DD statement :
DSN
DISP
DCB
UNIT
SPACE
VOL-SER
RETPD
EXPDT
DSN :
Status
NEW : It is specified for a new dataset and the corresponding OPEN Mode is OUTPUT.
SHR : It is specified for an existing dataset and the corresponding OPEN Mode is INPUT.
OLD : It is specified for an existing dataset and the corresponding OPEN Mode can be INPUT,
OUTPUT, I-O.
MOD : It is specified for a new or existing dataset and the corresponding OPEN Mode is EXTEND.
CATLG : When a new dataset is created, the dataset information is stored in the System Catalog.
UNCATLG : It removes the dataset information from the System Catalog but the dataset still
remains in the system catalog.
60
OM Technologies
KEEP : When KEEP is specified for a new dataset, the dataset is created but its information is not
stored in System Catalog. So, each time the dataset is to be accessed, user needs to specify the
Volume Serial Number.
Note : KEEP must always be specified for existing datasets as follows :
DISP=(SHR,KEEP,KEEP)
DISP=(OLD,KEEP,KEEP)
DELETE : It deletes the dataset from hard disk and it information from system catalog.
Examples :
DISP = (NEW,CATLG,DELETE)
DISP = (OLD,CATLG,UNCATLG)
By Default,
DISP = NEW will take DISP=(NEW,DELETE,DELETE)
DISP = SHR will take DISP=(SHR,KEEP,KEEP)
DISP = OLD will take DISP=(OLD,KEEP,KEEP)
DISP = MOD will take DISP=(MOD,CATLG,DELETE)
UNIT parameter specifies the storage device on which the dataset is to be created.
UNIT =DASD/SYSDA stores dataset on Hard Disk.
DASD - DIRECT ACCESS STORAGE DEVICE
SYSDA - SYSTEM DIRECT ACCESS
UNIT =TAPE stores dataset on TAPE device.
TAPE is an external device made of magnetic strips used to take backup of data.
VOL-SER specifies the volume serial number of the memory volume on which dataset is to be
created.
VOL-SER=V134
SPACE parameter specifies the amount of memory to be allocated for a dataset.
SPACE is allocated
SPACE=((Primary Quantity, Secondary Quantity, Directory Blocks),RLSE)
First Primary Quantity is allocated.
If not sufficient, then Secondary Quantity is allocated.
If still not sufficient, then again Secondary Quantity is allocated and so on upto 15 extents.
Eg :
SPACE=(1000,(10,20),RLSE)
SPACE=(BLKS,(10,20,5),RLSE)
SPACE=(TRKS,(5,10))
SPACE=(CYL,(10,5),RLSE)
61
OM Technologies
62
OM Technologies
//
//STEP3 EXE C
//DISK1 DD
//DISK2 DD
//
//
SPACE=(TRK,(10,5,0),RLSE)
PGM=RPTPGM,COND=(4,LT,STEP1)
DSN=FSS141.JS.FILE,DISP=SHR
DSN=FSS141.JS.RPT,DISP=(NEW,CATLG,DELETE),
DCB=(LRECL=133,BLKSIZE=0,RECFM=FB),
SPACE=(TRK,(10,5,0),RLSE)
JCL UTILITIES
IEBGENER
IEBCOPY
IEFBR14
IDCAMS
SORT
IEBGENER : It is used to copy data from one PS to another PS.
//JOB1
JOB - - - - //STEP1
EXEC
PGM=IEBGENER
//SYSUT1
DD DSN=FSS141.POL.FILE,DISP=SHR
//SYSUT2
DD DSN=FSS141.POL.FILE.BACKUP,
//
DISP=(NEW,CATLG,DELETE),
//
DCB=(LRECL=100,BLKSIZE=1000,RECFM=FB),
//
SPACE=(CYL,(10,5),RLSE)
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
IEBCOPY : It is used to copy data from one PDS to another PDS.
//JOB1
JOB - - - - //STEP1
EXEC
PGM=IEBCOPY
//SYSUT1
DD DSN=FSS141.OMT.SOURCE,DISP=SHR
//SYSUT2
DD DSN=FSS141.RAMU.SOURCE,
//
DISP=(NEW,CATLG,DELETE),
//
DCB=(LRECL=100,BLKSIZE=1000,RECFM=FB,DSORG=PO),
//
SPACE=(CYL,(10,5,5),RLSE)
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
COPY INDD=SYSUT1, OUTDD=SYSUT2
/*
To copy ONLY selected members from one PDS to another PDS.
//SYSIN DD *
COPY INDD=SYSUT1, OUTDD=SYSUT2
SELECT MEMBER=(PROG3,PROG66,PROG78)
/*
To EXCLUDE ONLY selected members from copying.
//SYSIN DD *
COPY INDD=SYSUT1, OUTDD=SYSUT2
EXCLUDE MEMBER=(PROG3,PROG66,PROG78)
/*
63
OM Technologies
DD DSN=FSS141.POL.FILE,
DISP=(MOD,DELETE,DELETE)
Alphanumeric
64
OM Technologies
N
Numeric
BI
Binary
PD
Packed Decimal
SORTIN is the INPUT DD name for the SORT utility
SORTOUT is the OUTPUT DD name for the SORT utility.
SORTWRK files are required to do the sorting process before processing the data into SORTOUT.
To copy only selected records based on condition
//SYSIN
DD
*
SORT FIELDS = COPY
INCLUDE COND = (23,5,CH,EQ,C JB)
/*
To exclude the records based on the condition
//SYSIN
DD
*
SORT FIELDS = COPY
OMIT COND = (23,5,CH,EQ,C JB)
/*
To eliminate duplicate records and to copy only unique records
//SYSIN
DD
*
SORT FIELDS = (23,5,CH,A)
SUM FIELDS = NONE
/*
To COPY duplicate records
//SYSIN
DD
*
SORT FIELDS = (23,5,CH,A)
SUM FIELDS = NONE,XSUM
/*
//SORTXSUM DD
DSN=FSS142.POL.FILE.DUP,DISP=OLD
To split a file data into multiple datasets
//JOB1
JOB
----//STEP1
EXEC PGM=SORT
//SORTIN
DD
DSN=FSS142.POL.FILE,DISP=SHR
//SORTWK01 DD
UNIT=DASD,SPACE=(TRK,(2,2),RLSE)
//SORTWK02 DD
UNIT=DASD,SPACE=(TRK,(2,2),RLSE)
//SORTWK03 DD
UNIT=DASD,SPACE=(TRK,(2,2),RLSE)
//SORTOF01 DD
DSN=FSS142.JB.FILE,
//
DISP=(NEW,CATLG,DELETE),
//
DCB=*.SORTIN,
//
SPACE=(TRK,(10,10),RLSE)
//SORTOF02 DD
DSN=FSS142.JS.FILE,
//
DISP=(NEW,CATLG,DELETE),
//
DCB=*.SORTIN,
//
SPACE=(TRK,(10,10),RLSE)
//SYSIN
DD
*
SORT FIELDS = COPY
OUTFIL FNAMES=SORTOF01,INCLUDE = (20,10,CH,EQ,C JB)
OUTFIL FNAMES=SORTOF02,INCLUDE = (20,10,CH,EQ,C JS)
/*
GDG is a collection of similar datasets i.e., structurally and functionally same.
65
OM Technologies
Uses of GDG
1. GDGs are used to take backup of data.
2. GDGs automate the process of deleting & creating datasets once the limit is reached.
3. We need not change the JCL for changing the file names.
GDG has two components.
1. GDG Base
2. GDG Generation
GDG Base is created using the utility IDCAMS as follows :
//JOB1
JOB - - - - - - - //STEP1 EXEC
PGM=IDCAMS
//SYSIN DD
*
DEFINE GDG(
NAME(FSS141.REL.DAILY.GDG)
LIMIT(7)
NOEMPTY/EMPTY
NOSCRATCH/SCRATCH)
/*
66
OM Technologies
JOB
DD
DD
DD
DD
DD
DD
DD
DD
-------PGM=IEBGENER
DSN=FSS141.REL.DAILY.GDG(-6),DISP=SHR
DSN=FSS141.REL.DAILY.GDG(-5),DISP=SHR
DSN=FSS141.REL.DAILY.GDG(-4),DISP=SHR
DSN=FSS141.REL.DAILY.GDG(-3),DISP=SHR
DSN=FSS141.REL.DAILY.GDG(-2),DISP=SHR
DSN=FSS141.REL.DAILY.GDG(-1),DISP=SHR
DSN=FSS141.REL.DAILY.GDG(0),DISP=SHR
DSN=FSS141.REL.WEEKLY.GDG(+1),
DISP=(NEW,CATLG,DELETE),
DCB=(LRECL=100,BLKSIZE=0,RECFM=FB),
SPACE=(TRK,(10,5),RLSE)
Procedures
PROCEDURE is a set of reusable JCL statements.
We cannot use * and JOBLIB in a PROC definition.
Procedures are of two types.
1. INSTREAM PROCEDURE
2. CATALOGED PROCEDURE
67
OM Technologies
Instream Procedures
//JOB1
JOB
--------//JOBLIB
DD
DSN=FSS142.KEERTHI.LOADLIB,DISP=SHR
//STEP1
EXEC PGM=PROG1
//PROC1
PROC
//STEPA
EXEC PGM=RPTPGM
//DISK1
DD
DSN=FSS146.JB.FILE,DISP=SHR
//DISK2
DD
DSN=FSS146.JB.RPT,
//
DISP=(NEW,CATLG,DELETE),
//
DCB=(LRECL=133,BLKSIZE=0,RECFM=FB),
//
SPACE=(TRK,(10,5,0),RLSE)
//SYSIN
DD
DSN=FSS145.CNTL.CARD,DISP=SHR
//
PEND
//STEP2
EXEC PROC1
//STEP3
EXEC PROC=PROC1
//STEP4
EXEC PGM=PROG2
//STEP5
EXEC PROC1
//
Instream Procedures Vs Catlagoed Procedure
Symbolic Parameters
Symbolic parameters are used to substitute DD statement parameter values. They are identified by
using single &.
Default values must be specified in PROC definition.
When Symbolic parameter values are specified in both JOB and PROC, then JOB values are considered.
68
OM Technologies
Overriding Parameters
These parameters are used to override the existing values for EXEC statement parameters.
Syntax :
Stepname.Parameter = New-value
For COND parameter,
COND.Stepname = New-value
69
OM Technologies
Db2 Database
Database management system (DBMS) is a software package that manages data
stored in databases.
IBMS Database 2 , commonly referred to as DB2, was made available in 1983 as
RDBMS concept.
Prior to DB2, IBM developed a HDBMS product IMS DB.
Data on Mainframe is stored in two ways :
1. Files
2. Database
DB2 is the RDBMS developed by IBM for storing and accessing heavy data.
RDBMS Relational Data Base Management System.
RDBMS allows data access to entities by establishing the following relationships :
ONE TO MANY
MANY TO ONE
MANY TO MANY
Advantages of database over files :
1. Database supports high volume of data storage whereas files support low volume of data
storage.
2. Database provides data security at various levels whereas files do not.
3. Accessing database data is easy as compared to files where programming is required.
4. Database supports data concurrency & locking.
5. Database avoids data redundancy.
When DB2 S/W is installed on the Mainframe, a system space and user space are
created. In the SYSTEM SPACE, default tables called DB2 catalog tables & DB2 directory
tables are stored. DB2 Catalog tables store the information of the user created database objects.
SYSIBM.SYSTABLESPACES
store tablespaces information.
SYSIBM.SYSTABLES
store tables information.
SYSIBM.SYSCOLUMNS
store columns information.
SYSIBM.SYSVIEWS
store views information.
DB2 Directory tables store the information about the physical memory locations of
database objects.
In the USER SPACE, user created database objects like tablespaces, tables, views,
synonyms, stored procedures, etc.
70
OM Technologies
Table: Table is the entity where we can store the data in the form of rows and columns.
Storage grp: It is a set of memory volumes allocated to the table space. Data in table spaces are stored
in the form of the tables.
Page: Page is an amount of space in the table space which is used to transmit the data from system
memory to buffer.
Page size can be 4k, 8k.32k.
Page can have maximum of 127 rows.
Table spaces are again 3 types.
Simple
Segmented
Partitioned
Simple table space: In this type of TS, a page can hold more than one tables data.
Segmented table space: In this type of TS, a page can hold ONLY one tables data.
Partitioned table space: In this type of TS, a set of pages are grouped into a partition and only specific
data is stored in each partition.
Using partitioned table space, amount of memory to be scanned is reduced, thereby improves the DB2
performance.
Data types in DB2 and COBOL
DB2
SMALL INT
2 bytes
INT
4 Bytes
CHAR (N)
N Bytes
VARCHAR (N)
(N+2) Bytes
DECIMA
DATE
TIME
TIMESTAMP
10 Bytes
8 Bytes
26 Bytes
COBOL
S9(4) COMP
S9(9) COMP
X(n)
01 VAR-FIELD
49 LEN
PIC S9(4) COMP.
49 TEXT
PIC X(N).
S9(M-N)V9(N) COMP-3
X(10) [DD-MM-YYYY]
X(08) [HH.MN.SS]
X(26) [DD-MM-YYYY- HH.MN.SS-NNNNN]
OM Technologies
CREATE:
It is used to create database objects.
Creating a database:
CREATE DATABASE DB123.
Creating a table space:
CREATE TABLE SPACE TS123
STORGROUP3
PAGESIZE 16K
SEGMENTED IN DB123.
Creating a table:
CREATE TABLE EMP_TBL
(EMP_ID
INT
NOT NULL,
EMP_NAME
CHAR(30),
EMP_DEPT
SMALL INT,
EMP_SAL
DECIMAL(11,2),
EMP_ADDR
VARCHAR(50),
EMP_JOIN_DT
DATE NOT NULL WITH DEFAULT,
EMP_JOIN_TM
TIME,
TRANS_TS
TIMESTAMP,
PRIMARY KEY (EMP_ID),
ON DELETE CASCADE)
IN DB123.TS123
Constraint is a mechanism to control the data in the tables.
1. Primary Key.
2. NULL Constraints
3. Referential Integrity
Primary Key:
It is used to uniquely identify a row in the table.
When primary key constraint set on a column it does not allow duplicate or null values.
Null value : It is an unknown value assigned to a column when no value is specified.
Null Constraint:
By default, any column is nullable (allows null values).
Not Null Constraint:
It does not allow null values to be stored and so a value must be specified.
Not Null with Default:
If no value is specified then instead of storing null value it stores a default value based on the data type.
Note:
For
SMALL INT
INT and
DECIMAL
Zeroes are the default values.
For
CHAR
Spaces are the default values.
For
DATE
Current date is the default value.
For
TIME
Current time is the default value.
For
TIMESTAMP
Current time stamp is the default value.
72
OM Technologies
Referential Integrity:
It controls the data in the parent and child table
Foreign Key: It is used to build the relationship between the tables. It must be a primary key of the table
and when we use this in the other table then it becomes as a foreign Key.
Table in which it is primary key then it is called Parent table and the table in which it is foreign key then
it is called child table.
RI rules :
1. Insert Rule
2. Update Rule
3. Delete Rules
- ON DELETE CASCADE
- ON DELETE RESTRICT
- ON DELETE SET NULL
INSERT RULE : It says before inserting a row with new foreign key value, insert it first
into
parent table.
UPDATE RULE : It says before updating a row with new foreign key value, update it first
in the
parent table.
DELETE Rules :
1. ON DELETE CASCADE : It says when a parent table row is deleted, the corresponding rows in all
child tables also get deleted.
2. ON DELTE RESTRICT : It says when a parent table row with corresponding rows in child tables
is to be deleted, then a restriction is applied. So, first, delete the child table rows and then
parent table row.
3. ON DELETE SET NULL : It says when a parent table row is deleted, the foreign key values for the
corresponding rows in all child tables are set to NULL.
ALTER:
It is used to modify the database objects.
Syntax: ALTER EMP_TBL ADD EMP_DOB DATE
This column will add at the last in the table EMP_TBL.
Note: A column can be added only as the last column in the table. If we need to add the column in
between the columns then we need to drop and create new table.
We can change the data types and data lengths.
ALTER EMP_TBL SET EMP_SAL DECIMAL (11,2) DECIMAL(13,2)
We can change the data types, increase/decrease the data length if a table is empty. But if the table is
non empty we can only increase the data length.
DROP:
Drop is used to permanently delete a data object in a database.
Syntax:
DROP TABLE EMP_TBL
DROP VIEW V_EMP_TBL
DML(Data Manipulation Language)
INSERT:
It is used to insert a new row into the table. Only one row at a time.
INSERT INTO EMP_TBL
73
OM Technologies
VALUES (0314,RAMESH)
If all the values are specified, then column names need not be specified.
INSERT INTO EMP_TBL
(EMP_ID, EMP_NAME)
VALUES (0314,RAMESH)
UPDATE:
It is used to modify the existing data in the table.
UPDATE EMP-TBL
SET EMP-SAL=EMP-SAL+1000
The above code will update all EMP-SAL column values in the table.
UPDATE EMP-TBL
SET EMP-SAL=EMP-SAL+1000
WHERE DEPT=D1;
WHERE clause is used to specify a condition based on which rows selective.
DELETE:
It is used to delete the rows from the table.
DELETE FROM EMP-TBL,
it will delete all the rows.
DELETE FROM EMP-TBL
WHERE DEPT = D1
SELECT:
It is used to retrieve the rows from the table.
SELECT * FROM EMP-TBL
The above query retrieves all the rows and columns.
SELECT EMP-ID,EMP-SAL FROM EMP-TBL
This query retrieves all the rows with column EMP-ID & EMP-SAL.
SELECT * FROM EMP-TBL
WHERE DEPT = D1
This query will retrieve all the rows with DEPT value D1.
SELECT EMP-ID FROM EMP-TBL
WHERE EMP-SAL BETWEEN 10000 AND 300000
It issues a permissions on DML commands
GRANT:
To provide access or permissions on data base objects to the users.
Syntax: GRANT INSERT,SELECT ON EMP_TBL
TO FSS141, GRP1.
GRANT ALL ON EMP_TBL
TO FSS142, FSS156
[
REVOKE:
To remove the authorizations or permissions.
REVOKE INSERT ON EMP_TBL
FROM FSS141, GRP1.
REVOKE ALL ON EMP_TBL
FROM FSS142, FSS156
74
OM Technologies
SQLCA
SQLCA is SQL Communication Area.
It is the communication are between COBOL and DB2.
SQLCA is used in the program as follows :
EXEC SQL
INCLUDE SQLCA
END-EXEC.
The above statement is resolved during DB2 pre-compilation as follows :
01 SQLCA.
03 SQLAID
PIC
03 SQLCODE
PIC
03 SQLWARN
PIC
03 SQLERR
PIC
03 SQLSTATE
PIC
SQLCODE is used to know the status of a Db2 statement.
If SQLCODE is 0 or +ve, DB2 execution is successful
If SQLCODE is -ve, DB2 execution is unsuccessful
SQLCODE = 0 Successful and row found
SQLCODE = 100
Successful but row not found
75
OM Technologies
76
OM Technologies
77
OM Technologies
78
OM Technologies
79
OM Technologies
80
OM Technologies
CURSORS
What is the need of cursor?
When a SELECT query retrieves more than one row, the program will abend with SQLCODE -811 since it
cannot hanlde multiple rows at a time.
Eg :
SELECT
EMP_SAL FROM EMP_TBL
WHERE
DEPT_ID = D6
Then how to handle multiple rows in the program?
Ans: Using Cursor.
What is a Cursor ?
Ans: Cursor is a pointer to a row in the resultant table.
Cursor Life Cycle :
Declaring cursor.
Opening the cursor.
Fetching the cursor.
Closing the
cursor.
81
OM Technologies
Closing
cursorL:f
Closing the cursor : It used to delete the cursor and the resultant table.
Exec SQL
Close EMPCUR
82
OM Technologies
END-EXEC
Updateable View
A View is said to be Updateable when it satisfies all of the below specified conditions :
1. View must be created on a single table.
83
OM Technologies
2.
3.
4.
5.
Non-Updateable View
A View is said to be Non-Updateable when it does not satisfy any one or all of the below specified
conditions :
1. View must be created on a single table.
2. No DISTINCT, GROUP BY or HAVING must be used.
3. No SUB-QUERIES must be used.
4. No Arithmetic operations must be used.
5. Base Table columns other than View columns must be nullable.
Aggregate Functions
These aggregate functions are used to act on a set of column values.
1 MAX : It gives the maximum value from a set of column values.
SELECT MAX(EMP_SAL)
FROM EMP_TBL
2. MIN : It gives the minimum value from a set of column values.
SELECT MIN(EMP_SAL) FROM EMP_TBL
3. SUM : It gives the sum of a set of column values.
SELECT SUM(EMP_SAL)
FROM EMP_TBL
4. AVG : It gives the average of a set of column values.
SELECT AVG(EMP_SAL) FROM EMP_TBL
Note : AVG will give an incorrect value when the column has null values.
5. COUNT : It gives the count of column values.
SELECT COUNT(EMP_SAL) FROM
EMP_TBL
It gives the count of column values in the table excluding null values.
SELECT COUNT(*) FROM
EMP_TBL
It gives the count of rows in the table.
GROUP BY
It is used to group a set of similar column values.
GROUP BY is mandatory when a combination of non-aggregate and aggregate columns are used.
To get the count of employees department wise :
SELECT DEPT_ID, COUNT(*) FROM EMP_TBL
GROUP BY DEPT_ID
To get the count of students class wise :
SELECT CLASS, COUNT(*) FROM SCH_TBL
GROUP BY CLASS
To get the count of students class & section wise :
SELECT CLASS, SECTION, COUNT(*) FROM SCH_TBL
84
OM Technologies
HAVING
It is used to specify a condition which acts on a set of column values.
HAVING must always follow GROUP BY clause.
Example :
SELECT DEPT_ID, COUNT(*) FROM EMP_TBL
GROUP BY DEPT_ID
HAVING COUNT(*) > 3
SELECT DEPT_ID, COUNT(*) FROM EMP_TBL
GROUP BY DEPT_ID
HAVING DEPT-ID = D3
Sub- Queries
Non-correlated Sub-queries
First the Inner Query executes and then based on its result, the Outer query executes.
Example : To find the 2nd maximum salary
SELECT MAX(SAL) FROM EMP_TBL
WHERE SAL < (SELECT MAX(SAL) FROM EMP_TBL)
Example : To find the 3rd maximum salary
SELECT MAX(SAL) FROM EMP_TBL
WHERE SAL < (SELECT MAX(SAL) FROM EMP_TBL)
WHERE SAL < (SELECT MAX(SAL) FROM EMP_TBL)
85
OM Technologies
Correlated Sub-queries
First the Outer Query executes and for each row of outer query, the inner query executes i.e., first the
outer query executes then the inner query.
Example : To find the 2nd maximum salary
SELECT E1.SAL FROM EMP_TBL E1
WHERE 1 = (SELECT COUNT(DISTINCT E2.SAL) FROM EMP_TBL E2
WHERE E2.SAL > E1.SAL)
Example : To find the 3rd maximum salary
SELECT E1.SAL FROM EMP_TBL E1
WHERE 2 = (SELECT COUNT(DISTINCT E2.SAL) FROM EMP_TBL E2
WHERE E2.SAL > E1.SAL)
th
To find the n maximum salary
SELECT E1.SAL FROM EMP_TBL E1
WHERE n-1 = (SELECT COUNT(DISTINCT E2.SAL) FROM EMP_TBL E2
WHERE E2.SAL > E1.SAL)
Example : To find the 2nd minimum salary
SELECT E1.SAL FROM EMP_TBL E1
WHERE 1 = (SELECT COUNT(DISTINCT E2.SAL) FROM EMP_TBL E2
WHERE E2.SAL < E1.SAL)
rd
Example : To find the 3 minimum salary
SELECT E1.SAL FROM EMP_TBL E1
WHERE 2 = (SELECT COUNT(DISTINCT E2.SAL) FROM EMP_TBL E2
WHERE E2.SAL < E1.SAL)
To find the nth minimum salary
SELECT E1.SAL FROM EMP_TBL E1
WHERE n-1 = (SELECT COUNT(DISTINCT E2.SAL) FROM EMP_TBL E2
WHERE E2.SAL < E1.SAL)
Example : To get the list of TOP 5 salaries
SELECT E1.SAL FROM EMP_TBL E1
WHERE 5 > (SELECT COUNT(DISTINCT E2.SAL) FROM EMP_TBL E2
WHERE E2.SAL > E1.SAL)
To get the list of TOP N salaries
SELECT E1.SAL FROM EMP_TBL E1
WHERE n > (SELECT COUNT(DISTINCT E2.SAL) FROM EMP_TBL E2
WHERE E2.SAL > E1.SAL)
Example : To get the list of LEAST 5 salaries
SELECT E1.SAL FROM EMP_TBL E1
WHERE 5 > (SELECT COUNT(DISTINCT E2.SAL) FROM EMP_TBL E2
WHERE E2.SAL < E1.SAL)
To get the list of LEAST N salaries
SELECT E1.SAL FROM EMP_TBL E1
WHERE n > (SELECT COUNT(DISTINCT E2.SAL) FROM EMP_TBL E2
WHERE E2.SAL < E1.SAL)
JOINS
86
OM Technologies
JOIN is used to combine columns from more than one table i.e., data can be
retrieved from more than one table by joining them on some common columns.
Types of Joins :
1. INNER JOIN
2. OUTER JOIN
- LEFT OUTER JOIN
- RIGHT OUTER JOIN
- FULL OUTER JOIN
87
OM Technologies
88
OM Technologies
UNIONS
UNION is used to combine rows from more than one table.
For using UNION, the data types and number of columns in both the queries must be same. Column
name may be different.
SELECT EMP_ID, DEPT_ID FROM DEPT_TBL1
UNION
SELECT EMP_ID, DEPT_ID FROM DEPT_TBL2
This will retrieve all the rows from both the tables but only unique rows are retrieved.
SELECT EMP_ID, DEPT_ID FROM DEPT_TBL1
UNION ALL
SELECT EMP_ID, DEPT_ID FROM DEPT_TBL2
This will retrieve all the rows from both the tables including duplicate rows.
Performance Tuning
DB2 Performance Tuning Techniques :
1. By using Indexes
2. By using DB2 utilities RUNSTAT and REORG
3. By avoiding arithmetic operations in DB2 queries.
4. By using Joins
Index
89
OM Technologies
Index reduces the amount of memory to be scanned, thereby reducing the execution
time and hence improves the DB2 performance.
DB2 Utilities
RUNSTAT utility : When it is run, all the statistics about the database objects are collected from DB2
catalog tables.
When RUNSTAT holds the latest information, OPTIMIZER can generate the BEST ACCESS PATH which will
inturn improve the DB2 performance.
REORG utility : When it is run, the tablespace memory is reorganized i.e., all the data pages are
accumulated releasing the unused pages into the free memory.
When REORG reorganizes the data in the tablespace, the amount of memory to be scanned reduces,
thereby improving the DB2 performance .
Using JOINs
Normal Query :
SELECT EMP_ID, DEPT_ID, DEPT_NUM, DEPT_NAME
FROM EMP_TBL,
DEPT_TBL
WHERE DEPT_ID = DEPT_NUM
AND EMP_SAL > 20000
This query retrieves the entire data from both the tables and then applies the WHERE condition.
Query using JOIN
90
OM Technologies
91
OM Technologies
92
OM Technologies
93
OM Technologies
94
OM Technologies
95
OM Technologies
96
OM Technologies
97
OM Technologies
98
OM Technologies
99
OM Technologies
100
OM Technologies
101
OM Technologies
102
OM Technologies
103
OM Technologies
TYPE=DSECT
TYPE=&SYSPARM
104
OM Technologies
105
OM Technologies
106
OM Technologies
107
OM Technologies
108
OM Technologies
109
OM Technologies
110
OM Technologies
111
OM Technologies
112
OM Technologies
113
OM Technologies
114
OM Technologies
115
OM Technologies
116
OM Technologies
117
OM Technologies
118
OM Technologies
119
OM Technologies
120
OM Technologies
121
OM Technologies
1.
2.
3.
4.
5.
6.
Requirements phase
Design phase
Build/CUT phase
Test phase
UAT (User Acceptance Test) phase
Implementation
Warranty Support / Post Implementation Support (optional)
122
OM Technologies
Requirement Phase
This is the first phase after the project is initiated.
In this phase, client gives a BRD (Business Requirements Document) to the Service
Provider.
This analysis is required to ensure Service provider has understood all the requirements or
not.
Design Phase
This is the second phase after the Requirements phase.
In this phase, the business requirements are converted into technical requirements i.e.,
HLD and LLD documents are prepared.
HLD (High Level Design) : This document provides a high level overview of each process
in the application.
Once HLD is signed-off, LLD is prepared.
123
OM Technologies
LLD (Low Level Design) : This document provides a detailed description of each
process in the application.
1.
2.
3.
4.
5.
TEST Phase
This is the fourth phase after the BUILD phase.
OM Technologies
In this phase, the S/W components (programs, copybooks, jobs, procs, bms maps) are
moved from development into production region.
Warranty Support
This is optional i.e., based on the contract, warranty support is provided for the
developed application. This is also called as Post-implementation Support.
Till the client is used to the application and to resolve any abends, warranty support is
provided.
Production Support
Once the application is handed over to the client, the production support team
oversees the smooth running of business applications.
1. Monitoring batch cycles i.e., monitoring the smooth running of batch jobs.
2. Providing resolutions to the abends.
3. Escalating issues to operations team.
Maintenance Activity
125
OM Technologies
From time to time, the existing applications has to be modifed as per the changing
business rules and strategies.
Enhancement Activity
From time to time, new functionalities must be added to the existing applications for the
new business rules and strategies.
126
OM Technologies