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

Module 9: DB2 COBOL Programming


DB2 Precompiler

The DB2 precompiler is the first step in building a COBOL DB2 program. It scans the COBOL source, extracts every SQL statement, and produces two outputs: a modified COBOL source the compiler can digest, and a DBRM for the bind step.

What the DB2 precompiler does

  • The precompiler (program DSNHPC) reads the COBOL source and finds all EXEC SQL ... END-EXEC blocks.
  • It copies every SQL statement into the DBRM (Database Request Module), which later becomes input to the BIND process.
  • It replaces each SQL block in the source with a CALL to the DB2 language interface module, passing a parameter list that identifies the SQL statement.
  • It expands EXEC SQL INCLUDE statements, pulling the SQLCA and DCLGEN copybooks into the source.
  • The output, called the modified source, is ordinary COBOL with no SQL left in it - ready for the COBOL compiler.

Precompiler inputs and options

  • Input: the COBOL source with embedded SQL (SYSIN), plus the libraries holding INCLUDE members.
  • Key PARM option: HOST(COB2) tells the precompiler the host language is Enterprise COBOL. Use APOST or QUOTE to match the program's string delimiter.
  • Outputs: SYSCIN (modified source, passed to the COBOL compile step) and the DBRM member in the DBRM library.
  • Return code 0 means clean; return code 4 means warnings; return code 8 or higher means errors - do not compile further until they are fixed.

How the precompiler fits the build

  • Order of steps in the build JCL: precompile, then COBOL compile, then link-edit, then BIND, then RUN.
  • If the program also uses CICS, the CICS translator runs before the DB2 precompiler.
  • Never hand-edit the modified source: always fix the original source and re-run the precompiler.

Example of a precompile JCL step:-

//PRECOMP EXEC PGM=DSNHPC, // PARM='HOST(COB2),SOURCE,APOST' //SYSIN DD DSN=MYID.COBOL.SRC(PROG1),DISP=SHR //DBRMLIB DD DSN=MYID.DBRM.LIB(PROG1),DISP=SHR //SYSCIN DD DSN=&&TEMPOUT,DISP=(NEW,PASS), // DCB=(RECFM=FB,LRECL=80,BLKSIZE=800) //SYSPRINT DD SYSOUT=* //SYSTERM DD SYSOUT=*





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant