A DB2 package turns the static SQL from one DBRM into an executable form that Db2 can run with chosen access paths and bind options. This hands-on tutorial walks through prerequisites, BIND PACKAGE steps, catalog verification, and the errors you are most likely to see when the package, plan, and load module fall out of sync.
When you precompile a COBOL, PL/I, C, or other host-language program that contains embedded SQL, Db2 produces a database request module (DBRM). The DBRM holds the SQL statements and a consistency token. Compiling and link-editing produce a load module that calls the Db2 language interface. Binding is the Db2-side step that validates the SQL, chooses access paths, and stores an executable package.
Modern shops almost always bind each DBRM into a package inside a collection, then point an application plan at that collection with PKLIST. That design lets you change and rebind one program without rebinding every other DBRM that used to live inside a monolithic plan MEMBER list.
Do not start BIND PACKAGE until the deployment unit is clear. The package is only one artifact in a chain that must stay consistent from precompile through production run.
| Area | What to verify |
|---|---|
| DBRM | A current DBRM member from the same precompile that produced the load module you intend to run. |
| Collection | An agreed collection name and promotion rules for test, QA, and production packages. |
| Authority | BINDADD or BIND (as needed), plus privileges on objects referenced by the SQL when VALIDATE(BIND) is used. |
| Plan linkage | A plan whose PKLIST includes the collection (or an explicit package entry) so run-time search can find the package. |
| Options | Documented OWNER, QUALIFIER, ISOLATION, RELEASE, EXPLAIN, APPLCOMPAT, and encoding standards for the shop. |
Confirm the Db2 subsystem or group attach name, the DBRM library disposition, and whether ACTION should be ADD for a new version or REPLACE for the current version. Agree on OWNER and QUALIFIER with the DBA team so unqualified SQL resolves to the intended schema and privilege checks use the intended authorization ID.
BIND PACKAGE has many options. Shops standardize a subset so test and production behave the same way. Understand at least these before you submit a bind job.
| Option | What it controls |
|---|---|
| PACKAGE(collection) | Target collection that owns the package being created or replaced |
| MEMBER(dbrm) | DBRM member name; usually matches the program name |
| ACTION(REPLACE|ADD) | Replace an existing package/version or add a new one |
| OWNER | Authorization ID that owns the package and is checked for SQL privileges |
| QUALIFIER | Default schema for unqualified object names in the SQL |
| ISOLATION | Default concurrency behavior such as CS, UR, RS, or RR |
| VALIDATE | BIND checks objects and privileges at bind time; RUN defers some checks |
| EXPLAIN | Optionally populate explain tables with access-path information |
Isolation, release, currentdata, degree, and APPLCOMPAT also matter for concurrency and SQL level. Copy an approved bind skeleton from your shop rather than inventing a unique set of options for every program. Different collections can hold the same package name with different options when you need alternate behaviors such as CS versus UR.
List the DBRM library member and match its name to the program. The member used for BIND PACKAGE must be the DBRM from the same precompile that produced the object module in the load library. Mixing a new load module with an old DBRM (or the reverse) is a classic path to SQLCODE -818.
Batch shops usually run the TSO Terminal Monitor Program IKJEFT01, start a DSN session for the subsystem, and issue BIND PACKAGE. The following skeleton uses a training collection and replaces the package for member EMPRPT01.
1234567891011121314151617//BINDPKG EXEC PGM=IKJEFT01,DYNAMNBR=20 //STEPLIB DD DISP=SHR,DSN=DSN.V12R1M0.SDSNEXIT // DD DISP=SHR,DSN=DSN.V12R1M0.SDSNLOAD //DBRMLIB DD DISP=SHR,DSN=APP.TRAIN.DBRMLIB //SYSTSPRT DD SYSOUT=* //SYSTSIN DD * DSN SYSTEM(DB2T) BIND PACKAGE(TRAINCOLL) MEMBER(EMPRPT01) - ACTION(REPLACE) - OWNER(APPTRAIN) - QUALIFIER(TRAINING) - ISOLATION(CS) - VALIDATE(BIND) - RELEASE(COMMIT) - EXPLAIN(YES) END /*
Adjust STEPLIB, SYSTEM, collection, OWNER, QUALIFIER, and library names to your site. Some shops put LIBRARY on the BIND statement instead of relying only on DBRMLIB. If you bind from DB2I, the panels collect the same information and generate comparable DSN commands.
Binding the package does not automatically attach it to every plan. A typical plan uses a collection wildcard:
1234BIND PLAN(TRAINPLN) - PKLIST(TRAINCOLL.*) - ACTION(REPLACE) - ISOLATION(CS)
After the collection is already on the PKLIST, rebinding one package is enough for that program change. Rebind the plan only when the package list itself changes.
BIND PACKAGE can COPY an existing package into another collection and change selected options. That pattern is useful when promoting a tested package or when you need the same SQL with a different ISOLATION or QUALIFIER without re-precompiling.
Treat a zero return code from the bind step as necessary but not sufficient. Verify the catalog and the runtime path.
123456SELECT COLLID, NAME, VERSION, OWNER, QUALIFIER, BINDTIME, ISOLATION, VALID, OPERATIVE FROM SYSIBM.SYSPACKAGE WHERE COLLID = 'TRAINCOLL' AND NAME = 'EMPRPT01' ORDER BY BINDTIME DESC;
Catalog column details can vary by Db2 release. Use the catalog documentation for your installed level, and prefer local reporting views when your site provides them.
Most package problems are consistency problems: wrong library, wrong collection, wrong plan list, or mismatched timestamps. Use the symptom table as a first triage guide.
| Symptom | Likely cause | Corrective action |
|---|---|---|
| DBRM not found / bind cannot open member | Wrong DBRMLIB, member name, or discarded DBRM after precompile | Confirm the DBRM library and MEMBER name from the successful precompile step. |
| Authorization failure on BIND PACKAGE | Missing BINDADD/BIND or OWNER not authorized for referenced objects | Identify the primary ID and OWNER, then grant only the required privileges. |
| Unresolved object or privilege at bind | Wrong QUALIFIER, missing table/view, or VALIDATE(BIND) with incomplete grants | Qualify names or correct QUALIFIER; create objects; grant SELECT/INSERT/UPDATE/DELETE as needed. |
| Package bound but program gets -805 | Plan PKLIST does not include the collection, or wrong package set at run time | REBIND PLAN with the correct PKLIST and verify CURRENT PACKAGESET if used. |
| Package bound but program gets -818 | Load module consistency token does not match the DBRM used for bind | Rebuild from one precompile: keep DBRM, object, and bind as one generation. |
Also watch for VALIDATE(RUN) packages that bind cleanly and then fail at first execution when an object or privilege is missing. Prefer VALIDATE(BIND) for static production packages unless your shop has a documented reason to defer validation.
Imagine each COBOL program writes its Db2 questions on a worksheet (the DBRM). Creating a package is like giving that worksheet to a teacher who checks the questions, decides the fastest way to find the answers, and files the finished sheet in a labeled binder (the collection). The class plan is a list of binders the teacher is allowed to open. If your sheet is filed but the class plan never lists that binder, the student still cannot get answers at run time.
1. What does BIND PACKAGE primarily build from?
2. Why bind packages into a collection instead of stuffing every DBRM into one plan?
3. Which option names the DBRM member to bind?
4. What does QUALIFIER control for unqualified SQL object names?
5. Where do you verify that a package exists after a successful bind?