Precompilation Process (COBOL + DB2 Program)


The precompilation process is the first step in compiling a COBOL + DB2 program. It involves the DB2 precompiler scanning the program to identify and process embedded SQL statements.

What is Precompilation Process?

When SQL statements are embedded within a COBOL program, a DB2 precompiler is used to extract and process SQL code. During precompilation, the SQL code is separated from the COBOL code and stored in a DBRM (Database Request Module), while the COBOL code is modified for later compilation.

DSNHPC (utilities belongs to the DSNHPC family) is used for the precompilation of COBOL + DB2 program.

Steps of Precompilation Process

The DB2 precompiler checks the program to identify embedded SQL and performs the following tasks:

  • Extract SQL Statements: SQL statements are extracted and stored in a Database Request Module (DBRM).
  • Replace SQL with COBOL Calls: Each embedded SQL code block is replaced with DB2 runtime API calls that connect to DB2 at execution time.
  • Generate Modified COBOL Source Code: A modified COBOL program (without SQL, but with DB2 runtime calls) is created for compilation.

The precompilation process -


The compilation process of the COBOL + DB2 program is different from the simple COBOL program compilation. If the program has DB2 statements, then we should add the precompiler step to the compilation JCL. i.e., the Precompilation JCL = Precompile step + COBOL Compile JCL.

Precompilation process

PRECOMPILER -

  • The precompiler takes the COBOL + DB2 source code as an input. It separates the COBOL and DB2 statements into two libraries (COBOL Loadlib and DBRM).
  • It is responsible for checking the syntax errors of DB2 statements before placing them in DBRM (DataBase Request Module).
  • It doesn't check the syntax errors of COBOL statements or any other programming language(PL/I, etc.) statements.
  • It generates timestamp tokens for both COBOL, which are validated while running the program.

Precompilation JCL -


Note! Below precompilation JCL works as it is when you change your project-specific utility libraries and LOAD, COPY, DCLGEN, and DBRM libraries.
Precompile JOB MAXCC

Precompilation Ways -


In the real-time environment, the precompilation process takes place in two ways -

  • Using Version Control tools like Endeavor, Changeman, etc: - If compiling a COBOL +DB2 program using a version control tool, the JCL also has the Bind step at the end to bind the program to the DB2 PLAN. i.e., Compilation JCL = Precompilation JCL + Bind Step.
  • Using a personal compilation JCL: If compiling a COBOL + DB2 program using JCL, the developer should bind the program separately after the compilation process is completed using compilation JCL. i.e., Compilation JCL = Precompilation JCL.
    BIND process should complete separately using another bind JCL. Refer to the BIND process described in a separate topic.

The main difference between these two types of processes is the Bind Step.

Practical Example -


Scenario - Below example describes how the COBOL + DB2 program precompiled using JCL.

Input - EMPLOYEE_DETAILS table

employee_details table

COBOL + DB2 Program to retrieve employee with id 5.

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SELECT1.

       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.

           EXEC SQL
             INCLUDE SQLCA
           END-EXEC.

           EXEC SQL
             ...
           END-EXEC.

       01 WS-EMPID          PIC S9(9) USAGE COMP.

       PROCEDURE DIVISION.

           MOVE 5    TO WS-EMPID.

           EXEC SQL
                SELECT EMP_ID,
                ...
           END-EXEC.

           IF SQLCODE = 0
           ...
           END-IF.

           STOP RUN.

Precompile JCL Code -

----+----1----+----2----+----3----+----4----+----5----+
//MATEGJP JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID
//*********************************************************
//*  COBOL + DB2 PRECOMPILE AND LINKEDIT                  *  
//*********************************************************  
//PCSTEP   EXEC PGM=DSNHPC, 
//             PARM='HOST(IBMCOB),XREF,SOURCE,FLAG(I),APOST'
//STEPLIB  DD  DISP=SHR,DSN=DSNA10.DBAG.SDSNEXIT
//         DD  DISP=SHR,DSN=DSNA10.SDSNLOAD
//SYSCIN   DD  DSN=&&DSNHOUT,DISP=(MOD,PASS),UNIT=SYSDA,
//             SPACE=(800,(500,500)) 
//SYSIN    DD  DSN=MATEGJ.COBDB2.SRCLIB(SELECT1),DISP=SHR
//SYSLIB   DD  DSN=MATEGJ.COBDB2.DCLGEN,DISP=SHR
//         DD  DSN=MATEGJ.COBDB2.COPYLIB,DISP=SHR
//DBRMLIB  DD  DSN=MATEGJ.COBDB2.DBRMLIB(SELECT1),DISP=SHR
...
//**********************************************************
//*  Compile the COBOL program if the precompile           *
//*        return code is 4 or less.                       *
//**********************************************************
//COB      EXEC PGM=IGYCRCTL,
//             PARM=('SIZE(4000K),BUFSIZE(32760),
                 LIST,LIB,MAP,OBJECT',
//             'DATA(31),XREF,RENT'),
//             COND=(4,LT,PCSTEP)
//STEPLIB  DD  DSNAME=IGY420.SIGYCOMP,DISP=SHR
//SYSPRINT DD  SYSOUT=*
//SYSTERM  DD  SYSOUT=*
//SYSLIN   DD  DSN=&&LOADSET,DISP=(MOD,PASS),UNIT=SYSDA,
//             SPACE=(800,(500,500))
//SYSLIB   DD  DSN=MATEGJ.COBDB2.COPYLIB,DISP=SHR
//SYSIN    DD  DSN=&&DSNHOUT,DISP=(OLD,DELETE)
...
//***************************************************
//*        Linkedit if the precompile and compile   *
//*        return codes are 4 or less.              *
//***************************************************  
//LKED     EXEC PGM=IEWL,PARM='MAP,XREF',
//         COND=((4,LT,PCSTEP),(4,LT,COB))
//SYSLIB   DD  DISP=SHR,DSN=CEE.SCEELKED
//         DD  DISP=SHR,DSN=DSNA10.SDSNLOAD
//         DD  DISP=SHR,DSN=ISP.SISPLOAD
//         DD  DISP=SHR,DSN=GDDM.SADMMOD
//         DD  DISP=SHR,DSN=MATEGJ.COBDB2.LOADLIB
//SYSLIN   DD  DSN=&&LOADSET,DISP=(OLD,DELETE)
//         DD  DDNAME=SYSIN
//SYSLMOD  DD  DSN=MATEGJ.COBDB2.LOADLIB(SELECT1),DISP=SHR
...

JOB Result - MAXCC

Precompile JOB MAXCC

JOB Result - Precompile Step

Precompile JOB Precompile Step

JOB Result - Precompile Step Final Report

Precompile JOB Precompile Step Result