Summary -

In this topic, we explain about the below sections -

Tip! Refer Precompilation process before proceeding for better understanding.

Why BIND?

The precompilation process produces the load module (compiled and link-edited source code) and database request module (DBRM) for every application program.

The DBRM is not the executable component to run the application program. To execute the application program, the DBRM should be bound to a package of a specific application plan.

Once the bound is successful, then we can run the application program that has DB2 SQL statements.

What is BIND?

The bind process builds a connection between an application program and its relational data(table data).

The binding process is responsible for detecting errors and correcting them before the execution of the program.

The Process -

DB2 BIND process completes the below actions -

  • Validates the object (tables, views, and column names) references in the SQL statements of the application program against the DB2 catalog.
  • Verifies the authorization of the program owner and authorization level to access the data that was requested by the SQL statements in the application program.
  • Selects the best access path to access the data by DB2. Table size, indexes, and other factors are considered while selecting the best access path.

Each package can contain only one DBRM or multiple DBRM.

We can run a plan by specifying it. However, we can't run a package without specifying a plan name along with it. Because the plan is executable and the package is not executable.

IKJEFT01 utility is used to bind the DBRM to the package.

Note! In this topic, we have taken COBOL as an application language. So, we discussed COBOL + DB2 bind process below.

If the module is a batch module (COBOL + DB2), bound the module to package is sufficient to execute. Suppose the module is an online module (COBOL + DB2 + CICS). In that case, RCT entries also require to execute the module after bound it to the package.

BIND PACKAGE JCL -

Note! Below BIND PACKAGE JCL works as it is when you change your project-specific utility libraries and DBRM libraries.

Code -

BIND JCL
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//MTH001B JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID                             
//**********************************************************************
//*  DB2 BIND JCL                                                       
//**********************************************************************
//BIND     EXEC PGM=IKJEFT01                                            
//STEPLIB  DD  DISP=SHR,DSN=mthA10.DBAG.SDSNEXIT                        
//         DD  DISP=SHR,DSN=mthA10.SDSNLOAD                             
//DBRMLIB  DD  DSN=MTH001.COBDB2.DBRMLIB,DISP=SHR                       
//SYSPRINT DD  SYSOUT=*                                                 
//SYSTSPRT DD  SYSOUT=*                                                 
//SYSUDUMP DD  SYSOUT=*                                                 
//SYSTSIN  DD  *                                                        
DSN SYSTEM (system-name)                                                
BIND  PACKAGE   (package-name)      -                                   
      MEMBER    (program-name)      -                                   
      ACTION    (action-options)    -                                   
      ISOLATION (isolation-options) -                                   
      VALIDATE  (validate-options)  -                                   
      RELEASE   (release-options)   -                                   
      EXPLAIN   (explain-options)   -                                   
      OWNER     (owner-id)          -                                   
      QUALIFIER (qualifier-name)    -                                   
      ENCODING  (encoding-options)                                      
END                                                                     
/*                                                                      
**************************** Bottom of Data ****************************

BIND PLAN JCL -

Note! Below BIND PLAN JCL works as it is when you change your project-specific utility libraries and DBRM libraries.

Code -

BIND PLAN JCL
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//MTH001B JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID                             
//**********************************************************************
//*  DB2 BIND JCL                                                       
//**********************************************************************
//BIND     EXEC PGM=IKJEFT01                                            
//STEPLIB  DD  DISP=SHR,DSN=MTHA10.DBAG.SDSNEXIT                        
//         DD  DISP=SHR,DSN=MTHA10.SDSNLOAD                             
//DBRMLIB  DD  DSN=MTH001.COBDB2.DBRMLIB,DISP=SHR                       
//SYSPRINT DD  SYSOUT=*                                                 
//SYSTSPRT DD  SYSOUT=*                                                 
//SYSUDUMP DD  SYSOUT=*                                                 
//SYSTSIN  DD  *                                                        
DSN SYSTEM (system-name)                                                
BIND  PLAN      (plan-name)         -                                   
      MEMBER    (program-name)      -                                   
      ACTION    (action-options)    -                                   
      ISOLATION (isolation-options) -                                   
      VALIDATE  (validate-options)  -                                   
      RELEASE   (release-options)   -                                   
      EXPLAIN   (explain-options)   -                                   
      OWNER     (owner-id)          -                                   
      QUALIFIER (qualifier-name)    -                                   
      ENCODING  (encoding-options)                                      
END                                                                     
/*                                                                      
**************************** Bottom of Data ****************************

MEMBER (program-name) -

  • MEMBER is the DBRM name used for the application program stored in the DBRM library.

PACKAGE (package-name) -

  • Package contains optimized access path (OAP) that is generated by optimizer of BIND Process.
  • The package is a non-executable component.
  • The package can contain one or more DBRMs.
  • The package is an intermediate component between the DBRM and PLAN.
  • The package's main advantage is that the rebound is not required when any change in the sub-program. Compilation of subprogram is only sufficient.
  • We should need to bind the plans locally regardless of packages are local or remote.
  • If the package is running at a remote location, the package needs to be bound at the remote location as well as local.

PLAN (plan-name) -

  • The plan also contains an optimized access path(OAP).
  • The plan is an executable component.
  • The plan used to execute the program.
  • The plan has the best access path to retrieve the data from the database by using the SQLs coded in the application program.
  • BIND PLAN command with ACTION(REPL) or ACTION(REPLACE) is used to assign the packages to the application plan.
  • Plans are collections of packages. Suppose we specify one or more DBRMs to include in the plan (using the MEMBER option of BIND PLAN). In that case, Db2 automatically binds those DBRMs into packages and then binds those packages into the plan.
  • The plan has the information about bound packages and data that the application programs panning to use.
  • The plan is stored in the DB2 catalog.

ACTION (action-options) -

  • The ACTION option defines whether the plan or package replaces an existing one with the same name or is new.
  • The available options are REPLACE and ADD.

ISOLATION (isolation-options) -

  • The ISOLATION option defines how far to isolate an application/application program from the effects of other running applications/application programs.
  • In other words, how the program execution is isolated for accessing the database that is accessed by the other programs concurrently.
  • Multiple users can access the database at a time (Concurrency).
  • The Isolation level is the way to maintain the concurrency for various users by setting the levels of access to the database.
  • ISOLATION is the BIND parameter that determines the page lock duration.
  • Types of isolation levels -

    1. Cursor Stability (CS)
    2. Repeatable Read (RR)
    3. Read Stability (RS)
    4. Uncommitted Read (UR)/Dirty Read (DR)

Isolation level can explain in detail in seperate topic.

VALIDATE (validate-options) -

  • VALIDATE option determines of rechecking of BIND or REBIND errors while the program is running.
  • The error types are "OBJECT NOT FOUND" and "NOT AUTHORIZED".
  • The validate-options are RUN and BIND.
  • If not specified anything, it takes RUN as default. i.e., VALIDATE(RUN).
  • Validate will not throw any error messages during the BIND process. It throws warning messages at the time of Running.

RELEASE (release-options) -

  • The RELEASE option is used to decide when to release resources that are used by the program.
  • They are releasing the resource either at each commit point or when the program terminates.
  • The validate-options are COMMIT and DEALLOCATE.
  • For example, DB2 requires an exclusive lock to update a particular table. The Exclusive lock taken by the program is released whenever the options in the RELEASE is executed.
  • If COMMIT is coded in RELEASE, the Exclusive lock will not get released until or unless the COMMIT is executed.

EXPLAIN (explain-options) -

  • The EXPLAIN option is used to obtain information about how SQL statements are executed in the package or plan.
  • The available options are - NO and YES.

OWNER (owner-id) -

  • The OWNER option specifies the owner authorization id of the plan or package.
  • The owner should have the required privileges to execute the SQL statements from the program.

QUALIFIER (qualifier-name) -

  • The QUALIFIER specifies the implicit qualifier for the tables, views, indexes, and aliases in the plan or package.
  • The qualifier is mainly used when performing BIND for remote systems.

ENCODING (encoding-options) -

  • The ENCODING option specifies application encoding for all host variables used in SQL statements in plan or package.
  • The available options are - ASCII, EBCDIC, UNICODE, and ccsid.

LIB -

  • LIB is the library used to specify the partitioned dataset where the DBRMs are stored.
  • If the DBRMLIB is not specified explicitly in the JCL, the LIB option with the DBRM library in the BIND command is required.
  • If the DBRMLIB is specified explicitly, the LIB option with the DBRM library in the BIND command is not required.

Runtime Supervisor -

  • Runtime supervisor is responsible for validating the timestamps of COBOL and DB2 object codes. It checks the timestamp tokens of the object code of COBOL (T1) & object code of DB2 (T2).
  • If T1=T2, the program is ready for execution.
  • If T1!=T2, the program ABENDs with -818 (timestamp mismatch error).

Practical Example -

Scenario - Below example describes how the COBOL + DB2 program bind process using JCL.

Input required -

  • DBRMLIB - MATEGJ.COBDB2.DBRMLIB
  • PLAN - MATEGJC

BIND JCL -

BIND JCL Code
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//MATEGJB JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID                             
//**********************************************************************
//*  DB2 BIND JCL                                                       
//**********************************************************************
//BIND     EXEC PGM=IKJEFT01                                            
//STEPLIB  DD  DISP=SHR,DSN=DSNA10.DBAG.SDSNEXIT                        
//         DD  DISP=SHR,DSN=DSNA10.SDSNLOAD                             
//DBRMLIB  DD  DSN=MATEGJ.COBDB2.DBRMLIB,DISP=SHR                       
//SYSTSIN  DD  *                                                        
DSN SYSTEM (DBAG   )                                                    
BIND  PLAN      (MATEGJC ) -                                            
      MEMBER    (SELECT1 )  -                                           
      ACTION    (REP)       -                                           
      ISOLATION (CS)        -                                           
      VALIDATE  (BIND)      -                                           
      RELEASE   (COMMIT)    -                                           
      OWNER     (MATEGJ )  -                                            
      QUALIFIER (MATEGJ )  -                                            
       ENCODING  (1047)                                                  
 END                                                                     
 /*                                                                      
 //SYSPRINT DD  SYSOUT=*                                                 
 //SYSTSPRT DD  SYSOUT=*                                                 
 //SYSUDUMP DD  SYSOUT=*                                                 
 **************************** Bottom of Data ****************************

JOB Result - MAXCC

BIND JOB MAXCC

JOB Result - BIND Step

BIND JOB Precompile Step

JOB Result - BIND Step Final Report

BIND JOB Precompile Step Result