COBOL DB2 Precompilation Process flow diagram.
COBOL DB2 Precompilation Process flow diagram.
DB2 Precompilation Process.

COBOL DB2 Compilation Process (DB2 precompilation process).

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.

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.

What is COBOL DB2 Program.
What is COBOL DB2 Program.
COBOL DB2 Program / COBOL DB2 Applications.

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:

  1. Replaces the embedded SQL statements with equivalent calls to DB2 language interface modules.
  2. 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.

DB2 precompilation flow diagram.
DB2 precompilation flow diagram.
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:

  1. 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)).
  2. 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.
  3. 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.

DB2 Precompilation flow diagram using DB2 coprocessor.
DB2 Precompilation flow diagram using DB2 coprocessor.
DB2 precompilation by using DB2 coprocessor.

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.

DB2 Precompilation Process Tutorial.

Please Subscribe to Topictrick & Don’t forget to press THE BELL ICON to never miss any updates. Please visit below mention the link to stay connected with Topictrick.
Topictrick.com
Youtube
Follow us on Twitter
Facebook
Linkedin
Reddit
Mainframe Blog

Thank you for your support.

Topictrick™

Topictrick is a comprehensive repository of programming language tutorial and tech reviews. Also, it showcases what new in the tech industry. One place for all.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store