Sei sulla pagina 1di 36

DB2 - Program Preparation

DB2-Prep-1

Program Preparation
COBOL Program with Embedded SQL

DB2 Precompiler

Modified COBOL Program

DBRM

DB2 Catalog
Compile and Linkedit
Load Module Plan/Package
DB2-Prep-2

BIND

Pre-compiler
The Precompiler
Comments all SQL statements and replaces them with COBOL CALL statements Checks for errors Does not access the DB2 Catalog Places Consistency Token in the modified source program and the DBRM

DB2-Prep-3

Pre-compile parameters

LEVEL HOST() DATE APOST/QUOTE

PRECOMP, COMP,LKED JCL


//PRECOMP EXEC PGM=DSNHPC //DBRMLIB DD DSN=DBRMLIB,DISP=SHR //SYSIN DD DSN=SOURCE,DISP=SHR //SYSLIB DD DSN=&INCLLIB,DISP=SHR //STEPLIB DD DSN=DSN410.SDSNEXIT,DISP=SHR // DD DSN=DSN410.SDSNLOAD,DISP=SHR //SYSCIN DD DSN=&&DSNHOUT,DISP=(NEW,PASS),UNIT=3390, // SPACE=(800,(&WSPC,&WSPC)) //SYSPRINT DD SYSOUT=* //SYSTERM DD SYSOUT=* //SYSUDUMP DD SYSOUT=* //SYSUT1 DD SPACE=(100,(&WSPC,&WSPC),,,ROUND),UNIT=3390

BIND
The BIND routine Checks for errors, using the DB2 catalog Develops access strategy for each SQL statement Stores strategies as Plans or Packages

DB2-Prep-4

PLAN
PLAN

DBRM

DBRM

DBRM

DBRM

DBRM

DB2-Prep-6

BIND PLAN
BIND PLAN (PLAN1) MEMBER ( PROG1, PROG2, PROG3) LIBRARY (TRG1T01.DBRMLIB) QUALIFIER (TRG001) OWNER (TRG001) ..

DB2-Prep-7

PLAN with DBRMs : Disadvantages


PLAN1

PROG1

PROG2

PROG3

Optimization of all SQL statements in all DBRMs even if only one of them changes.

PLAN1

PLAN2

PLAN3

When the same DBRM is bound into multiple plans. all the plans need to be rebound when the DBRM changes.

PROG1
DB2-Prep-9

PACKAGES & COLLECTIONS


Collection

Package

Package

Package

Package

DBRM

DBRM

DBRM

DBRM

DB2-Prep-10

BIND PACKAGE
BIND PACKAGE (COLL1) MEMBER ( PROG1 ) LIBRARY (TRG1T01.DBRMLIB) OWNER (TRG001) QUALIFIER (TRG001) ..

DB2-Prep-11

PACKAGES : Naming Convention


A package has a three-part name: location_name.collection_id.package_id A package has two attributes: version_id and consistency token.

Example:

loc1.coll1.prog1.test loc1.coll1.prog1
DB2-Prep-13

PLANS AND PACKAGES


PLAN

Collection

Collection

Collection

DBRM

Package

Package

Package

Package

Package

DBRM

DBRM

DBRM

DBRM

DBRM

DB2-Prep-14

BIND PLAN : PKLIST Parameter


BIND PLAN(PLAN1) PKLIST (MYCOLL1.* , MYCOLL2.PACK1 , *.PACK2 ) . .. .. An Asterisk (*) can be used in place on Location_name Collection_id Package_id : *.COLL1.PACK1 : *.PACK1 : COLL1.*

DB2-Prep-15

Package Search
PLAN1

COLL1.*

COLL2.*

COLL3.*

PACK1

PACK2

PACK3

PACK4

PACK5

Search Direction
DB2-Prep-16

SET CURRENT PACKAGESET


Package Search
COLL1.* PLAN1

COLL2.*

COLL3.*

PACK1

PACK2

PACK3

PACK4

PACK5

SET CURRENT PACKAGESET = COLL2 ;


DB2-Prep-17

Package Versions
Prog1 Prog1

TEST

PROD

Prog1

DBRMs

Prog1

With Packages, the precompiler option VERSION can be used to bind multiple versions of the programs into packages.

Prog1.prod Prog1.test

PACKAGE
DB2-Prep-12

VERSION Revisited
PROG1

Version(TEST)

Precompiler

Version(PROD)

Compile & Link-edit

BIND PACKAGE

Compile & Link-edit

BIND PACKAGE

TEST PROG1 LOAD LIBRARY

COLL1. PROG1. TEST PACKAGE

PROG1
PRODUCTION LOAD LIBRARY

COLL1. PROG1. PROD PACKAGE


DB2-Prep-18

QUALIFIER Parameter
SELECT NAME

FROM

EMPLOYEE

PROG1

WHERE EMPID = :WS-EMPID

TEST

QUALIFIER

PROD

TEST.EMPLOYEE

PROD.EMPLOYEE
DB2-Prep-20

ACQUIRE
ACQUIRE(USE) - Opens table spaces and acquires locks only when the application program bound to the plan first uses them. ACQUIRE(ALLOCATE) - Opens all table spaces and acquires all table space locks when the plan is allocated. ACQUIRE(USE) - Fixed for Packages

DB2-Prep-21

RELEASE

RELEASE(COMMIT) Releases resources at each commit point RELEASE(DEALLOCATE) Releases resources only when the application plan terminates.

DB2-Prep-22

CONCURRENCY

ACQUIRE(ALLOCATE) / RELEASE(DEALLOCATE) ACQUIRE(USE) / RELEASE(DEALLOCATE) ACQUIRE(USE) / RELEASE(COMMIT)

Greater Concurrency but more chances of a Deadlock


DB2-Prep-23

ISOLATION : RR
Row1
Row2 LOCK LOCKS LOCKS Row3

Request a new page or a row


DB2-Prep-24

ISOLATION : CS
Row1
Row2 LOCK LOCKS LOCKS Row3

Request a new page or a row

DB2-Prep-25

ISOLATION : UR

Allows applications to read UNCOMMITTED DATA

Applies to read-only operations

Introduced in DB2 Version 4

DB2-Prep-26

ISOLATION LEVELS : Summary


ISOLATION Access to uncommitted data Not Possible Non-repeatable Read Not Possible Not Possible Possible Phantom Read Not Possible Possible Possible

Repeatable Read (RR) Cursor Not Possible Stability (CS) Uncommitted Possible Read (UR)

DB2 Version 4 Allows ISOLATION LEVEL to be specified at statement level


DB2-Prep-27

VALIDATE

How to handle "OBJECT NOT FOUND" and "NOT AUTHORIZED" errors that occur at bind time.

RUN - At run-time if failed during bind time BIND - Only during Bind time

DB2-Prep-28

ACTION
ADD Add a new plan/package that does not already exist REPLACE replace old plan/package with a new one of the same name

REPLVER replace a specific version of a package


DB2-Prep-29

COPY Parameter
BIND PACKAGE (MYCOLL1) COPY (MYCOLL2.PACK1) COPYVER(PROD) .. COPY - SQL statements from an existing package are copied to the package

COPYVER - Version that needs to be copied

DB2-Prep-30

REBIND PLAN/ REBIND PACKAGE


REBIND PLAN(PLAN1) VALIDATE(BIND) . . ... When SQL statements have not changed but An INDEX is added RUNSTATS is run REBIND PLAN/PACKAGE is cheaper than BIND with ACTION(REPLACE)
DB2-Prep-31

FREE PLAN
FREE PLAN (PLAN1) Delete the plan PLAN1

FREE PLAN (*)


Delete all plans

DB2-Prep-32

FREE PACKAGE
FREE PACKAGE(MYCOLL1.*) FREE PACKAGE(MYCOLL1.MYPACK1)

FREE PACKAGE(MYCOLL1.MYPACK1.TEST)

DB2-Prep-33

bind jcl
//BINDDBZ1 EXEC PGM=IKJEFT01 //SYSUDUMP DD SYSOUT=* //SYSTSPRT DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSTSIN DD * DSN SYSTEM(DBZ1) BIND LIBRARY(DBRM LIBRARY) ACTION(REPLACE), VALIDATE(BIND), ISOLATION(CS), FLAG(I), ACQUIRE(USE) , RELEASE(COMMIT), EXPLAIN (NO) , OWNER(SSG1T00) QUALIFIER(SSG1T01), PLAN (planname), MEMBER (dbrmname) END

Executing a Program
RUN PROGRAM(PROG1) PLAN(PLAN1) LIBRARY (TRG001.LOADLIB) PARMS (01-01-1996) RUN subcommand can be issued in the TSO foreground or in the TSO background as well as from the DB2I RUN panel

DB2-Prep-34

Run jcl
//SQLSTEP EXEC PGM=IKJEFT01 //SYSTSPRT DD SYSOUT=X //SYSTSIN DD * DSN SYSTEM(DBZ1) RUN PROGRAM(progname) PLAN(planname) LIBRARY (load library) END //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=*,DCB=LRECL=81 //SYSABOUT DD SYSOUT=* //SYSDBOUT DD SYSOUT=*

Program Execution : Consistency Token

Load Module

Plan/Package

Consistency Token

Modified COBOL Program

DBRM

DB2-Prep-5

Potrebbero piacerti anche