How COBOL DB2 Compilation Process Works

In Mainframe Programming, it is very important to understand how a COBOL DB2 program is compiled and to be aware of all the important steps in the compilation process.

What is DB2 Pre-Compilation Process in Mainframe

DB2 pre-compilation is one of an important step in COBOL DB2 Compilation process. COBOL-DB2 module includes SQL statements and Cobol statements. These SQL statements cannot be processed by host language compilers such as COBOL compilers. So a DB2 pre-compiler or DB2 coprocessor is used to process these SQL statements.

In this article, you’ll learn the basic concept of DB2 pre-compilation process. You’ll get an overview of DB2 pre-compiler, DB2 co-processor, DBRM (Database Request Module) and Consistency token. Let’s start with COBOL DB2 compilation process.

How COBOL-DB2 Compilation Process Works
Photo by olia danilevich on Pexels.com

What is a COBOL DB2 Program

How to compile a COBOL DB2 module or what are the steps which is involved in compiling a COBOL-DB2 program.

A COBOL program that reads or write data to the DB2 database with the help of an SQL statement is known as COBOL DB2 program. COBOL-DB2 Application programs includes various SQL statements to perform many data manipulation operation and SQL statements cannot be processed by host language compiler such as COBOL, C++ orJava. To process these SQL statements, you required either DB2 pre-compiler or DB2 co-processor.

SQL statements processor performs the following actions in COBOL DB2 Compilation:

  • It replaces the embedded SQL statements with equivalent calls to DB2 language interface modules.
  • Generate a database request module (DBRM), which will communicate with the embedded SQL requests to DB2 database engine during binding process.

Now, Let’s see how the DB2 pre-compilation process works using a DB2 pre-compiler.

How COBOL DB2 Compilation Process works

COBOL-DB2 program compilation is a process which is slightly different from normal COBOL program compilation process. It has the below steps in its compilation process:

  • COBOL-DB2 module’s source code is processed by a DB2 pre-compiler. Pre-compiler will generate two outputs (a Modified Source code and Database Request Module (DBRM) consisting of SQL statements).
  • Modified source code is a compiled and link-edit like a simple COBOL program because it does not have any SQL statements. The SQL statements are replaced with an equivalent call to DB2 language interface which is known as DL/I.
  • The Database request modules (DBRMs) are bind into the package or directly into an application plan. The DB2 bind process converts the SQL statement into an executable runtime instruction.

What is DB2 Bind process in COBOL DB2 compilation

DB2 Bind Process is one of the important steps in COBOL DB2 program and it perform 2 important steps as described below:

  1. First, it verifies that your Mainframe ID is authorized to do a bind.
  2. Second, it validates the SQL statement syntax in the program.
  3. Third, DB2 optimizer will turn these SQL statements into an executable code after SQL query optimization. Also, DBRM includes a consistency token to differentiate it from other DBRM which is derived from the other version of the program.

IBM Utilities for Compiling and Binding COBOL DB2 program

IBM Utility program IGYCRCTL is used for compiling COBOL programs and IEWL utility program is used to link edit the program. DSNHPC is the utility to pre-compile and extract the DBRMs. Bind is done using IKJEFT01 utility and its the same utility to execute the COBOL DB2 program as well.

DB2 Precompiler vs Coprocessor: Understanding the Differences

Both the DB2 precompiler and coprocessor play crucial roles in executing SQL statements within the DB2 environment. However, choosing between them depends on specific needs and desired functionalities. Let’s delve into their key differences:

DB2 Precompiler:

  • Functionality: Translates embedded SQL statements in high-level languages like COBOL into low-level calls for the DB2 database system.
  • Strengths:
    • Offers efficient execution for simple SQL statements within host programs.
    • Requires less CPU and memory resources compared to the coprocessor.
    • Suitable for applications with limited SQL complexity.
  • Limitations:
    • Less flexible for handling complex SQL statements like dynamic queries or stored procedures.
    • Doesn’t support some of the latest SQL features and functionalities.
    • Requires recompilation of host programs whenever changes are made to SQL statements.

DB2 Coprocessor:

  • Functionality: Provides a separate engine within the DB2 system dedicated to processing SQL statements.
  • Strengths:
    • Offers more flexibility and efficiency for handling complex SQL statements and dynamic queries.
    • Supports a wider range of SQL features and functionalities compared to the precompiler.
    • Allows for easier execution of stored procedures and dynamic SQL.
    • Eliminates the need for recompilation of host programs when SQL statements change.
  • Limitations:
    • May require more CPU and memory resources compared to the precompiler.
    • Can be slightly slower for simple SQL statements due to additional processing steps.
    • May require additional configuration and setup compared to the precompiler.

Choosing the Right Option:

The best choice between the precompiler and coprocessor depends on several factors:

  • Complexity of SQL statements: For simple embedded SQL statements, the precompiler offers efficient execution. However, for complex or dynamic SQL, the coprocessor provides greater flexibility and functionality.
  • Performance requirements: For applications requiring high performance and efficient resource utilization, the precompiler might be preferable for simple SQL queries.
  • Support for latest SQL features: If your applications rely on the latest SQL features and functionalities, the coprocessor is the recommended choice.
  • Development and maintenance: The precompiler requires recompilation of host programs after SQL changes, while the coprocessor eliminates this need.

Additional Considerations:

  • Some DB2 environments allow for both precompiler and coprocessor to coexist, offering a hybrid approach.
  • Migrating from precompiler to coprocessor requires careful planning and testing to ensure smooth transition.

Final Thoughts on COBOL DB2 compilation

In Almost every Mainframe Interview, this is one question that you can expect for sure to test your understanding. I hope this article helps you understand the COBOL DB2 compilation process and overall got a better understanding on how a COBOL DB2 program works.

Leave a Comment