Processing SQL statements by using the DB2 precompiler

The DB2® precompiler scans a program and copies all of the SQL statements and host variable information into a DBRM (database request module). The precompiler also returns source code that has been modified so that the SQL statements do not cause errors when you compile the program.

About this task

After the SQL statements and host variable information are copied into a DBRM and the modified source code is returned, you can compile and link-edit this modified source code.

Before you run the DB2 precompiler, use DCLGEN to obtain accurate SQL DECLARE TABLE statements. The precompiler checks table and column references against SQL DECLARE TABLE statements in the program, not the actual tables and columns.

DB2 does not need to be active when you precompile your program.

You do not need to precompile the program on the same DB2 subsystem on which you bind the DBRM and run the program. You can bind a DBRM and run it on a DB2 subsystem at the previous release level, if the original program does not use any properties of DB2 that are unique to the current release. You can also run applications on the current release that were previously bound on subsystems at the previous release level.

Procedure

To process SQL statements by using the DB2 precompiler:

  1. Ensure that your program is ready to be processed by the DB2 precompiler by performing the following actions. For information about the criteria for programs that are passed to the precompiler, see Input to the DB2 precompiler.
  2. If you plan to run multiple precompilation jobs and are not using the DFSMSdfp partitioned data set extended (PDSE), change the DB2 language preparation procedures (DSNHCOB, DSNHCOB2, DSNHICOB, DSNHFOR, DSNHC, DSNHPLI, DSNHASM, DSNHSQL) to specify the DISP=OLD parameter instead of the DISP=SHR parameter. The DB2 language preparation procedures in job DSNTIJMV use the DISP=OLD parameter to enforce data integrity. However, the installation process converts the DISP=OLD parameter for the DBRM library data set to DISP=SHR, which can cause data integrity problems when you run multiple precompilation jobs.
  3. Start the precompile process by using one of the following methods:
    Recommendation: Specify the SOURCE and XREF precompiler options to get complete diagnostic output from the DB2 precompiler. This output is useful if you need to precompile and compile program source statements several times before they are error-free and ready to link-edit.

    The output that is returned from the DB2 precompiler is described in Output from the DB2 precompiler.

Results

Preparing a program with object-oriented extensions by using JCL:
If your C++ or Enterprise COBOL for z/OS® program satisfies both of these conditions, you need special JCL to prepare it:
  • The program consists of more than one data set or member.
  • More than one data set or member contains SQL statements.

You must precompile the contents of each data set or member separately, but the prelinker must receive all of the compiler output together.

JCL procedure DSNHCPP2, which is in member DSNTIJMV of data set DSN1010.SDSNSAMP, shows you one way to do this for C++.

Precompiling a batch program: When you add SQL statements to an application program, you must precompile the application program and bind the resulting DBRM into a package, as described in Preparing an application to run on DB2 for z/OS.