THE PRECOMPILER
The DB2 Precompiler does not need DB2 to run. It carries out three primary tasks as it reads the program serially, top-to-bottom, looking for DB2 delimiters.First, if the delimiters surrounded an
INCLUDE
statement, the Precompiler goes to the INCLUDE
library named in the job control language data definition statement and pulls the included MEMBERNAME
into the program. This function is the same as a COBOL COPY MEMBERNAME
, but the timing is different. COBOL COPYBOOK
s get copied in at COMPILE
time; DB2 INCLUDE
s get copied in at precompile time. The only difference between an SQL INCLUDE
and a COBOL COPY
is timing. The most common item INCLUDE
d in a program was (and is) a DCLGEN
. DCLGEN
s are structures that describe a table. One DCLGEN
is usually included for each table that the program will access at run time. Each DCLGEN
is a two-part structure consisting of a DECLARE TABLE
statement, which describes the table in DB2 SQL language, and a COBOL structure that describes the table using an 01-Level COBOL working storage structure (much like a typical copybook for a VSAM file).Second, if the delimiters surround an SQL statement, the precompiler does a very basic syntax check to make sure that the column and table names are valid (that they're spelled correctly and that the columns and the table exist). Many DBAs and programmers think that this validation is done by reading the DB2 CATALOG, but they're wrong. Remember, the precompiler doesn't need DB2 or its CATALOG. DB2 might not even be installed on the machine. The DB2 Precompiler uses the top part of the DCLGEN to validate the SQL syntax.
The third, and most important, task performed by the DB2 Precompiler is to split the program into two parts: a COBOL and a DB2 part. All of the SQL that the programmer carefully embedded is stripped out of the program and put into its own partitioned data set (PDS) member, called a DBRM. A single program containing two languages, COBOL and SQL, goes into the DB2 Precompiler and two pieces come out. Twins, but fraternal twins — much like Arnold Schwarzenegger and Danny DeVito. Arnold looks just like his COBOL mother, and Danny looks just like his DB2 father. COBOL Arnold, with all of the SQL commented out, goes down one path in life. SQL Danny, containing only SQL, goes down a different path in life.
The twins, separated at birth, have a tendency to lose each other. To help the twins find each other later in life (in other words, at run time), the precompiler engraves each with identical tattoos. The tattoo is carried forward with COBOL Arnold, through compile and link edit, into the
LOAD
module in the LOAD
library. The tattoo is part of the run-time executable code of the LOAD
module. The same tattoo is carried forward with SQL Danny through BIND
. BIND
is to SQL what COMPILE
is to COBOL. The purpose of COBOL COMPILE
is to come up with run-time code for the COBOL. The purpose of BIND
is to come up with run-time executable code for the SQL.Both sets of code bear identical tattoos (timestamps or consistency tokens).
So, the COBOL twin becomes a transportable load module in the COBOL
LOADLIB
and the SQL becomes a transportable DBRM in the DBRMLIB
. Just as the COBOL twin had to be compiled, the DBRM twin has to go through BIND
to create the run-time executable code for the DB2 portion of the COBOL program and put that executable code into the "right" DB2 subsystem.
Unleashed the truth of everyday confusions. @ DB2 users. It worths a read.
ReplyDeleteThanks Gautam.