Archives for category: DB2 bind process
Add new DB2 program in Changeman

Point to take care while creating new DB2 program in changeman and to promote it to test regions

Create a PKG member in the package where a new DB2 program is present. This member is required in order for DBRM to be promoted to the test region. If this member is not present, changeman gives error while promoting DBRM.

          BIND PACKAGE      (PVNPRBDL) +
                MEMBER          (PVNBPBOT) + 
                OWNER            (DABOC) + 
                QUALIFIER       (PVNDB001) + 
                ACTION           (REPLACE) + 
                DEGREE          (1) +  
                ISOLATION      (CS) + 
                VALIDATE       (BIND) + 
                EXPLAIN         (YES) +  
                 RELEASE       (COMMIT) + 
                CURRENTDATA  (YES) 


Member name = New program name.

Whenever we promote a DB2 component we need to promote all the three components related to the program namely DBR, LDB,PKG. Bind will automatically occur.
So we do not require a separate JCL to bind.

                PVNPNOT           DBR
                PVNPNOT           LDB
                PVNPNOT           PKG

In some mainframe enviornments, do not bind a program to a plan, since in the environment a lot of packages are bound to a plan. Doing a plan bind results in corruption of plan as only one DBRM is bound to the specific plan then.

So always do a package bind by the above process in case plan is bound by various packages in the test region. (Please check environment details with DBA before binding any program).
DB2 Bind precompiler process

DB2 Bind Process  

Find a quick overview of the bind process in my earlier post.

                                         Process for Bind in Brief

PrecompilerFunctions:

Checks the DB2 code  in the program for errors. 
Adds working storage areas and source code compatible statements that are used to     invoke DB2. One to the working storage areas contains a literal “timestamp” called a consistency token.
Extracts all the SQL statement from the program source and placed into a member called   the DataBase Request Module, or DBRM, which has same consistency token.

Compiler:The COBOL code with SQL is input to complier and compiler checks for any error and Object Module is formed. This code is complied version of code.

Modified Code: 
The Object Module is input to Link-edit and modified code is linked to all the DB2 runtime components to create Load module or .exe file which is include in DB2COBOLprograms.
The 'timestamp' or consistency token is embed in this module which was generated in prec-ompiler stage. If there are more than one DB2 modules linked statically to load module then token  of each is generated and linked.

DB2 Bind:

  • Bind Process read DBRM which is created in precomplier stage and creates access path to read data.
  • Access path along with consistency token is stored in DB2 catalog tables as a package.
  • Every package is bound into package list or collection
  • Collection name is specified by package parameter.
  • A Collection is a group of Packages that are included in one or more Plans. The QUALIFIER parameter of the bind is used to direct the SQL to the specific set of DB2 objects (tables, views, aliases or synonyms) qualified by this name.
  • Apart from building plans and packages, bind also validates:
  1. SQL statements using DB2 Catalog
  2. Validates authorization id that if owner is allowed to perform bind process 
  3.  Selects access path depending upon availability of  indexes, table size etc. 

DB2-COBOL Program:

DB2 sub-system and plan name is given in JCL under SYSTSIN. 
When SQL statement is executed, DB2 searches for collection with the plan by package name and timestamp. This should match else it give bind error -805.

I have written DB2 bind as required in SCLM. The steps may vary for some other tools but the bind process remains same. 


The bind process

 The bind process establishes a relationship between an application program and its relational data. This step is necessary before you can execute your program. Currently, DB2 allows you two basic ways of binding a program: to a package, or directly to an application plan.

Even when they are bound into packages, all programs must be designated in an application plan. BIND PLAN establishes the relationship between DB2 and all DBRMs or packages in that plan. Plans can specify explicitly named DBRMs, packages, collections of packages, or a combination of these elements. The plan contains information about the designated DBRMs or packages and about the data the application program intends to use. It is stored in the DB2 catalog.


I am giving you one practical example to differentiate between plan and package and DBRM which i read recently in a book–

PLAN package and DBRM:-
Consider a grocery store analogy. Before going to a grocery store you prepare a shopping list. As you go through the list and you find an item in the list, you place the item in  your shopping cart. After you pay for the items at the check-out counter, the counter person  places item in your bag. You can think the purchasing item as DBRMs. The bag is the plan. You have multiple DBRMs(grocery items) in your plan(shopping bag).

In the package environment, rather than actually removing items from the shelf, you would mark on your shopping list the location of each item in the store. Later you gave the checked list to the counter person at the counter. The counter person then would place the list in the bag not the actual items. The Plan(bag) contains a list pointing to the physical location of the packages (grocery items) that are still on the self.

In addition to building packages and plans, the bind process:
Validates the SQL statements using the DB2 catalog.  During the bind process, DB2 checks your SQL statements for valid table, view, and column names. Because the bind process occurs as a separate step before program execution, errors are detected and can be corrected before the program is executed.
Verifies that the process binding the program is authorized to perform the data accessing operations requested by your program’s SQL statements. When you issue BIND, you can specify an authorization ID as the owner of the plan or package. The owner can be any one of the authorization IDs of the process performing the bind. The bind process determines whether the owner of the plan or package is authorized to access the data the program requests.Selects the access paths needed to access the DB2 data your program wants to process.In selecting an access path, DB2 considers indexes, table sizes, and other factors. DB2 considers all indexes available to access the data and decides which ones (if any) to use when selecting a path to the data.

Advantages of packages


Ease of maintenance: When you use packages, you do not need to bind the entire plan again when you change one SQL statement. You need to bind only the package associated 
with the changed SQL statement.

Incremental development of your program: Binding packages into package collections allows you to add packages to an existing application plan without having to bind the entire plan again. A collection is a group of associated packages. If you include a collection name in the package list when you bind a plan, any package in the collection becomes available to the plan. The collection can even be empty when you first bind the plan. Later, you can add packages to the collection, and drop or replace existing packages, without binding the plan again.