Você está na página 1de 27

COBOL-DB2 Program

DB2 Training Class 04


Required Steps

Write a COBOL + DB2 program

Compile the COBOL + DB2 program

Execute the program.


Required Copyboos

SQLCA copy book

Host variable/DCLGEN copybook


Application program containing SL !tatement !houl" ha#e SLCA
copybook. SLCA copybook i! a collection o$ #ariable! that are
up"ate" $or e#ery SL !tatement.
%hi! copybook i! o$ 136 byte! in length.
Contain! mo!t important #ariable like SLCODE& SLE''D
SQLCODE contain the !tatu! co"e a$ter e#ery Execution o$ SL
!tatement (ho!e picture clau!e i! S9(9) COMP-3.
SQLERRD i! an occur! "ata item in (hich the * occurrence contain!
the number o$ e$$ecte" ro(! by a gi#en +uery i.e. SQLERRD(3).
!ost "ariable
%he!e are #ariable "e$ine" in the ost la!"#a"e to 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! (%&'
#mbedded S$L
All the SL relate" !tatement !houl" be co"e".embe""e" in
bet(een
E/EC SL 0 E1D2E/EC.
Both SLCA an" ho!t #ariable !houl" be co"e" in bet(een
E/EC SL an" E1D2E/EC (ith 31CL4DE Statement.
E/EC SL E/EC SL
31CL4DE SLCA 31CL4DE DCL5E1
E1D2E/EC. E1D2E/EC.
#mbedded S$L Statement
E/EC SL 31SE'% 31%O E678%AB9E1O&E1A6E)
-AL4ES9:,S2E1O&:,S2E1A6E)
E1D2E/EC.
E/EC SL SELEC% E1O&E1A6E 31%O :,S2E1O&:,S2E1A6E
;'O6 E678%AB W,E'E E1O<==>
E1D2E/EC.
E/EC SL 47DA%E E678%AB SE% E1A6E<:,S2E1A6E
E1D2E/EC.
E/EC SL DELE%E ;'O6 E678%AB W,E'E E1O<:,S2E1O
E1D2E/EC.
Program Preparation
We nee" to $ollo( $e( !tep!

7recompile

Compile 0 link

Bin"

7ackage 9B31D 7AC?A5E)

7lan 9B31D 7LA1)


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.
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
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
Pa%age ( its )d"antage
7ackage i! boun" $orm o$ SL !tatement
A(va!ta"es:
'e"uce" bin" time
Can !peci$y bin" operation in the programmer le#el
7ro#i"e remote "ata acce!!
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 re+uire! an application plan
7lan! are create" u!ing the DB2 !ub comman" B31D 7LA1
Bind Parameters
Bind Parameters
..SAS%S31 DD B
DS1 SAS%E69DBC5)
B31D 7AC?A5E9;SS%SO7?) 6E6BE'9DB'66E6) 2
OW1E'9;SS>CD) 4AL3;3E'9;SS>CD) 2
-AL3DA%E9B31D) 3SOLA%3O19CS) 2
'ELEASE9CO663%) AC%3O19'E7LACE) 2
E/7LA3191O)
E1D
.B
..SAS%S31 DD B
DS1 SAS%E69DBC5)
B31D 7LA19;SS>CD7L) 7?L3S%9;SS%SO7?.B)
.B
Bind Parameters
7?L3S% : 7?L3S% i! a bin" parameter o$ bin" plan. 7ackage! to be
connecte" (ith plan are name" here.
AC%3O19ADDE'E7LACE) package or plan i! a"" or replace". "e$ault
i! 'E7LACE.
AC43'E A1D 'ELEASE :

AC43'E94SE.ALLOCA%E lock! table an" table !pace on u!e

'ELEASE9CO663%.DEALLOCA%E) relea!e (hen the plan


terminate!
SLE''O'91O7AC?A5E.CO1%314E) it !ay! (eather to create the
package in ca!e o$ !+l error
E/7LA319AES.1O) loa"! the acce!! path !electe" by the optimFerin
plan8table. no i! "e$ault
&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, Rea(s% %hi! e#ent occur! (hen a tran!action
rea"! "ata that ha! not yet been committe".
No!re+eatable Rea(s% %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!to-s' %hi! e#ent occur! (hen a ro( o$ "ata
matche! !ome !earch criteria but initially i! not !een.
&solation le"els

Re+eatable Rea(

Rea( Stabilit,

C#rsor Stabilit,

*!$o--itte( Rea(
.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 ac+uire" an" hel" on all >&=== ro(! !canne"Hnot
Iu!t on the >= ro(! retrie#e".
T*e Read Stability &solation Le"el
(hen the 'ea" Stability i!olation le#el i! u!e"& only ro(! that
are 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 ac+uire"& more tran!action! can run concurrently.

i$ a tran!action !can! >&=== ro(! in or"er to retrie#e >=& lock!
are only ac+uire" an" hel" on the >= ro(! retrie#e"Hnot on all
>&=== ro(! !canne".
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 ac+uire" 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! ac+uire" $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.
T*e +n%ommitted Read &solation
Le"el
%he uncommitte" rea" i!olation le#el i! the lea!t intru!i#e
i!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"2only 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
T*an ,ou

Você também pode gostar