Bind a COBOL DB2 Program End to End

Binding a COBOL DB2 program connects the load module you run to the package Db2 executes. This tutorial covers the full chain: DBRM from precompile, BIND PACKAGE, plan PKLIST, verification, and the consistency errors that appear when any link in that chain is rebuilt alone.

Hands-on COBOL bind
Progress0 of 0 lessons

The COBOL Db2 bind pipeline

A COBOL program with EXEC SQL does not talk to Db2 merely because it compiled. The SQL must be extracted, bound, and reachable through an application plan. Treat the following stages as one release unit.

Artifacts produced at each stage
StagePrimary output
Precompile / SQL statement processorModified COBOL source + DBRM member
COBOL compileObject module with Db2 call stubs
Link-editExecutable load module in application loadlib
BIND PACKAGEPackage in a collection with access paths
BIND PLAN (as needed)Plan PKLIST pointing at the collection

The consistency token stamped into the DBRM and load module is how Db2 proves that the running program matches the bound package. If you promote a new load module without the matching package, or bind an old DBRM against a new load module, runtime SQL fails even when every JCL step reports return code zero in isolation.

Prerequisites

COBOL bind readiness checks
AreaWhat to verify
SourceCOBOL program with embedded SQL that precompiles cleanly for the target Db2 level.
LibrariesDBRM library, object library, load library, and Db2 SDSNEXIT/SDSNLOAD concatenations.
NamesAgreed program, collection, plan, OWNER, and QUALIFIER naming standards.
AuthorityBINDADD/BIND plus object privileges required for VALIDATE(BIND).
ObjectsTables, views, and indexes referenced by the SQL exist in the QUALIFIER schema.

Include DCLGEN or equivalent host declarations when the shop standard requires them. Confirm APPLCOMPAT and SQL level expectations for new syntax. For promotion pipelines, identify whether test and production use different collections with the same plan name pattern or different plans entirely.

Steps: bind the COBOL program

1. Precompile and build the load module

Run the Db2 precompiler or SQL statement coprocessor so the DBRM member is written to the DBRM library and the modified COBOL source is ready to compile. Compile and link-edit into the application load library. Do not discard the DBRM after a successful compile; bind needs that exact member.

2. BIND PACKAGE for the DBRM

Bind the program DBRM into the target collection. Keep OWNER, QUALIFIER, ISOLATION, and VALIDATE aligned with shop standards.

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//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 /*

3. BIND PLAN with PKLIST when needed

If the plan already lists TRAINCOLL.*, a package replace is usually enough. For a new collection or first-time plan, bind or rebind the plan explicitly:

jcl
1
2
3
4
5
6
7
8
9
10
11
12
13
//BINDPLN EXEC PGM=IKJEFT01,DYNAMNBR=20 //STEPLIB DD DISP=SHR,DSN=DSN.V12R1M0.SDSNEXIT // DD DISP=SHR,DSN=DSN.V12R1M0.SDSNLOAD //SYSTSPRT DD SYSOUT=* //SYSTSIN DD * DSN SYSTEM(DB2T) BIND PLAN(TRAINPLN) - PKLIST(TRAINCOLL.*) - ACTION(REPLACE) - ISOLATION(CS) - RETAIN END /*

RETAIN preserves existing plan authorizations when your shop uses that option. Some sites bind package and plan in one SYSTSIN stream; others separate them for clearer promotion control. Either approach is fine when the final catalog state is correct.

4. Document the release set

Record program name, DBRM member, collection, package version if used, plan name, bind job name, and load library dataset. That checklist is the fastest way to diagnose -805 and -818 later.

Verify results

  • Confirm BIND PACKAGE and BIND PLAN return codes and message text.
  • Query SYSIBM.SYSPACKAGE for the collection and member name; note BINDTIME and VALID.
  • Confirm the plan lists the collection in SYSIBM.SYSPACKLIST or local reports.
  • Run a smoke test through the intended attachment (batch DSN RUN, CICS, or TSO) and check SQLCODE after the first SQL statement.
  • If EXPLAIN(YES) was specified, review access paths for the critical statements before promoting to production.
sql
1
2
3
4
5
6
7
8
9
SELECT COLLID, NAME, VERSION, OWNER, QUALIFIER, BINDTIME, VALID FROM SYSIBM.SYSPACKAGE WHERE COLLID = 'TRAINCOLL' AND NAME = 'EMPRPT01'; SELECT PLANNAME, LOCATION, COLLID, NAME FROM SYSIBM.SYSPACKLIST WHERE PLANNAME = 'TRAINPLN' ORDER BY SEQNO;

Common errors

Frequent COBOL bind and first-run failures
SymptomLikely causeCorrective action
Precompile SQL errorsInvalid SQL, missing DECLARE TABLE, or unsupported syntax for APPLCOMPATFix the SQL, regenerate DCLGEN if needed, and re-precompile before bind.
Bind authorization failureMissing BINDADD/BIND or OWNER lacks privileges on referenced objectsAlign OWNER/QUALIFIER with granted roles and retry with the correct ID.
SQLCODE -805 at first runPlan PKLIST missing the collection or wrong package set/versionInspect SYSPACKLIST/SYSPACKAGE and REBIND PLAN with the correct PKLIST.
SQLCODE -818 at first runLoad module and bound DBRM came from different precompilesRebuild the full chain from one precompile and rebind that DBRM.
Unexpected tablespace scanStale statistics or missing index when the package was boundRUNSTATS, review EXPLAIN, then REBIND PACKAGE with approved options.

Also watch for QUALIFIER mistakes that bind successfully against the wrong schema. VALIDATE(BIND) catches missing objects in the intended qualifier, but it cannot stop you from intentionally pointing at an incorrect yet existing schema. Review QUALIFIER in the bind skeleton as carefully as MEMBER.

Explain It Like I'm Five

Your COBOL program is a robot with a shopping list of Db2 questions. Precompile copies the shopping list onto a special paper (the DBRM). Binding is when Db2 reads that paper, decides the fastest aisles to walk, and files the finished plan in a binder. Running the robot only works when the robot you start is the same one that wrote that paper, and when the classroom plan says it may open that binder.

Exercises

  1. Draw the artifact flow from COBOL source to runnable batch step for program PAYRPT01.
  2. Write BIND PACKAGE and BIND PLAN commands for collection PAYCOLL and plan PAYPLAN.
  3. Explain the difference between replacing one package and rebinding an entire plan MEMBER list of twenty DBRMs.
  4. Given SQLCODE -818, list the three artifacts that must share one precompile generation.
  5. Write catalog queries you would use to prove a package is present and listed on a plan.

Quiz

Test Your Knowledge

1. What artifact from COBOL precompile does BIND PACKAGE consume?

  • Only the COBOL listing
  • The DBRM that contains the program static SQL and consistency token
  • Only the SYSIN JCL
  • A tablespace image copy

2. Why prefer package-plus-plan over binding every DBRM directly into one plan?

  • Plans are obsolete in all shops
  • A single program change can be rebound as one package without reprocessing every other DBRM in a large plan
  • Packages remove the need for STEPLIB
  • Packages disable authorization checking

3. Which BIND PLAN option associates packages with the plan?

  • PKLIST
  • FREEPAGE
  • MAXPARTITIONS
  • COPYDDN

4. SQLCODE -818 after a COBOL change usually means:

  • The table is in COPY pending
  • The load-module precompiler timestamp does not match the DBRM used for bind
  • SPUFI AUTOCOMMIT is NO
  • The CICS region is stopped

5. What should you verify after a successful bind return code?

  • Only that the job produced SYSOUT
  • Package and plan catalog rows, PKLIST coverage, and a controlled program smoke test
  • Only that SDSF shows RC=0
  • Only that the COBOL compile had no warnings

Frequently Asked Questions