#o$ert Cattera IBM rfcatter%us&i$'&co' Bati'ore/(ashin!ton DB2 )sers *roup Dece'$er +, 2011 2011 IBM Corporation -!enda . - /ision of a 'odern DB2 for z/OS data0ser/in! s"ste' . - $rief re/ie1 of ad/ances in DB2 for z/OS stored procedure functionait" since DB2 23 . 4ati/e S56 procedures . So'e !o0for1ard reco''endations . 7ints, tips, etc& 2011 IBM Corporation - /ision of a 'odern DB2 for z/OS data0ser/in! s"ste' 2011 IBM Corporation DB2 data ser/er Stored procedures Data 8a/a appication ser/er 9(e$Sphere or (e$6o!ic or:; (indo1s/&4<T appication ser/er M5 istener (e$Sphere M5 =ueue The $i! picture 2011 IBM Corporation Points a$out the >/ision? dia!ra' . The DB2 ser/er patfor' is not specifica" identified coud $e z/OS, or 6inu@, or )4IA, or (indo1s . - pet pee/e of 'ine . 5uit usin! >DB2? as shorthand for DB2 for z/OS and >)DB? as shorthand for DB2 for 6inu@/)4IA/(indo1s . Perpetuates the unhepfu notion DB2 for z/OS and DB2 for 6)( inco'pati$iit", 1hereas fro' a cient/ser/er appication de/eop'ent and architecture perspecti/e, the t1o DB2 patfor's are /irtua" identica . 8ust sa" >DB2? . If "ou 1ant to refer 'ore specifica" to a DB2 ser/er patfor', sa" >DB2 for z/OS? or >DB2 for 6)(? 2011 IBM Corporation More on the /ision dia!ra' . The DB2 ser/er is a pure data$ase ser/er there is no transaction 'ana!e'ent su$s"ste' on the ser/er . This has $een the standard set0up for so'e ti'e in the distri$uted s"ste's 1ord . Mainfra'es 1ith DB2 often ha/e CICS or IMS, as 1e usua" $ecause the or!anization ran a DB20accessin! transactiona 1orBoad $efore DB2 stored procedure functionait" 1as a/aia$e . Static, ser/er0side S56 9i'portant for scaa$iit"; can $e pacBa!ed in CICS or IMS transaction pro!ra's or in DB2 stored procedures . Man" 'ainfra'ers $eie/e that "ou ha/e to ha/e CICS or IMS/TM to support a hi!h0/ou'e DB2 for z/OS0$ased transactiona 1orBoad Not so 2011 IBM Corporation Mainfra'e M5 6istener Stored procedure DB2 Messa!e M5 =ueue -nd a itte 'ore: . M5 is a /er" i'portant part of the picture . 7o1 M5 and DB2 stored procedures can 1orB to!etherC . Cient pro!ra' puts a 'essa!e 9so'e infor'ation; on an M5 =ueue . - process caed the M5 6istener can perfor' an action in response to a 'essa!e arri/in! on a =ueue . <@a'peC ca a DB2 stored procedure, 1ith 'essa!e pro/idin! input to the stored procedure 9M5 can aso in/oBe a CICS transaction; 2011 IBM Corporation *reat use of M5 and DB2 SPs 91; . Dor data$ase updates that need to occur in near0rea0ti'e $ut not s"nchronous" reati/e to end user input . Possi$e e@a'pesC custo'er chan!es persona infor'ation 9e&!&, address;, or 'aBes an onine pa"'ent . )ser cicBs on >Su$'it,? input infor'ation captured in M5 'essa!e . -ppication can i''ediate" respond to end user 1ith 9for e@a'pe; >Eour update has $een recei/ed and 1i $e appied to "our profie 'o'entari"? . BacB0end DB2 data$ase updates iBe" to occur 1ithin seconds . -d/anta!es of as"nchronous approachC . Potentia" $etter end0user response ti'e 9/er" fast rep" after >Su$'it?; . I'pro/ed s"ste' a/aia$iit" 9fro' userFs perspecti/e;C if $acB0end data$ase ser/er is una/aia$e, 'essa!es si'p" accu'uate on =ueue and are processed 1hen data$ase ser/er is $acB onine 2011 IBM Corporation (orBfo1 orchestration appication <nterprise ser/ice $us 9$uit on M5 foundation; DB2 data$ase Stored proc 1 Stored proc 2 Stored proc G Messa!es *reat use of M5 and DB2 SPs 92; . Dor auto'atic orchestration of co'pe@ $usiness 1orBfo1s in/o/in! 'utipe reated transactions 9e&!&, order processin!; . (orBfo1 orchestration appication ensures that re=uired transactions are co'peted in the necessar" order 2011 IBM Corporation - $rief re/ie1 of ad/ances in DB2 for z/OS stored procedure functionait" since DB2 23 2011 IBM Corporation MSTR z/OS DBM1 IRLM DDF SPAS .Stored procedure programs run here, using DB2 call attach acilit! interace 23C stored procedures introduced . 4e1 address spaceC DB20'ana!ed stored procedure address space 9aBa SP-S; . - shortco'in!C caer coud not fetch resuts of cursor decared and opened in a stored procedure . 7ad to use output para'eters 9not idea for resut sets 1ith indeter'inate nu'$er of ro1s, not feasi$e for ar!e resut sets; 2011 IBM Corporation MSTR z/OS DBM1 IRLM DDF DB2"managed SPAS .#se not recommended .$one in DB2 % &LM"managed SPAS ', (1 SPAS ', (2 SPAS ', () &LM"managed SPAS *, (1 2HC t1o si!nificant enhance'ents . Caer of a stored procedure can fetch ro1s fro' a cursor decared and opened in the stored procedure . (6M0'ana!ed stored procedure address spaces introduced 2011 IBM Corporation More on (6M0'ana!ed SP-Ss . Eou can ha/e se/era of the' . )sefu for stored procedure 'ana!e'ent and 'onitorin! . Ma"$e ha/e a SP-S for ne1er stored procedure pro!ra's . Ma"$e !roup stored procedures $" appication . (6M can auto'atica" fire up additiona instances of a !i/en SP-S in response to 1orBoad de'ands . Stored procedure t1o0phase co''it capa$iit" /ia ##S-D . #eco/era$e resource ser/ices attach faciit" re=uired for stored procedure pro!ra's e@ecutin! in a (6M0'ana!ed SP-S . Coordinated co''it/ro$acB for update of DB2 I 2S-M or DB2 I M5 . Pro/ide support for stored procedures 1ritten in 8a/a . <na$e stored procedures to access 6OBs 9ar!e o$Jects; 2011 IBM Corporation 2K and 2+C DD6, S56P6, COMMIT . DB2 2KC C#<-T</-6T<#/D#OP P#OC<D)#< state'ents added to DD6 . Before that, DB- had to insert/update/deete ro1s in SESP#OC<D)#<S catao! ta$e 9tedious, error0prone; . B" the 1a"C SESP#OC<D)#<S out, SES#O)TI4<S in . DB2 2+C S56 Procedure 6an!ua!e introduced 9S56P6; . Stored procedures coud $e 1ritten entire" in S56 . S56 1as e@tended to incude o!ic fo10contro state'ents such as *OTO, ID, IT<#-T<, 6<-2<, 6OOP, #<P<-T, and (7I6< . S56 procedure con/erted under0the0co/ers to C pro!ra' 1ith e'$edded S56 DM6 e@ecutes as an e@terna stored procedure pro!ra' . DB2 2+ aso ao1ed for COMMIT and #O66B-CL to $e issued fro' stored procedure 2011 IBM Corporation 2MC fe@i$e a$end i'it, (6M s"ner!" . Stored procedure a$end i'it can $e set at indi/idua stored procedure e/e, /ersus a DB2 su$s"ste'01ide settin! . If a stored procedure a$ends n ti'es, paced in stopped status 9after $ein! fi@ed, restarted /ia 0ST-#T P#OC<D)#< co''and; . 7i!her a$end i'it 'i!ht $e appropriate for ne1er stored procedures . Better s"ner!" 1ith z/OS (orBoad Mana!er . DB2, z/OS 1orB to!ether to opti'ize nu'$er of tasBs in a SP-S 9a stored procedure TCB is conceptua" iBe a CICS0DB2 su$tasB TCB; . >8ust ri!ht? nu'$er of tasBs in a SP-S heps to i'pro/e CP) efficienc" . 4u'$er of tasBs in a SP-S 'a" $e /aried up or do1n, $ut 4)MTCB 9para'eter specified 1hen definin! (6M e@ecution en/iron'ent; re'ains upper $ound for a SP-S 2011 IBM Corporation 2NC >nati/e? S56 procedures . -s far as IF' concerned, the 'ost i'portant ad/ance in DB2 for z/OS stored procedure technoo!" since stored procedures 1ere introduced 1ith DB2 23 Gets its own section in this presentation (DB2 10 stored procedure enhancements will be covered later in this session) 2011 IBM Corporation 4ati/e S56 procedures 2011 IBM Corporation 4ati/e S56 proceduresC $i! chan!e . BeforeC S56 procedure turned into a C an!ua!e pro!ra' under the co/ers . #uns as an e@terna stored procedure in a (6M0'ana!ed SP-S . 4ot0in0DB2 part of a C pro!ra' !enera" consu'es 'ore CP) than does e=ui/aent COBO6 code 9thou!h ess than 8a/a; . - nati/e S56 procedure 9a/aia$e $e!innin! 1ith DB2 N in ne1 function 'ode; is Just a pacBa!e a >runti'e structure? $ased on the S56 state'ents to $e e@ecuted . - nati/e S56 procedure runs in the DB2 data$ase ser/ices address space 9DBM1; 2011 IBM Corporation Use my thread. 4ati/e S56 procedure efficienc" 91; . -n e@terna stored procedure runs under its o1n TCB . CaerFs tasB 9TCB or S#B; is suspended, and stored proc tasB uses caerFs thread for co''unication 1ith DB2 . In so'e cases, there can $e processin! dea"s and a $uid0up of DBM1 /irtua stora!e consu'ption associated 1ith the s1itchin! of threads fro' cain!0 pro!ra' tasBs to stored procedure tasBs . - nati/e S56 procedure runs under the cain! pro!ra'Fs tasB . 4o =ueuin!, no dea"s reated to thread0s1itchin! 2011 IBM Corporation 4ati/e S56 procedure efficienc" 92; . Dor e/er" S56 state'ent in an e@terna stored procedure 9or an" other e@terna0to0DB2, S560issuin! pro!ra';, an >addressa$iit" round trip? is re=uired . Pro!ra'Fs tasB s1itches addressa$iit" fro' >ho'e? address space 9for e@terna S56 procedure, thatFs a (6M0'ana!ed stored procedure address space; to DB2 DBM1 for S56 e@ecution, then s1itches $acB . <ach round trip pro$a$" consu'es a fe1 thousand instructions, and thatFs Just the $acB0and0forth not S56 e@ecution in DBM1 . 4ati/e S56 procedures ei'inate this e@tra path en!th . (ith the C-66 to the nati/e S56 procedure, "ouFre aread" in DBM1, and "ou sta" there unti the stored procedure co'petes 2011 IBM Corporation Cient pro!ra' C-66 MEP#OC 9par'1, par'2; z/OS ser/er DDD DBM1 S561 S562 end DB2 director" Stored proc pacBa!e Cient pro!ra' C-66 MEP#OC 9par'1, par'2; z/OS ser/er DDD DBM1 (6M SP-S Stored proc pro!ra' 6oad i$rar" S561 S562 end DB2 director" Stored proc pacBa!e <@terna /s& nati/e procedure External Native 2011 IBM Corporation The zIIP factor . zIIPC speciat" 'ainfra'e en!ine that costs ess than a !enera0purpose processor and does not factor into soft1are pricin! . - nati/e S56 procedure is zIIP0ei!i$e if it is in/oBed /ia a re'ote ca throu!h the DB2 Distri$uted Data Daciit" 9DDD; . (h" restricted to re'ote /s& oca C-66s 9>oca C-66s? $ein! those that are issued $" pro!ra's runnin! on the sa'e ser/er as DB2;O . Technica", $ecause DDD re=uests run under enca/e S#Bs . M" opinionC IBM is encoura!in! or!anizations to use DB2 for z/OS as a data ser/er in 'uti0tier cient0ser/er appication en/iron'ents . -'ount of CP) processin! directed to a zIIP en!ine tends to $e around HHP for nati/e S56 procedures caed throu!h DDD 2011 IBM Corporation T!pe o procedure Base cost +,P#-tran. ,ost ater /IIP redirect COBO6 1A 9$ase; &MMA <@terna S56 1&K2A 1&3NA 4ati/e S56 1&13A &KHA So'e CP) fi!ures . Dro' a presentation dei/ered $" IBMFs 8ohn Ca'p$e at a recent ID)* DB2 Tech Conference . #esuts o$tained usin! I#(( O6TP 1orBoad 9a standard 1orBoad used $" IBM for $ench'arBin! purposes; . Stored procedures in/oBed /ia D#D- and DDD . 4oteC test 1as run a coupe of "ears a!o, usin! DB2 N nati/e S56 procedure picture pro$a$" ooBs e/en $etter no1 . DB2 10 deli1ered impro1ed S2L procedure language perormance 2011 IBM Corporation <nhanced functionait", too . - nested co'pound state'ent 9a co'pound S56 state'ent 1ithin another co'pound S56 state'ent; is ao1ed in a nati/e S56 procedure, not in an e@terna S56 procedure . Co'pound state'entC a !roup of S56 state'ents, $ounded $" B<*I4 and <4D . (ithin a co'pound state'ent, /aria$es, cursors, and condition handers can $e decared . - S56 procedure 1i /er" often contain a co'pound S56 state'ent . (ith nested co'pound state'ents, condition handers can ha/e their o1n co'pound state'ents 9ena$es 'ore sophisticated error handin!; . -soC $etter co'pati$iit" across DB2 Da'i" 9DB2 for 6inu@, )4IA, and (indo1s aread" pro/ided support for nested co'pound state'ents in S56 procedures; i'portant for cross0patfor' de/eop'ent 2011 IBM Corporation Simple is good 4ati/e S56 procedure ifec"ce . Si'per creation, 'ana!e'ent, 'aintenance /ersus e@terna stored procedures . 4o e@terna0to0DB2 resources in/o/ed 9e&!&, no source / o$Ject / oad i$raries; . The nati/e S56 procedure pacBa!e is the e@ecuta$e, and it is stored in the DB2 director" . 4o e@terna0to0DB2 processes in/o/ed 9e&!&, no need for co'pie and inB processes; . -'on! other !ood thin!sC no 1orries a$out pro!ra'/pacBa!e coordination . 4ati/e S56 procedures ha/e a consistenc" toBen 9used to 'atch e@terna0to0DB2 pro!ra's 1ith correspondin! pacBa!e;, $ut itFs Just a >s"non"'? for the procedureFs /ersion ID 2011 IBM Corporation So'e !o0for1ard reco''endations 2011 IBM Corporation *ettin! fro' here to there: . >There? $ein! a situation in 1hich "ouFre !ettin! 'a@i'u' $enefit fro' the use of DB2 stored procedures . DirstC use stored procedures 9if not aread" doin! so; . If "ou are in a DB2 2M or DB2 N CM en/iron'ent, code and depo" so'e S56 stored procedures to !ain fa'iiarit" 1ith their de/eop'ent . </en if COBO6 has $een "our preferred stored procedure pro!ra''in! an!ua!e . I $eie/e that S56 procedures are the 1a" of the future, and it 1oud $e a !ood idea to !et read" for that future . DB2 10 allo3s user"deined unctions +#DFs. to 4e 3ritten in S2LPL, too 2011 IBM Corporation If "ou use CICS: . Tr" 'aBin! functionait" of one or 'ore CICS0DB2 transactions a/aia$e to D#D- re=uesters /ia stored procedure cas . - 'ore >open? 1a" to e@pose the transaction functionait" . Coud $e done $" con/ertin! COBO6 CICS pro!ra' to COBO6 stored procedure 9often in/o/es itte chan!e;, or repicatin! transaction functionait" in S56 procedure . Coud aso in/oBe CICS transaction /ia stored procedure . One optionC DS4-CICS stored procedure that co'es 1ith DB2 . -ternati/eC code to CICS <ACI interface "oursef, usin! eitherC . <ACI C-66, or . <A<C CICS 9easier to code; . 9anao!ous to DB2 ca attach /ersus TSO attach; 2011 IBM Corporation #unnin! DB2 N 94DM; or DB2 10O . )se nati/e S56 stored procedures, $ut $e dei$erate a$out this if "ouFre aread" usin! e@terna S56 procedures . The si'per ifec"ce processes of nati/e S56 procedures are ess co'pein! if "our e@terna S56 procedure infrastructure is 1e esta$ished and 'ature . Botto' ineC ad/anta!es of nati/e S56 procedures /ersus e@terna S56 procedures 'aBe con/ersion 1orth1hie, $ut "ouF 1ant to do that in a non0disrupti/e fashion . If "ou donFt aread" ha/e zIIP en!ines, consider !ettin! so'e 9or 'a"$e addin! to 1hat "ou ha/e; . 4ati/e S56 procedures coud $e a !ood dri/er of zIIP utiization on "our s"ste' 2011 IBM Corporation )sin! e@terna S56 proceduresO . *et fa'iiar and co'forta$e 1ith the different ifec"ce processes of nati/e S56 procedures . 4e1 D<P6OE option of BI4D P-CL-*< . 4e1 -CTI2-T< 2<#SIO4 option of -6T<# P#OC<D)#< . Ma"$e con/ert e@terna S56 procedures to nati/e S56 procedures 1hen up!radin! e@istin! appication . So'eti'es, as si'pe as droppin! and recreatin! the procedure 1ithout the D<4C<D and <AT<#4-6 options, and 1ithout a (6M <42I#O4M<4T specification . Ma" need (6M <42I#O4M<4T DO# D<B)* MOD< . So'eti'es, not so si'pe 9'ore on this to co'e; . -s appropriate, choose nati/e S56 procedures for ne1 DB2 appication de/eop'ent 2011 IBM Corporation 7ints, tips, etc& 2011 IBM Corporation - co''on =uestion . >I thou!ht that ha/in! 'utipe (6M0'ana!ed stored procedure address spaces 1as !ood for scaa$iit"& 4ati/e S56 procedures run in one address space 1onFt that ha/e a constrainin! effect on throu!hputO? . -ns1erC 4O, it 1i not . ThinB a$out itC a nati/e S56 procedureFs e@ecuta$e is a pacBa!e, and pacBa!es a1a"s run in DBM1 . If "ouFre runnin! 1000 CICS0DB2 transactions per second fro' 'utipe CICS re!ions, each one has a pacBa!e that runs in DBM1 . DonFt 1orr" a$out DBM1 >runnin! out of tasBs? a nati/e S56 procedure runs under the caerFs tasB, 1hich is e@terna to DBM1 2011 IBM Corporation -nother co''on =uestion . >Mutipe stored procedure address spaces $oost a/aia$iit" 9e&!&, "ou can isoate ne1 stored procedures in their o1n address space;& (ith nati/e S56 procedures a runnin! in DBM1, 1onFt that ne!ati/e" i'pact appication sta$iit"O . -ns1erC 4O, it 1i not . ThinB a$out itC e/er"thin! that e@ecutes in DBM1 is DB20!enerated, DB20'ana!ed code . Mutipe address spaces for e@terna stored procedures hep to protect the s"ste' fro' an error that 'i!ht e@ist in user01ritten code thatFs not a pro$e' 1ith nati/e S56 procedures 2011 IBM Corporation <@terna0to0nati/e con/ersion 91; . So'e S56 source code chan!es 'a" $e re=uired . One reason for thatC so'e error0handin! o!ic that 1orBed for an e@terna S56 procedure 1onFt produce the desired $eha/ior in a nati/e S56 procedure . -s pre/ious" noted, nati/e S56 procedures ao1 nested co'pound state'ents, pro/idin! a 'eans of codin! 'uti0state'ent error handers . 6acBin! that option, peope codin! e@terna S56 procedures 1oud so'eti'es use an ID $ocB to i'pe'ent the 'uti0state'ent hander . Pro$e'C an >a1a"s true? condition used to enter an ID0$ased hander 9ID 1Q1 T7<4:; 1i in a nati/e S56 procedure cear the dia!nostics area 9oops; . In >!oin! nati/e?, chan!e these condition handers to co'pound S56 state'ents set off $" B<*I4 and <4D 2011 IBM Corporation <@terna0to0nati/e con/ersion 92; . -nother potentia reason for S56 source code chan!es 1hen con/ertin! fro' e@terna to nati/eC differences in un=uaified cou'n//aria$e/para'eter na'e resoution . Eou coud ha/e in "our S56 procedure an un=uaified /aria$e or para'eter na'e thatFs the sa'e as the na'e of a cou'n in a ta$e accessed $" the procedure . If an e@terna procedureC DB2 1i checB first to see if a /aria$e of that na'e has $een decared, then if itFs the na'e of one of the procedureFs para'eters if neither is true, assu'ption is that itFs a cou'n na'e . If nati/eC DB2 1i first checB to see if the na'e is that of a cou'n of a ta$e referenced $" the procedure, then if a /aria$e of that na'e has $een decared, then if itFs the na'e of one of the procedureFs para'eters . SoutionC either use =uaified na'es, or use a na'in! con/ention that cear" identifies para'eters and /aria$es 9e&!& use pR or /R prefi@es; 2011 IBM Corporation <@terna0to0nati/e con/ersion 9G; . (hat a$out the e@terna procedureFs coectionO . The pacBa!e of an e@terna S56 procedure can $e $ound into an" coection, and that coection na'e can $e specified /ia the CO66ID option of C#<-T< P#OC<D)#< . B" defaut, cain! pro!ra' 1i search in CO66ID coection for e@terna procedureFs pacBa!e . (hen a nati/e S56 procedure is created, the coection na'e for the pacBa!e 1i $e the sa'e as the procedureFs sche'a na'e . If the pacBa!e of a to0$e0con/erted e@terna S56 procedure 1as $ound into a coection 1ith a na'e other than the procedureFs sche'a na'eC . <nsure that the coection 1ith the sa'e na'e as the procedureFs sche'a 1i $e searched 1hen the nati/e S56 procedure is caed, O# . Put a S<T C)##<4T P-CL-*<S<T in the $od" of the S56 procedure, referencin! the e@terna procedureFs coection na'e, and $ind a cop" of the nati/e S56 procedureFs >root? pacBa!e into that coection 2011 IBM Corporation <@terna0to0nati/e con/ersion 93; . Dor 'ore con/ersion infor'ation, checB out the $rief 9Just a fe1 pa!es; $ut hi!h" infor'ati/e IBM >Technote? at this )#6C httpC//111001&i$'&co'/support/doc/ie1&1ssOuidQs1!212N+N3M 2011 IBM Corporation Detchin! resut sets 91; . -n area in 1hich there is a !ood $it of confusion . E<S, the caer of a stored procedure can fetch resut set ro1s fro' a cursor decared and opened in the stored procedure . Detais can $e found in the DB2 -ppication Pro!ra''in! and S56 *uide, $ut here are the $asicsC . The stored procedure is created 1ith DE4-MIC #<S)6T S<TS n, 1ith >n? $ein! the nu'$er of resut sets that can $e returned $" the stored procedure . OL if >n? S actua nu'$er of cursors to $e decared and opened $" the stored procedure 2011 IBM Corporation F5T,6 Detchin! resut sets 92; . The stored procedure decares one or 'ore cursors (IT7 #<T)#4 . If stored procedure created 1ith COMMIT O4 #<T)#4 E<S, cursor decaration 'ust aso specif" (IT7 7O6D 9this to pre/ent the cursor fro' $ein! cosed 1hen stored procedure co'petes; . The stored procedure opens the cursor, $ut does 4OT fetch fro' the cursor . -n" ro1s fetched $" the stored procedure openin! the cursor 1i not $e a/aia$e to the caer of the stored procedure 2011 IBM Corporation Detchin! resut sets 9G; . The cain! pro!ra' decares resut set ocator /aria$es for stored procedure0opened cursors that 1i return ro1s to the caer . The cain! pro!ra' cas the stored procedure 9or procedures; that returns a resut set 9or sets; . The cain! pro!ra' issues an -SSOCI-T< 6OC-TO#S state'ent for each stored procedure caed that 1i return one or 'ore resut sets . If caed stored procedure AET 1i open se/era cursors, the -SSOCI-T< 6OC-TO#S state'ent for AET in the cain! pro!ra' 1i incude a resut set ocator /aria$e for each cursor . <@a'peC -SSOCI-T< 6OC-TO#S 9C6OC1, C6OC2; (IT7 AET 2011 IBM Corporation Detchin! resut sets 93; . The cain! pro!ra' issues an -66OC-T< C)#SO# state'ent for each resut set ocator /aria$e na'ed in an -SSOCI-T< 6OC-TO#S state'ent . 4o need for the cursor na'e in an -66OC-T< C)#SO# state'ent to 'atch the na'e of the cursor decared in the caed stored procedure . The cain! pro!ra' fetches ro1s fro' the resut sets, usin! the cursors na'ed in the -66OC-T< C)#SO# state'ents 2011 IBM Corporation DB2 10C #<T)#4 TO C6I<4T cursors . DB2 NC stored procedure can return resut set one e/e up in chain of nested procedures 9(IT7 #<T)#4 TO C-66<#; . Dor e@a'pe, if pro!ra' P#O*R- cas stored procedure P#OCRB, and P#OCRB cas P#OCRC, P#OCRB can fetch fro' a cursor decared and opened in P#OCRC, $ut P#O*R- cannot . If P#O*R- needs that resut set, P#OCRC can put it in a te'porar" ta$e, and P#O*R- can !et the ro1s fro' that te'p ta$e, O# . P#OCRB can decare and open a cursor referencin! the te'p ta$e, and P#O*R- can fetch the resut set ro1s throu!h that cursor; . - DB2 10 stored procedure can decare a cursor (IT7 #<T)#4 TO C6I<4T 9Just iBe DB2 for 6)(; . >Top0e/e? pro!ra' 9one that cas first stored procedure, 1hich then cas another stored procedure; can fetch ro1s, $ut the cursorFs resut set is in/isi$e to stored procedures $et1een it and top0e/e pro!ra' 2011 IBM Corporation Pre/ious sideFs point, in a picture: . DB2 NC . DB2 10C Pro!ra' AET Stored proc - Stored proc B DECLARE C1 CURSOR C-66 C-66 WITH RETURN TO CALLER Pro!ra' AET Stored proc - Stored proc B DECLARE C1 CURSOR C-66 C-66 WITH RETURN TO CALLER WITH RETURN TO CLIENT 2011 IBM Corporation #o$ert Cattera rfcatter%us&i$'&co' Than7s or !our time8