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

Module 9: DB2 COBOL Programming


DB2 COBOL Compile Process

A COBOL DB2 program becomes executable in five stages: precompile, COBOL compile, link-edit, bind, and run. Miss a stage or run them in the wrong order and the program will not work. The diagram below shows the full flow.

The five stages

  • 1. Precompile (DSNHPC): extracts the SQL into a DBRM and replaces it with CALL statements, producing the modified COBOL source.
  • 2. COBOL compile (IGYCRCTL): compiles the modified source into an object module. The compiler never sees SQL.
  • 3. Link-edit (IEWL): links the object module with the DB2 language interface module (DSNELI/DSNULI) into a load module.
  • 4. Bind: reads the DBRM, validates against the catalog, optimizes, and stores the access path in a plan or package.
  • 5. Run: the load module executes; its CALL statements reach DB2, which runs the bound SQL from the plan.

Typical build JCL layout

  • One job with four steps in order: PRE (DSNHPC), COB (IGYCRCTL), LKED (IEWL), BIND (IKJEFT01 with DSN).
  • Temporary datasets (&&) pass the modified source and object module between steps.
  • The RUN step (IKJEFT01 with DSN RUN PROGRAM(...) PLAN(...)) executes the finished load module.
  • Check the return code of every step: 0 is clean, 4 is warnings, 8 or more means errors - do not continue past errors.

Why the order matters

  • Compiling before precompiling fails: the COBOL compiler cannot parse EXEC SQL blocks.
  • Binding before compiling works, but rebinding is still required after every recompile because the DBRM timestamp changes.
  • Linking without the DB2 interface module gives unresolved references at link time.

Example of a full DB2 COBOL build JCL (precompile, compile, link):-

//DB2COB JOB (ACCT),'DB2 BUILD',CLASS=A,MSGCLASS=X //PRE EXEC PGM=DSNHPC,PARM='HOST(COB2),SOURCE,APOST' //SYSIN DD DSN=MYID.SRC.COBOL(PROG1),DISP=SHR //DBRMLIB DD DSN=MYID.DBRM.LIB(PROG1),DISP=SHR //SYSCIN DD DSN=&&COBSRC,DISP=(NEW,PASS), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800) //SYSPRINT DD SYSOUT=* //COB EXEC PGM=IGYCRCTL,PARM='LIB,APOST,OBJECT' //SYSIN DD DSN=&&COBSRC,DISP=(OLD,DELETE) //SYSLIN DD DSN=&&LOADSET,DISP=(NEW,PASS) //SYSPRINT DD SYSOUT=* //LKED EXEC PGM=IEWL,PARM='LIST,XREF' //SYSLIN DD DSN=&&LOADSET,DISP=(OLD,DELETE) // DD DDNAME=SYSIN //SYSLMOD DD DSN=MYID.LOAD.LIB(PROG1),DISP=SHR //SYSIN DD * INCLUDE SYSLIB(DSNELI) NAME PROG1(R) /*





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant