Showing posts with label BIND PLAN. Show all posts
Showing posts with label BIND PLAN. Show all posts

Saturday, 24 August 2013

Db2 Application Environment: COBOL, DBRM, Package, Plan, and Runtime Flow



Last updated: July 2026

A COBOL program with embedded SQL does not run against Db2 just because the source compiled. The program must pass through precompile, compile, link-edit, bind, execution JCL, runtime libraries, and SQL return-code checks. A missing package, a wrong collection, or a stale plan can stop the job before the first business record is processed.

The Db2 application environment is the set of source members, DBRMs, packages, plans, load modules, subsystem settings, libraries, and runtime checks that let an application program use Db2 safely on z/OS.

Db2 application environment flow from COBOL source to precompile, compile link, bind, and runtime
Build and bind before the program runs.

What belongs in a Db2 application environment

For a Db2 for z/OS application, the environment usually includes developer source libraries, precompile output, DBRM libraries, load libraries, bind jobs, package collections, plans, runtime JCL, and operational logging. The exact names vary by shop, but the responsibilities are similar.

PartPurposeWhat to verify
COBOL sourceContains embedded SQL inside EXEC SQL and END-EXEC.Host variables, copybooks, SQLCA include, and indicator variables are correct.
Precompile stepSeparates SQL from COBOL and creates a DBRM.DBRM member name, SQL syntax, and precompiler options match the application standard.
Compile and link-editBuilds the executable load module.Correct compiler options, copybook libraries, and Db2 interface modules are available.
Bind package or planCreates the executable SQL control structure used by Db2.Collection, owner, qualifier, isolation, validation timing, and package/plan name are right.
Runtime JCL or online regionRuns the program under batch, CICS, IMS, or another execution path.Subsystem, libraries, plan or package reference, and error logging are correct.
SQLCA handlingReports SQL execution results back to the program.Program checks SQLCODE, SQLSTATE, warning flags, and row counts where needed.

Batch COBOL Db2 flow

A common batch flow starts with a COBOL source member, runs a Db2 precompile, compiles the modified COBOL, link-edits the load module, binds the DBRM into a package or plan, and executes the program through JCL. If one of those artifacts is out of sync, production can fail with package-not-found, authorization, or access-path problems.

//BINDPKG  EXEC PGM=IKJEFT01
//SYSTSPRT DD SYSOUT=*
//SYSTSIN  DD *
  DSN SYSTEM(DB2P)
  BIND PACKAGE(APP1COLL) -
       MEMBER(ACCTUPD) -
       ACTION(REPLACE) -
       ISOLATION(CS) -
       VALIDATE(BIND)
  END
/*

The bind job is not just a build step. It decides where Db2 will look for objects, which collection holds the package, when object checks happen, and what access path Db2 records for static SQL.

Online application paths

Batch is not the only application path. CICS and IMS programs can also call Db2, but the runtime setup is different. CICS needs the correct Db2 connection setup, transaction definition, program definition, and plan or package access. IMS regions need the correct dependent-region and Db2 attachment configuration.

For support work, the practical question is simple: which subsystem did the program connect to, which plan or package did it use, and what SQL return code came back?

Development, test, and production separation

Most shops keep separate Db2 subsystems or schemas for development, test, and production. The program name can stay the same while the collection, qualifier, or subsystem changes by environment. That is useful, but it also creates easy mistakes.

  • A test package might be rebound while production still uses an old access path.
  • A job might point to the wrong subsystem after a JCL copy.
  • A package collection might contain the right member name but the wrong version.
  • A static SQL change might be compiled but not bound.

Runtime checks inside the program

The application environment is incomplete without runtime validation. A program should include SQLCA handling and should check the SQL result close to the statement that produced it.

EXEC SQL
   INCLUDE SQLCA
END-EXEC.

EXEC SQL
   SELECT ACCT_STATUS
     INTO :WS-ACCT-STATUS
     FROM ACCOUNT
    WHERE ACCT_NO = :WS-ACCT-NO
END-EXEC.

EVALUATE SQLCODE
   WHEN 0
      PERFORM PROCESS-ACCOUNT
   WHEN +100
      PERFORM HANDLE-NOT-FOUND
   WHEN OTHER
      PERFORM WRITE-DB2-ERROR
      PERFORM ROLLBACK-WORK
END-EVALUATE.

That small check prevents a program from treating a missing row as a valid business result. For data-change SQL, add row-count checks when the program expects exactly one row or a known number of rows.

Common failure points

DBRM and load module are not from the same source level

This often happens when a compile runs but the bind step is missed. The load module contains the latest logic, while Db2 still executes SQL based on an older package.

Wrong collection or plan

A job can run the correct program and still use the wrong package collection. Check the bind cards, run JCL, and runtime messages together.

Authorization missing at bind or run time

Bind authorization and execution authorization are separate concerns. A developer may be able to compile a program but not bind or run against a protected table.

SQL warnings ignored

Warnings can indicate truncation or null-handling problems. Treat warning flags as part of the application contract, not as decoration.

Checklist before moving to production

  • Confirm the source, DBRM, load module, package, and plan names match the release package.
  • Confirm the bind ran in the correct Db2 subsystem with the intended collection and qualifier.
  • Confirm runtime JCL or online definitions point to the expected subsystem and libraries.
  • Confirm SQLCA handling logs SQLCODE, SQLSTATE, message tokens, program name, and business keys.
  • Confirm restart or rollback behavior for failed updates in batch jobs.

Related Db2 topics

Use this guide with Db2 Binding Application, Db2 Binding and Rebinding, Db2 Packages, Db2 SQL Execution Validation, and Db2 SQLCODE and SQLSTATE.

FAQ

What is a Db2 application environment?

It is the set of build, bind, runtime, and support components that allow an application program to execute SQL against Db2, including source, DBRM, package or plan, load module, subsystem, JCL, and SQLCA handling.

Why does a COBOL Db2 program need precompile and bind?

The precompile step extracts embedded SQL and creates a DBRM. The bind step turns that DBRM into executable SQL control information that Db2 can use at runtime.

What should be checked when a Db2 program fails in production?

Check the subsystem, package collection, plan, load library, bind timestamp, SQLCODE, SQLSTATE, message tokens, and the business key being processed when the failure occurred.

Db2 Directory Guide: SPT01, SCT02, DBD01, SYSLGRNX, and SYSUTILX


Db2 directory guide showing SPT01 SCT02 DBD01 SYSLGRNX and SYSUTILX internal control data
Db2 manages the directory internally.

A Db2 package can be present in the catalog and still fail at execution time if the internal execution structures are damaged, unavailable, or out of sync. When recovery, bind, or utility processing is involved, Db2 uses directory objects that normal application SQL does not query.

The Db2 directory stores internal control information used by Db2 for operation, package and plan execution, database descriptors, log range tracking, and utility restart. Unlike the catalog, the directory is not a normal SQL reporting source. Db2 and supported utilities maintain it.

What the Db2 directory does

The directory supports Db2 execution and recovery work that must be fast and controlled. It stores internal forms of packages and plans, database descriptors, log ranges used for recovery, and utility status needed for restart. Developers usually learn about it when a bind, run, utility, or recovery problem points below normal catalog metadata.

Directory versus catalog

AreaPurposeNormal access
Db2 catalogStores queryable metadata about objects, privileges, packages, plans, routines, and statistics.Read with SQL when authorized.
Db2 directoryStores internal control data used by Db2 for execution, recovery, utility restart, and package or plan processing.Managed by Db2 and supported utilities, not normal application SQL.

Important Db2 directory objects

Directory objectWhat it supportsWhy it matters
SPT01Skeleton package table, often called SKPT.Contains internal package information and access-path data created by BIND PACKAGE and removed by FREE PACKAGE.
SCT02Skeleton cursor table, often called SKCT.Contains internal plan information and access-path data created by BIND PLAN and removed by FREE PLAN.
DBD01Database descriptors.Stores internal database descriptor information for table spaces, indexes, tables, constraints, and related structures.
SYSLGRNXLog range tracking.Helps Db2 locate log ranges needed for recovery of updated table spaces or partitions.
SYSUTILXUtility execution and restart state.Stores utility status so Db2 can restart, recover, or terminate utility work correctly.

How directory objects show up in support work

Package or plan execution

When a static SQL program runs, Db2 uses package or plan structures created at bind time. Catalog rows help you identify the package, collection, and validity, but execution also depends on internal structures in the directory. If a bind or free operation fails, support teams often check both catalog state and Db2 messages tied to directory processing.

Recovery and log ranges

SYSLGRNX helps Db2 find the log ranges needed for recovery. If an object has been updated, Db2 can use recorded ranges instead of searching all log data blindly. This matters during RECOVER, restart, and problem diagnosis after an outage.

Utility restart

SYSUTILX is involved when utilities such as REORG, LOAD, COPY, or RECOVER need restart or cleanup handling. If a utility stops, do not delete anything by hand. Use supported commands such as -DISPLAY UTILITY, restart procedures, or -TERM UTILITY only when site rules allow it.

-DISPLAY UTILITY(*)
-TERM UTILITY(utility-id)

Safe handling rules

  • Do not update or delete Db2 directory data manually.
  • Use supported Db2 commands, bind actions, utilities, and recovery procedures.
  • Check the catalog first when the question is about object names, package names, privileges, or statistics.
  • Check Db2 messages, utility output, and recovery documentation when the problem points to directory-managed state.
  • Escalate directory damage, utility restart confusion, or recovery inconsistencies to the DBA or systems programmer team.

Common mistakes

Treating the directory like catalog tables

The catalog is meant to be queried for metadata. The directory is internal. Treating both as ordinary application data is a support risk.

Terminating utilities without restart context

A utility entry can represent recoverable work. Capture the utility ID, phase, object name, and messages before taking action.

Looking only at package catalog rows

Package catalog rows help identify the package, but a runtime issue may also involve bind output, plan references, load libraries, directory-managed structures, or subsystem messages.

Related Db2 topics

Use this guide with Db2 Catalog, Db2 Packages, Db2 Utilities, Db2 Commands Quick Reference, and Db2 Binding and Rebinding.

FAQ

What is the Db2 directory?

The Db2 directory stores internal control information used by Db2 for package and plan execution, database descriptors, log range tracking, utility restart, and recovery processing.

Can I query the Db2 directory with SQL?

No for normal application or support work. The catalog is the SQL-queryable metadata source. The directory is maintained by Db2 and supported utilities.

What is SYSUTILX used for?

SYSUTILX stores Db2 utility execution and restart information. It helps Db2 restart or clean up utility work after interruption.

Saturday, 17 August 2013

Db2 Binding an Application: COBOL DBRM, Package, Plan, and Run JCL


Db2 application bind checklist from COBOL source to DBRM package plan and run JCL
Bind the DBRM before the program runs.

A COBOL program with embedded SQL does not run against Db2 just because the load module was created. The SQL has to be precompiled into a DBRM, the program has to be compiled and link-edited, and Db2 must have a package or plan that matches what the program calls at run time.

That is the point of application binding. It connects the program's static SQL to Db2 access paths before the batch job, CICS transaction, or IMS program reaches production.

Where binding fits in the COBOL build

A typical static SQL build has four moving parts. If one of them is missing or from the wrong compile, the job can fail even when the COBOL source looks correct.

Build part What it creates Why it matters
Db2 precompile Modified COBOL source and a DBRM member The DBRM contains the static SQL that Db2 will bind.
COBOL compile Object module The embedded SQL calls have already been replaced with host-language calls.
Link-edit Executable load module The load module calls the Db2 language interface at run time.
Bind Package and plan entries in Db2 Db2 stores executable forms of the SQL statements and the selected access paths.

Precompile creates the DBRM

The Db2 precompiler reads the COBOL source and finds each EXEC SQL block. It checks SQL syntax, handles host variable references, includes members such as SQLCA or DCLGEN copybooks when requested, and writes a DBRM member to a partitioned data set.

The DBRM is not the same as the COBOL object module. It is the Db2-side input for binding. In many shops the member name matches the program name, such as PAYRPT01, because that makes the bind JCL and promotion controls easier to audit.

//PC.SYSIN    DD  DSN=APP.SOURCE(PAYRPT01),DISP=SHR
//PC.SYSCIN   DD  DSN=APP.WORK.COBOL(PAYRPT01),DISP=SHR
//PC.DBRMLIB  DD  DSN=APP.DBRMLIB(PAYRPT01),DISP=SHR

Bind the package from the DBRM

For most production applications, bind the DBRM as a package and include the package in a plan. A package keeps the bind unit close to one program module, so a change to one COBOL program does not force every related DBRM in a large plan to be rebound.

BIND PACKAGE(APP01)
  MEMBER(PAYRPT01)
  ACTION(REPLACE)
  ISOLATION(CS)
  CURRENTDATA(NO)
  QUALIFIER(PROD)

The exact bind options depend on the shop standard and workload. For example, a read-only reporting program may use different lock and isolation choices from an update program that posts end-of-day financial rows. Do not copy a bind card from another application without checking the program's SQL behavior.

Bind the plan used by run JCL

The application plan tells the run command which packages can be used. A common pattern is to bind packages into a collection and then bind a plan with a package list.

BIND PLAN(PAYPLAN)
  PKLIST(APP01.PAYRPT01)
  ACTION(REPLACE)

Some sites use a wildcard package list such as APP01.* for a controlled collection. That can reduce plan maintenance, but it should still be managed by promotion rules so test packages do not accidentally become callable from production jobs.

Run JCL must point to the right plan

After compile, link-edit, package bind, and plan bind, the batch job still has to call the expected plan. A typical DSN run step names the Db2 subsystem, program, plan, and application load library.

//RUNSQL  EXEC PGM=IKJEFT01
//STEPLIB DD  DSN=DSN.V12.SDSNLOAD,DISP=SHR
//SYSTSIN DD  *
  DSN SYSTEM(DSN1)
  RUN PROGRAM(PAYRPT01) PLAN(PAYPLAN) -
      LIB('APP.PROD.LOADLIB')
  END
/*
//SYSPRINT DD SYSOUT=*

If the run step names an old plan, a test collection, or the wrong load library, the program may call a package that does not match the current DBRM. That is why a release checklist should compare the load module, DBRM member, package bind, plan bind, and run JCL before the job is released.

Common bind failures and runtime clues

Binding problems usually show up in the bind output, Db2 messages, or SQLCODE returned to the program. The exact message text matters, so always check the Db2 output from the failing job before changing bind options.

Symptom Likely area to check
Bind fails because a table or view cannot be found Check the qualifier, owner, current environment, and whether the object exists in that subsystem.
Bind fails because the user is not authorized Check package, plan, table, view, and execute privileges for the bind owner.
Runtime SQLCODE points to package not found Check package collection, plan package list, subsystem, and whether the package was promoted.
Runtime SQLCODE points to timestamp or consistency mismatch Check whether the load module and DBRM/package came from the same precompile.

Application bind checklist

  • Use the DBRM created from the same source version that produced the load module.
  • Keep DBRM library, load library, package collection, and plan name visible in promotion records.
  • Bind changed programs as packages instead of rebinding a large plan directly from many DBRMs.
  • Review QUALIFIER, OWNER, VALIDATE, isolation, and current data options against the application type.
  • Confirm the run JCL names the intended plan and load library before moving the job to production.

Related DB2 topics

Application binding sits close to several other Db2 topics. Review Db2 Binding and Rebinding for package and plan maintenance, Db2 Packages for package structure, Db2 Objects for database object context, and Db2 SQL Optimization Tips for COBOL Programs for access path review.

FAQ

Is a DBRM the same as a package?

No. The DBRM is produced by the precompile step. A package is created when Db2 binds that DBRM into the catalog and directory.

Can a COBOL Db2 program run without a bind?

A static SQL COBOL program needs a valid package or plan before it can run successfully against Db2. Dynamic SQL follows a different prepare path at run time.

Why does a program fail after a successful compile?

The compile only proves the host language build completed. The run can still fail if the DBRM was not bound, the plan does not include the package, or the load module and package do not match.

For production, treat bind output as part of the build evidence. A clean compile without the matching DBRM, package, plan, and run JCL is not enough.

DB2 BIND and REBIND: What They Do and When to Run Each


Db2 bind and rebind flow showing COBOL source, DBRM, BIND PACKAGE, BIND PLAN, REBIND, and package set
Binding turns static SQL into a runnable package.

A COBOL program with embedded SQL does not become runnable after compile alone. The SQL is precompiled into a DBRM, bound into a package, connected to a plan or package list, and then used by the job, CICS transaction, or IMS program at runtime.

This refresh explains Db2 binding and rebinding for mainframe developers: what BIND does, why REBIND is used, how collections and package sets affect runtime lookup, and what to check before promoting a changed program.

Where Binding Fits in a COBOL Db2 Build

A typical static SQL build has these steps:

  1. Precompile the COBOL source and extract SQL into a DBRM.
  2. Compile the modified COBOL source.
  3. Link-edit the load module.
  4. Bind the DBRM into a package.
  5. Bind or use a plan that includes the package.

If the package is missing or the plan cannot find it, the program can compile cleanly and still fail at runtime.

What BIND PACKAGE Does

BIND PACKAGE takes a DBRM and creates a package. During bind, Db2 validates SQL, checks object names, checks authorization, and selects an access path for static SQL statements.

BIND PACKAGE(CERTCOL)
     MEMBER(CERTPGM)
     ACTION(REPLACE)
     ISOLATION(CS)
     OWNER(DB2USER1)
     QUALIFIER(DB2USER1)

The package becomes the stored form of the program's static SQL. The access path chosen at bind time can change when statistics, indexes, SQL text, or bind options change.

What BIND PLAN Does

A plan is the runtime object that lets an application execute Db2 SQL. Modern static SQL designs usually bind DBRMs into packages and then bind a plan that references package collections through PKLIST.

BIND PLAN(CERTPLAN)
     PKLIST(CERTCOL.*)
     ACTION(REPLACE)
     ISOLATION(CS)

Using package lists means packages can be added or replaced in a collection without rebinding the plan every time.

Collections and Package Names

A collection is a group of associated packages. A package name is commonly referenced as collection.package. The collection is implicitly created the first time a package is bound into that collection.

Collections are useful for separating environments or application versions. For example, test packages can use CERTCOL while production packages use a different collection name.

CURRENT PACKAGESET

The CURRENT PACKAGESET special register can direct package lookup to a specific collection for dynamic package resolution scenarios. Older applications sometimes use it to force package searches into a chosen collection.

EXEC SQL
    SET CURRENT PACKAGESET = 'CERTCOL'
END-EXEC.

Use this carefully. If the collection name is wrong, the application can fail even when the package exists somewhere else.

What REBIND Does

REBIND rebuilds an existing package or plan without changing the source program. It is commonly used after RUNSTATS, index changes, catalog changes, or Db2 maintenance when access paths need to be refreshed.

REBIND PACKAGE(CERTCOL.CERTPGM)

REBIND can change access paths. That is useful when statistics have improved, but risky when a critical batch job depends on a stable path. Review high-risk packages before rebinding in production.

BIND ADD, BIND REPLACE, and REBIND

ActionUse whenCommon risk
ACTION(ADD)Creating a new package or plan.Fails if the object already exists.
ACTION(REPLACE)Program SQL changed and the package must be replaced.Can replace the wrong collection member if naming is sloppy.
REBINDProgram did not change, but access path or bind options need refresh.Can change a stable access path after statistics or index changes.

Binding While a Package Is in Use

Packages and plans can be locked during execution and bind processing. A package or plan generally cannot be rebound while the same object is actively running. A different package version, however, can be bound depending on how versioning and collections are set up.

This is why batch windows and CICS availability matter. Rebinding a package used by a high-volume transaction is not the same as rebinding a rarely used report package.

Bind Options That Affect Programs

Bind options can affect runtime behavior. Some options control isolation, ownership, qualifier resolution, package lookup, and environment restrictions.

BIND PLAN(CICSONLY)
     PKLIST(CERTCOL.*)
     ACTION(REPLACE)
     ISOLATION(CS)
     OWNER(DB2USER1)
     QUALIFIER(DB2USER1)
     ENABLE(CICS)

These settings should be reviewed as deployment controls, not just DBA syntax.

Freeing or Dropping Packages

Use FREE to remove packages or plans from the catalog when they are no longer needed.

FREE PACKAGE(CERTCOL.*)

A package can also be removed with SQL in environments that support the statement and required authorization:

DROP PACKAGE DB2USER.DB2CERT

Do not remove a package just because a load module is old. Confirm runtime references, collection usage, and fallback needs first.

Promotion Checklist

  • Confirm the DBRM member matches the COBOL source level.
  • Bind into the correct collection.
  • Confirm the plan or package list can find the package.
  • Review changed access paths for high-volume SQL.
  • Check authorization for the bind owner and runtime auth ID.
  • Keep fallback package/version details for production rollout.

How Binding Relates to Packages

This article focuses on bind and rebind actions. For a wider explanation of package structure, collections, plans, DBRMs, and static SQL promotion, see Db2 Packages Guide for COBOL Static SQL.

For access-path checks after bind or rebind, see Db2 SQL Optimization Tips for COBOL Programs and Db2 Indexing.

FAQ

What is the difference between BIND and REBIND in Db2?

BIND creates or replaces a package or plan from DBRM input. REBIND rebuilds an existing package or plan, often to refresh access paths after statistics, index, or catalog changes.

Does REBIND require a COBOL program change?

No. REBIND is commonly used when the program did not change but Db2 should reconsider access paths or bind options.

Why do collections matter in Db2 packages?

A collection groups related packages and helps plans or package lookup find the correct package version at runtime.

Binding is not an afterthought after compile. It is the point where Db2 validates the SQL, checks authority, and chooses the access path your COBOL program will use.

New In-feed ads