DB2 precompilation process is an important step to prepare a COBOL DB2 program for execution. COBOL DB2 program includes the SQL statement and these SQL statements cannot be processed by host language compilers. Thus, DB2 precompiler or DB2 coprocessor is used to process SQL statements.
In this session, you’ll learn the basic concept of DB2 precompilation process. You’ll get an overview of DB2 precompiler, DB2 coprocessor, Database Request Model (DBRM), Consistency token. Let’s get started with COBOL DB2 compilation process.
Scenario: Let’s say you have been asked to compile a COBOL DB2 program but being a new team member you don’t know how to compile a COBOL DB2 program or what are the steps which is involved in compiling a COBOL DB2 program.
What is COBOL DB2 Program or COBOL DB2 Application?
In layman term, 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.
Why you need DB2 precompilation process for any COBOL DB2 application?
COBOL DB2 Applications included SQL statement to perform various data manipulation operation and SQL statements cannot be processed by host language compiler such as COBOL, C++, Java etc. To process these SQL statements, you required either DB2 precompiler or DB2 coprocessor.
SQL statement processor performs the following actions:
- Replaces the embedded SQL statements with equivalent calls to DB2 language interface modules.
- Generate a database request module (DBRM), which communicate your embedded SQL requests to DB2 database engine during the binding process.
Now. let's focus on the DB2 precompilation process by using DB2 precompiler.
COBOL DB2 program compilation process is slightly different from normal COBOL program compilation process. Now, let's try to understand the flow:
- COBOL DB2 program source code is processed by a DB2 precompiler. It generates two outputs (i.e. Modified Source code and Database Request Module (DBRM)).
- 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 already replaced with an equivalent call to DB2 language interface.
- Database request module (DBRM) are bind into the package or directly into an application plan. The DB2 bind process converts the SQL statement into an executable runtime instruction.
Note: DB2 Bind process performs three important functions. First, it verifies that you are authorized to do a bind. Second, it validates your SQL statement syntax. Third, DB2 optimizer will turn your SQL statement into an executable code after SQL query optimization. Also, DBRM includes a consistency token to distinguish it from other DBRM which is derived from the other version of the program.
Now. let's focus on DB2 precompilation process by using DB2 coprocessor processor.
Now, if you look at the DB2 precompiler and DB2 coprocessor diagram, then you can easily make out the difference.
When you use DB2 coprocessor the compiler automatically handles your source code that contains embedded SQL statements. You don’t require a separate pre-compiled step.
When the compiler encounters the SQL statement in the source program it interfaces with the DB2 coprocessor and the complete SQL statement between EXEC SQL and END SQL is passed to the DB2 SQL statement coprocessor.
DB2 coprocessor analyses SQL statement and indicate compiler to generate native COBOL statement corresponding to the SQL statement and the remaining process of generating a load module and binding DBRM into a plan or a package will remain the same.
Note: You’ve to specify SQL compiler option to use DB2 coprocessor instead of DB2 pre-compiler.
Topictrick Youtube: DB2 precompilation process is associated with a youtube video tutorial.