PP2 includes a precompiler as well as the services that execute or provide runtime support for a compiled application. A precompiler is necessary to interpret the embedded SQL statements in the host program. Regardless of the host language, PP2 operation consists of two stages:
- The precompile phase, which precedes application compilation and linking.
- Execution, or runtime support, of the application.
During precompilation, PP2 reads and replaces all the SQL statements embedded in the host program with CLIv2 calls that are acceptable to the native compiler for the host language. The host programming language syntax remains unchanged.
At runtime, the inserted syntax runs in conjunction with Call-Level Interface version 2 (CLIv2) and Teradata Director Program (TDP) modules to provide a convenient interface between the application program and the database.
Following are the steps that PP2 performs, from logging on to the database through precompilation. The example uses a COBOL program, though the process is similar for other languages:
- Logs a session onto the database and determines whether it is to be a Teradata mode or ANSI-compatible mode session.
- Checks the syntax of SQL statements in the host language source program, validating database objects against the entries in the Data Dictionary.
- Builds code in the DATA division for the data elements.
- Builds code in the PROCEDURE division to handle SQL statement passing to the database.
- Comments out the SQL source code.
- Produces COBOL source for input to the COBOL compiler.
The following figure gives a high-level view of starting with a PL/I embedded SQL program as the source input file, then precompiling, compiling, linking, and finally, running the PL/I program.