Modernization Hub

DB2 Precompiler

Enhanced Definition

The DB2 Precompiler is a utility in the IBM z/OS environment that processes application programs containing embedded SQL statements. Its primary purpose is to convert these embedded SQL statements into host language (e.g., COBOL, PL/I, C/C++) call statements that the standard compiler can understand, and to generate a Database Request Module (DBRM). The DB2 Precompiler is a utility that processes application programs written in host languages (like COBOL, PL/I, or C/C++) that contain embedded SQL statements. Its primary purpose is to replace these SQL statements with standard host language CALL statements that interact with DB2, preparing the source code for compilation by a standard language compiler.

Key Characteristics

    • Input/Output: Takes a source program with embedded EXEC SQL ... END-EXEC statements and produces a modified source program (with SQL replaced by host language calls) and a DBRM (Database Request Module).
    • SQL Syntax Checking: Performs initial syntax checking of the embedded SQL statements against DB2 rules and validates host variable declarations within the program.
    • Host Variable Resolution: Identifies and resolves host variables used in SQL statements, ensuring they are properly defined and accessible within the host language program.
    • Error Reporting: Generates a listing file that details any errors, warnings, or informational messages encountered during the precompilation process.
    • DBRM Creation: The DBRM is a crucial output that contains a parsed representation of all SQL statements from the source program, which is later used by the DB2 BIND process.
    • Language Specificity: Different precompilers exist for various host languages (e.g., COBOL, PL/I, C/C++), each tailored to the specific syntax and conventions of that language.

Use Cases

    • Developing New DB2 Applications: It is the essential first step in the development cycle for any new application program (e.g., COBOL batch program, CICS transaction, IMS BMP) that needs to interact with DB2 databases.
    • Modifying Existing DB2 Applications: Required whenever embedded SQL statements in an existing program are changed, added, or removed, necessitating the generation of a new DBRM.
    • Preparing for Standard Compilation: The modified source code produced by the precompiler is then passed to the standard language compiler (e.g., IBM COBOL for z/OS) to generate an object module.
    • Generating DBRMs for BIND: The DBRM is subsequently used by the DB2 BIND utility to create or replace an application package or plan, defining how DB2 will access data and execute the SQL statements.

Related Concepts

The DB2 Precompiler is an integral part of the DB2 application development lifecycle, directly preceding the standard language compiler (e.g., COBOL compiler). Its primary output, the DBRM (Database Request Module), is the input for the DB2 BIND utility, which creates packages and plans that define the access paths for SQL statements. It works closely with host variables, which are program variables used to exchange data between the application program and DB2, and is a prerequisite for any program that requires CICS or IMS to access DB2.

Best Practices:
  • Integrate into Build Process: Automate precompilation as an early step in your build process (JCL or build script) to catch SQL syntax errors and host variable issues as soon as possible.
  • Version Control DBRMs: Treat DBRMs as critical artifacts and manage them under strict version control, ensuring that the DBRM used for BIND always corresponds to the correct version of the precompiled source code.
  • Handle SQLCODE/SQLSTATE: Always include robust error handling logic in your application programs to check SQLCODE and SQLSTATE after every SQL statement to manage successful execution, warnings, and errors.
  • Use Appropriate Options: Select the correct precompiler options (e.g., APOST, QUOTES, DATE, TIME, SQL(CICS)) to match the conventions of your application, host language, and DB2 subsystem, especially for CICS programs.
  • Review Listing Files: Carefully examine the precompiler listing for any warnings or errors, even if the precompilation completes successfully, as warnings can indicate potential performance or runtime issues.

Related Vendors

ABA

3 products

ASE

3 products

IBM

646 products

Broadcom

235 products

Trax Softworks

3 products

Related Categories

CASE/Code Generation

19 products

Operating System

154 products

Browse and Edit

64 products