After the Db2 precompiler writes a DBRM, nothing runs until you BIND. In DB2 for z/OS the DSN subcommands are BIND PACKAGE, BIND PLAN, BIND QUERY (statement-level hints), and BIND SERVICE (native REST services). This page explains what each builds, the authorization you need, and the bind options beginners meet on every production bind job.
BIND is not -BIND from SDSF. You start a DSN session (TSO command DSN SYSTEM(ssid)) or use DB2I, then enter the subcommand. Batch jobs use IKJEFT01 with DSN in SYSTSIN. Data sharing scope is group: the package/plan is available on every member. BIND PACKAGE also deletes phased-out package copies as part of plan management.
| Subcommand | Input | Result |
|---|---|---|
| BIND PACKAGE | DBRM MEMBER or COPY of an existing package | Package in a collection (catalog + directory) |
| BIND PLAN | PKLIST of packages (MEMBER deprecated) | Application plan required to run SQL |
| BIND QUERY | DSN_USERQUERY_TABLE (+ EXPLAIN tables) | SYSQUERY / SYSQUERYPLAN / SYSQUERYOPTS rows |
| BIND SERVICE | One SQL statement (DD or API body) | REST service package + DSNSERVICE row |
BIND PACKAGE builds an application package. Db2 records the description in catalog tables (SYSIBM.SYSPACKAGE and friends) and stores the executable form in the directory. Identify the package by collection and, from the DBRM, package-id and version. Optional location-name binds at a remote server.
123456DSN SYSTEM(DB2A) BIND PACKAGE(PAYROLL) MEMBER(PAYCALC) - ACTION(REPLACE) OWNER(PAYBIND) QUALIFIER(HR) - ISOLATION(CS) RELEASE(COMMIT) EXPLAIN(YES) - VALIDATE(BIND) CURRENTDATA(NO) END
The package owner must be authorized to execute the embedded SQL or the bind produces errors (SYSADM and DATAACCESS include that). VALIDATE(BIND) checks most authorization at bind time; LOCK TABLE and some DDL wait until run time. VALIDATE(RUN) retries failed checks at run time.
Adding a package depends on BINDNV (BIND NEW PACKAGE). The default BINDADD path needs BINDADD plus CREATE IN or PACKADM on the collection (or SYSADM/SYSCTRL/System DBADM). If BINDNV is BIND, PACKADM or BIND on the collection can add a new version of an existing package. REPLACE needs ownership, BIND on the package, or a system authority. BINDAGENT lets you bind on behalf of OWNER. In a trusted context with role ownership, OWNER is a role.
Every program still needs an application plan to allocate Db2 resources at run time. BIND PLAN builds it. Modern plans are thin: PKLIST names collections and packages. The MEMBER option still exists but is deprecated—it binds DBRMs into packages and stuffs them on the plan. Use BIND PACKAGE plus PKLIST unless you cannot.
12345BIND PLAN(PAYPLAN) - PKLIST(PAYROLL.*, COMMON.*) - ACTION(REPLACE) RETAIN - ISOLATION(CS) RELEASE(COMMIT) - CACHESIZE(1024) CURRENTSERVER(DB2A)
| Option | Meaning |
|---|---|
| OWNER | Authorization ID (or role) that owns the package/plan |
| QUALIFIER | Default schema for unqualified objects in static SQL |
| ISOLATION | CS, RR, RS, or UR locking/isolation for the bound SQL |
| RELEASE | COMMIT or DEALLOCATE — when locks/resources are freed |
| VALIDATE | BIND vs RUN — when missing objects/auth are accepted |
| EXPLAIN | NO, YES, or ONLY — populate EXPLAIN tables |
| PATH | SQL path for function/type resolution in the package |
| APPLCOMPAT | SQL application compatibility level (for example V12R1M500) |
| DYNAMICRULES | How dynamic SQL in the package checks authorization |
| CURRENTDATA | Currency of data with isolation CS (NO is common) |
Isolation values: CS (cursor stability, the usual OLTP default), UR (uncommitted read), RS (read stability), RR (repeatable read). DEGREE(1 | ANY) controls query I/O parallelism. REOPT(NONE | ALWAYS | ONCE | AUTO) controls whether Db2 reoptimizes with host-variable values. OPTHINT names a package-level hint. PLANMGMT(OFF | BASIC | EXTENDED) keeps previous and original copies for SWITCH on REBIND. APREUSE / APCOMPARE reuse or compare access paths. Round out production binds with ENCODING, IMMEDWRITE, CONCURRENTACCESSRESOLUTION, and KEEPDYNAMIC as your shop standard requires.
BIND QUERY is not for COBOL DBRMs. It reads every row of DSN_USERQUERY_TABLE (statement text, default schema, bind options) plus correlated EXPLAIN / PLAN_TABLE hint rows. With LOOKUP(NO) (default), Db2 inserts SYSIBM.SYSQUERY, SYSQUERYPLAN, and SYSQUERYOPTS. That is how statement-level access path hints become catalog objects other packages can pick up.LOOKUP(YES) searches for matching catalog rows and reports DSNT280I/DSNT281I without inserting.
123456DSN SYSTEM(DB2A) BIND QUERY END /* or */ BIND QUERY LOOKUP(YES) BIND QUERY LOOKUP(NO) EXPLAININPUTSCHEMA(MYSCHEMA)
BIND QUERY is one of the DSN subcommands that does not run under DB2I the same way as BIND PACKAGE; it is typically batch DSN. You need the authority to insert those catalog rows (SYSADM or the documented bind-query privileges for your release). FREE QUERY removes the rows later.
BIND SERVICE builds the package that implements a native REST service: one static SQL statement (SELECT, INSERT, UPDATE, DELETE, TRUNCATE, CALL, or WITH) invoked over HTTP(S) through DDF. Db2 records the service in SYSIBM.DSNSERVICE. After bind, that package is executed as a service, not as a normal application CALL.
12345BIND SERVICE(PAYROLL) NAME(getEmp) - SQLDDNAME(SQLIN) - DESCRIPTION('Employee by empno') - OWNER(PAYBIND) QUALIFIER(HR) - ISOLATION(CS) APPLCOMPAT(V12R1M500)
Options NAME, DESCRIPTION, VERSION, SQLDDNAME, and SQLENCODING are service-specific. Other bind options match BIND PACKAGE (ISOLATION, QUALIFIER, APPLCOMPAT, and so on). The createService REST API is an alternative to the DSN subcommand. You must be able to execute the embedded SQL and to bind into the collection. FREE SERVICE drops the active REST package; FREE PACKAGE with PLANMGMTSCOPE(INACTIVE) can still drop inactive copies.
A DBRM is a recipe card the precompiler wrote. BIND PACKAGE is the kitchen cooking that card into a labeled frozen meal (the package) and putting it on a shelf (the collection). BIND PLAN is the dinner ticket that lists which shelves the waiter may take meals from. BIND QUERY is pinning a sticky note on one recipe that says “always use this oven setting.” BIND SERVICE is wrapping one meal so a web app can order it by scanning a QR code (HTTP) instead of sitting in the dining room (COBOL).
1. What does BIND PACKAGE do?
2. Why is MEMBER on BIND PLAN deprecated?
3. What does BIND QUERY read?
4. What does BIND SERVICE create?
5. Which privilege is typically required to ADD a new package?