Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 12: DBRM, Package, Plan and DB2 JCL


DB2 Compile and Bind Process

A DB2-COBOL program goes through more steps than a plain COBOL program: precompile, compile, link-edit, bind package, bind plan, and finally run.

The complete flow

  • 1. Source program - COBOL with EXEC SQL ... END-EXEC blocks and host variables.
  • 2. DB2 precompiler (DSNHPC) - extracts the SQL into a DBRM member and writes a modified COBOL source with the SQL replaced by CALLs.
  • 3. COBOL compiler - compiles the modified source into an object module.
  • 4. Link-editor - builds the load module and stamps it with the consistency token.
  • 5. BIND PACKAGE - binds the DBRM into a package in a collection. The optimizer picks access paths.
  • 6. BIND PLAN - binds the plan, pointing at the packages through PKLIST (or binds DBRMs directly).
  • 7. RUN - the program executes under the plan via IKJEFT01 and DSN RUN.

What happens at each step

  • The precompiler is the only step that understands SQL. Everything after it sees plain COBOL CALLs.
  • Compile and link-edit work exactly like a non-DB2 program, except the source they see is the precompiler's modified version.
  • BIND is the only step that talks to the DB2 catalog and directory. It validates objects, checks authorization and optimizes.
  • At RUN time DB2 matches the consistency token in the load module against the plan/package. A mismatch ends the program with -818.

Why the order matters

  • Bind after compile and link, so the consistency tokens in the load module and the package/plan are stamped from the same precompile.
  • After any change to the SQL, redo the full chain: precompile, compile, link, bind. Skipping a step is the classic cause of -818.
  • After RUNSTATS or index changes with no source change, a REBIND alone is enough. No recompile needed.
  • Never run a program whose load module timestamp differs from its plan or package.

Example: precompile to bind in one job

  • One job can chain the whole flow: precompile the source, then bind the package and the plan:
    //PCOMP EXEC PGM=DSNHPC,REGION=0M, // PARM='HOST(COBOL),SOURCE' //SYSIN DD DSN=USERID.SOURCE(PROG1),DISP=SHR //SYSCIN DD DSN=&&MODSRC,DISP=(NEW,PASS),SPACE=(TRK,(10,10,5)) //DBRMLIB DD DSN=USERID.DBRMLIB(PROG1),DISP=SHR //SYSTSPRT DD SYSOUT=* //* //BIND EXEC PGM=IKJEFT01,DYNAMNBR=20 //STEPLIB DD DSN=DB2A.SDSNLOAD,DISP=SHR //SYSTSPRT DD SYSOUT=* //SYSTSIN DD * DSN SYSTEM(DB2A) BIND PACKAGE (MYCOLL) MEMBER (PROG1) LIB ('USERID.DBRMLIB') ACTION (REPLACE) BIND PLAN (MYPLAN) PKLIST (MYCOLL.*) ACTION (REPLACE) RETAIN END /*





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant