Upload
sharathraj
View
222
Download
1
Embed Size (px)
Citation preview
8/21/2019 Db2 Trianing Class 04
1/27
COBOL-DB2 Program
DB2 Training Class 04
8/21/2019 Db2 Trianing Class 04
2/27
Required Steps
Write a COBOL + DB2 programCompile the COBOL + DB2 program
Execute the program.
8/21/2019 Db2 Trianing Class 04
3/27
Required Copyboos
SQLCAcopy book
Hostvariable/DCLGENcopybook
Application program containing SL !tatement !houl" ha#e SLCA
copybook. SLCA copybook i! a collection o$ #ariable! that areup"ate" $or e#ery SL !tatement.
%hi! copybook i! o$ 136byte! in length.
Contain! mo!t important #ariable like SLCODE& SLE''D
SQLCODEcontain the !tatu! co"e a$ter e#ery Execution o$ SL
!tatement (ho!e picture clau!e i! S9(9)COMP-3.
SQLERRDi! an occur! "ata item in (hich the * occurrence contain!
the number o$ e$$ecte" ro(! by a gi#en uery i.e. SQLERRD(3).
8/21/2019 Db2 Trianing Class 04
4/27
!ost "ariable
%he!e are #ariable "e$ine" in the ostla!"#a"eto u!e in
application program.
,o!t -ariable are the only mean! o$ mo#ing "ata $rom an"
to DB2 table!
We u!e DCLGEN tool to pro"uce ho!t #ariable are the
!ame a! the column o$ the table!
We nee" to co"e ho!t #ariable! (ith in the SL !tatement
but !houl" be prece"e" by $olo!(%&'
8/21/2019 Db2 Trianing Class 04
5/27
#mbedded S$L
All the SL relate" !tatement !houl" be co"e"embe""e" in
bet(een
E/ECSL 0 E1DE/EC.
Both SLCA an" ho!t #ariable !houl" be co"e" in bet(een
E/EC SL an" E1DE/EC (ith 31CL4DE Statement.
E/ECSL E/ECSL
31CL4DE SLCA 31CL4DE DCL5E1
E1DE/EC. E1DE/EC.
8/21/2019 Db2 Trianing Class 04
6/27
#mbedded S$L Statement
E/ECSL 31SE'% 31%O E678%AB9E1O&E1A6E)
-AL4ES9:,SE1O&:,SE1A6E)
E1DE/EC.
E/ECSL SELEC% E1O&E1A6E 31%O :,SE1O&:,SE1A6E;'O6 E678%AB W,E'E E1O
E1DE/EC.
E/ECSL 47DA%E E678%AB SE% E1A6E
8/21/2019 Db2 Trianing Class 04
7/27
Program Preparation
We nee" to $ollo( $e( !tep!
7recompile
Compile0 link
Bin"
7ackage9B31D7AC?A5E)
7lan9B31D7LA1)
8/21/2019 Db2 Trianing Class 04
8/27
8/21/2019 Db2 Trianing Class 04
9/27
Pre%ompile
Searche!all the SL !tatement! an" inclu"e member! an"
comment! out e#ery SL !tatement! in the program
%he SL !tatement are replace"by a call!tatement along
(ith the parameter!
All SL !tatement! are extracte"an" put in a DB'6
Both SLCA 0 DCL5E1 copybook! are expan"e" in the
pre compile proce!! only.
3t al!o a!!ign a time !tamp to the mo"i$ie" co"e an" DB'6
member.
8/21/2019 Db2 Trianing Class 04
10/27
Compile and Lin
6o"i$ie" COBOL co"e output i! then compile"
Compile" co"e i! then link e"ite" to an Executable
loa" mo"ule
8/21/2019 Db2 Trianing Class 04
11/27
B&'D Pro%ess
A type o$ compiler $or SL !tatement u!ing a pre (ritten
program i.e. 3?@E;%=>
3t rea"! the SL !tatement $rom the DB'6 an" pro"uce! a
mechani!m to acce!! "ata a! "irecte" by the SL !tatement
3n thi! bin" proce!! it check! the !yntax& check! $or the
correctne!! o$ the table 0 column! "e$inition! again!t the
catalog in$ormation an" per$orm authentication #ali"ation
%he output o$ the bin" proce!! can be a package or a plan
8/21/2019 Db2 Trianing Class 04
12/27
Pa%age ( its )d"antage
7ackage i! boun" $orm o$ SL !tatement
Ava!ta"es:
'e"uce" bin" time
Can !peci$y bin" operation in the programmer le#el
7ro#i"e remote "ata acce!!
8/21/2019 Db2 Trianing Class 04
13/27
PL)'
7ackage i! not Executable (here a! plan i! Executable
An application plan contain one or both o$ the $ollo(ing
element!
A li!t o$ package name!
%he boun" $orm o$ SL !tatement taken $rom one or more
DB'6
E#ery DB2 application reuire! an application plan
7lan! are create" u!ing the DB2 !ub comman" B31D 7LA1
8/21/2019 Db2 Trianing Class 04
14/27
Bind Parameters
8/21/2019 Db2 Trianing Class 04
15/27
Bind Parameters
SS%S31 DD
DS1 SS%E69DB5)
B31D 7AC?A5E9;SS%SO7?) 6E6BE'9DB'66E6)
OW1E'9;SS>) 4AL3;3E'9;SS>)
-AL3DA%E9B31D) 3SOLA%3O19CS) 'ELEASE9CO663%) AC%3O19'E7LACE)
E/7LA3191O)
E1D
SS%S31 DD
DS1 SS%E69DB5)
B31D 7LA19;SS>7L) 7?L3S%9;SS%SO7?.)
8/21/2019 Db2 Trianing Class 04
16/27
Bind Parameters
7?L3S%: 7?L3S% i! a bin" parameter o$ bin" plan. 7ackage! to be
connecte" (ith plan are name" here.
AC%3O19ADD'E7LACE) package or plan i! a"" or replace". "e$ault
i! 'E7LACE.
AC43'EA1D 'ELEASE:
AC43'E94SEALLOCA%Elock! table an" table !pace on u!e
'ELEASE9CO663%DEALLOCA%E) relea!e (hen the plan
terminate!
SLE''O'91O7AC?A5ECO1%314E) it !ay! (eather to create the
package in ca!e o$ !l error
E/7LA319ES1O) loa"! the acce!! path !electe" by the optimFerin
plan8table. no i! "e$ault
8/21/2019 Db2 Trianing Class 04
17/27
&solation Le"els
Lost *+ates% %hi! e#ent occur! (hen t(o
tran!action! rea" the !ame "ata& both attempt to up"ate
that "ata& an" one o$ the up"ate! i! lo!t.
Dirt, Reas% %hi! e#ent occur! (hen a tran!action
rea"! "ata that ha! not yet been committe".
No!re+eatable Reas% %hi! e#ent occur! (hen a
tran!action rea"! the !ame ro( o$ "ata t(ice& but get!
"i$$erent re!ult! each time
Pa!tos'%hi! e#ent occur! (hen a ro( o$ "ata
matche! !ome !earch criteria but initially i! not !een.
8/21/2019 Db2 Trianing Class 04
18/27
&solation le"els
Re+eatable ReaRea Stabilit,
C#rsor Stabilit,
*!$oitte Rea
8/21/2019 Db2 Trianing Class 04
19/27
.e Re+eatable Rea &solation Le"el
%he 'epeatable 'ea" i!olation le#el i! the mo!t re!tricti#e
i!olation le#el a#ailable.
When thi! i!olation le#el i! u!e"& e#ery ro( that i! re$erence"
in any manner by the i!olate" tran!action i! Glocke"G $or the"uration o$ that tran!action.
%hu!& i$ a tran!action !can! >&=== ro(! in or"er to retrie#e >=&
lock! are acuire" an" hel" on all >&=== ro(! !canne"Hnot
Iu!t on the >= ro(! retrie#e".
8/21/2019 Db2 Trianing Class 04
20/27
8/21/2019 Db2 Trianing Class 04
21/27
T*e Read Stability &solation Le"el
(hen the 'ea" Stability i!olation le#el i! u!e"& only ro(! thatare actually retrie#e" by a !ingle tran!action are locke" $or the
"uration o$ that tran!action.
phantom!& ho(e#er& can an" may be !een but becau!e o$ $e(er
lock! are acuire"& more tran!action! can run concurrently.
i$ a tran!action !can! >&=== ro(! in or"er to retrie#e >=& lock!
are only acuire" an" hel" on the >= ro(! retrie#e"Hnot on all>&=== ro(! !canne".
8/21/2019 Db2 Trianing Class 04
22/27
8/21/2019 Db2 Trianing Class 04
23/27
T*e Cursor Stability &solation Le"el
When the Cur!or Stability i!olation le#el i! u!e"& only the ro(
that i! currently being re$erence" by a cur!or i! locke". %he
lock acuire" remain! in e$$ect until the cur!or i! repo!itione"
or until the i!olating tran!action terminate!.
3$ the cur!or i! repo!itione"& the lock being hel" on the la!t ro(
rea" i! relea!e" an" a ne( lock i! acuire" $or the ro( the
cur!or i! no( po!itione" on..
1on repeatable rea"! an" phantom!& on the other han"& can an"may be !een.
8/21/2019 Db2 Trianing Class 04
24/27
8/21/2019 Db2 Trianing Class 04
25/27
T*e +n%ommitted Read &solationLe"el
%he uncommitte" rea" i!olation le#el i! the lea!t intru!i#ei!olation le#el pro#i"e".
3n $act& (hen the uncommitte" rea" i!olation le#el i! u!e"& ro(!
that are retrie#e" by a !ingle tran!action are only locke" i$
another tran!action attempt! to "rop or alter the table $rom (hich
the ro(! (ere retrie#e". Becau!e ro(! o$ten remain unlocke"
When thi! i!olation le#el i! u!e"& "irty rea"!& nonrepeatable
rea"!& an" phantom! can occur.
%he uncommitte" rea" i!olation le#el i! commonly u!e" $or
tran!action! that acce!! rea"only table!#ie(! or tran!action!
that execute uerie! on (hich uncommitte" "ata $rom other
tran!action! (ill ha#e no a"#er!e a$$ect
8/21/2019 Db2 Trianing Class 04
26/27
8/21/2019 Db2 Trianing Class 04
27/27
T*an ,ou