Processing SQL statements

The first step in preparing an SQL application to run is to process the SQL statements in the program. To process the statements, use either the DB2® precompiler or the DB2 coprocessor. During this step, the SQL statements are replaced with calls to DB2 language interface modules, and a DBRM is created.

About this task

For assembler or Fortran applications, use the DB2 precompiler to prepare the SQL statements.

For C, C++, COBOL, or PL/I applications, you can use one of the following techniques to process SQL statements:
  • Use the DB2 precompiler before you compile your program.

    You can use this technique with any supported version of C or C++, COBOL, or PL/I.

  • Invoke the DB2 coprocessor for the host language that you are using as you compile your program. You can use the DB2 coprocessor with C, C++, COBOL, and PL/I host compilers. To invoke the DB2 coprocessor, specify the SQL compiler option followed by its suboptions, which are those options that are defined for the DB2 precompiler. Some DB2 precompiler options are ignored.
    • For C or C++, you need IBM® z/OS® Version 1 Release 8 C/C++ or later. For C and C++, you can also invoke the coprocessor from UNIX System Services on z/OS to generate a DBRM in either a partitioned data set or an HFS file.
    • For COBOL, you need Enterprise COBOL for z/OS Version 3 Release 4 or later to use this technique.
    • For PL/I, you need Enterprise PL/I for z/OS Version 3 Release 4 or later to use this technique.
CICS: If the application contains CICS® commands, you must translate the program before you compile it.

DB2 version in DSNHDECP module

When you process SQL statements in your program, if the DB2 version in DSNHDECP is the default system-provided version, DB2 issues a warning and processing continues. In this case, ensure that the information in DSNHDECP that DB2 uses accurately reflects your environment.

SQL statement processing

Because most compilers do not recognize SQL statements, you can prevent compiler errors by using either the DB2 precompiler or the DB2 coprocessor.

Start of changeThe precompiler scans the program and returns modified source code, which you can then compile and link edit. The precompiler also produces a DBRM (database request module). You can bind this DBRM to a package using the BIND subcommand. When you complete these steps, you can run your DB2 application.End of change

Alternatively, you can use the DB2 coprocessor for the host language. The DB2 coprocessor performs DB2 precompiler functions at compile time. When you use the DB2 coprocessor, the compiler (rather than the precompiler) scans the program and returns the modified source code. The DB2 coprocessor also produces a DBRM.

Related reference:
Enterprise COBOL for z/OS

Related information