Binding application packages and plans

You must bind the DBRM that is produced by the SQL statement processor to a package before your Db2 application can run. The bind process establishes a relationship between an application program and its relational data.

Before you begin

You must have appropriate privileges. For more information, see Privileges required for handling plans and packages

About this task

During the precompilation process, the Db2 precompiler produces both modified source code and a database request module (DBRM) for each application program. The modified source code must be compiled and link-edited before the program can be run. DBRMs must be bound to a package. You can then associate that package with a particular application plan.

During the bind process, Db2 also completes the following actions:

  • Validates object references in the SQL statements of the program, such as table, view, and column names, against the Db2 catalog. Because the bind process occurs before program execution, errors are detected and can be corrected before the program is executed.
  • Verifies the authorization of the bind process to specify the program owner and the authorization of the specified owner to access data that is requested by SQL statements in the program.
  • Selects the access paths that Db2 uses to access data for the program. Db2 considers factors such as table size, available indexes, and others, when selecting the access paths.

When determining the maximum size of a plan, you must consider several physical limitations, including the time required to bind the plan, the size of the EDM pool, and fragmentation. As a general rule, the EDM pool should be at least 10 times the size of the largest DBD or plan, whichever is greater.

Each package that you bind can contain only one DBRM.

Exception: You do not need to bind a DBRM if the only SQL statement in the program is SET CURRENT PACKAGESET.

Because you do not need a plan or package to execute the SET CURRENT PACKAGESET statement, the ENCODING bind option does not affect the SET CURRENT PACKAGESET statement. An application that needs to provide a host variable value in an encoding scheme other than the system default encoding scheme must use the DECLARE VARIABLE statement to specify the encoding scheme of the host variable.

You must bind plans locally, regardless of whether they reference packages that run remotely. However, you must bind the packages that run at remote locations at those remote locations.

From a Db2 requester, you can run a plan by specifying it in the RUN subcommand, but you cannot run a package directly. You must include the package in a plan and then run the plan.

Tip: Develop a naming convention and strategy for the most effective and efficient use of your plans and packages.

Procedure

To bind application programs, take the following actions.

  1. To bind individual DBRMs into packages, use BIND PACKAGE commands with ACTION(REPLACE). Packages provide the flexibility for you to test different versions of a program without having to rebind everything in the application plan.

    For programs whose corresponding DBRMs are in HFS files, you can use the Db2 command line processor to bind the DBRMs to packages. Optionally, you can also copy the DBRM into a partitioned data set member by using the oput and oget commands and then bind it by using conventional JCL.

    To create new trigger packages for existing triggers, you must re-create the trigger that is associated with the package. For more information, see Trigger packages.

  2. To designate packages in application plans, use the BIND PLAN command with ACTION(REPLACE). Plans can specify packages, collections of packages, or a combination of these elements. If you specify one or more DBRMs to include in the plan (by using the MEMBER option of BIND PLAN), Db2 automatically binds those DBRMs into packages and then binds those packages into the plan. The plan contains information about the designated packages and about the data that the application programs intend to use. The plan is stored in the Db2 catalog.