Showing posts with label Db2 plan. Show all posts
Showing posts with label Db2 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.

Saturday, 17 August 2013

Db2 Packages Guide for COBOL Static SQL


Db2 package flow showing COBOL embedded SQL, DBRM, BIND PACKAGE, package, plan, and REBIND
Db2 packages hold prepared SQL and access paths.

A COBOL program with static SQL does not carry its access path inside the load module. During precompile, Db2 extracts embedded SQL into a DBRM. During bind, Db2 turns that DBRM into a package that records prepared SQL, bind options, authorization context, and the access path chosen for the SQL statements.

This refresh replaces the old C-oriented explanation with a Db2 for z/OS package guide for COBOL teams. It covers DBRMs, collections, packages, plans, BIND PACKAGE, REBIND, and the checks developers should make before promoting a static SQL change.

What Is a Db2 Package?

A Db2 package is a database object that contains the prepared form of static SQL statements from one program or routine. IBM's BIND PACKAGE documentation says the subcommand builds an application package, records the package description in catalog tables, and saves the prepared package in the directory.

For a COBOL application, the package is the Db2-side partner to the compiled and linked load module. If the load module and package do not match the same SQL level, the program can fail or run with the wrong assumptions.

COBOL Static SQL Build Flow

The build path matters because each output has a different job. The COBOL compiler handles host language code. Db2 handles embedded SQL through the DBRM and bind process.

Step Output Why it matters
Precompile Modified COBOL source and DBRM Separates SQL from COBOL source.
Compile and link-edit Load module Creates executable program code.
BIND PACKAGE Package in a collection Prepares static SQL and records access paths.
BIND PLAN or package list Runtime plan reference Connects run unit to packages.

DBRM, Package, Collection, and Plan

These four terms often get mixed together in incident calls. Keep them separate.

Term Meaning Common problem
DBRM Database request module created by precompile. Wrong DBRM library used during bind.
Package Bound SQL from a DBRM or copied package. Package not rebound after SQL or statistics change.
Collection Named group that contains packages. Runtime points to the wrong collection.
Plan Runtime object that can include a package list. Plan does not include the expected package collection.

BIND PACKAGE Example

Site JCL and options vary, but a package bind normally identifies the collection, DBRM member, action, owner or qualifier options, isolation level, and validation behavior.

BIND PACKAGE(ACCTCOLL) -
     MEMBER(ACCTPOST) -
     ACTION(REPLACE) -
     QUALIFIER(ACCT) -
     ISOLATION(CS) -
     VALIDATE(BIND) -
     EXPLAIN(YES)

Do not copy bind options blindly. ISOLATION(UR), RELEASE(DEALLOCATE), VALIDATE(RUN), and REOPT can be correct in one workload and wrong in another. Use the site standard unless there is a documented reason to deviate.

Package and Access Path

For static SQL, the access path is selected at bind or rebind time. That is why a COBOL program can slow down after a package rebind even when source code did not change. New RUNSTATS, index changes, subsystem function level, bind options, and SQL changes can all affect the path.

  • Capture EXPLAIN output when binding important packages.
  • Record the DBRM library, collection, package, and version used in the change.
  • Compare access paths before and after a rebind for high-volume programs.
  • Know the rollback option if the new package performs badly.

The related Db2 SQL Optimization Tips for COBOL Programs article covers access-path investigation in more detail.

REBIND PACKAGE

A rebind rebuilds an existing package using the current environment and selected options. It is common after RUNSTATS, index changes, SQL compatibility changes, or package maintenance. Rebind is powerful because it can improve performance without changing COBOL source, but it can also choose a worse path if statistics or options are wrong.

REBIND PACKAGE(ACCTCOLL.ACCTPOST) -
       APREUSE(WARN) -
       EXPLAIN(YES)

For production packages, make the rebind visible in the change record. Include package name, collection, owner, bind options, reason, expected benefit, and fallback plan.

Common Package Problems

Symptom Likely package issue Check
Program works in test but fails in production. Different collection or missing package. Plan PKLIST, collection, package name, and version.
SQL starts running slowly after maintenance. Access path changed during rebind. EXPLAIN before/after and RUNSTATS timing.
Authorization error appears at bind or run time. Owner or VALIDATE option mismatch. Package owner, binder authority, and object grants.
Old load module calls new SQL package. Promotion mismatch. Load library, DBRM, package timestamp, and change ticket.

Developer Checklist

  • Confirm the DBRM was generated from the same source level as the load module.
  • Confirm the package collection used by the runtime plan.
  • Review bind options with the DBA for high-volume programs.
  • Use EXPLAIN for SQL that can affect batch windows or online response time.
  • Keep package rollback details in the implementation plan.
  • Coordinate package changes with related DB2 Binding and Rebinding procedures.

FAQ

Is a Db2 package the same as a plan?

No. A package contains prepared SQL for a program or routine. A plan is a runtime object that can reference packages through a package list.

When should a package be rebound?

Rebind after relevant SQL, index, statistics, compatibility, or bind-option changes. For critical packages, compare access paths before and after the rebind.

Can a COBOL program run without its package?

No, static SQL needs the corresponding package or plan/package setup at runtime. The load module and Db2 package must be promoted together.

Package work is successful when the COBOL load module, DBRM, package collection, bind options, and access path all line up. Treat the package as part of the application deliverable, not an afterthought.

New In-feed ads