Chapter 7. Embedded SQL 79
C/END-EXEC
7.2 Creating a SQLRPG - Program/service program/module
Creating Integrated Language Environment (ILE) objects is always a two-step process:
1. The language compiler converts the source code and creates module objects.
RPG modules are created by the CL command CRTRPGMOD.
A module is sometimes called a compilation unit since it comes from the compilation of
one source member. Modules are not executable. They must be built to either program or
service program objects.
2. The binding process creates programs or service programs by binding the module
objects.
A program is created by the CL command CRTPGM, while to create a service program
the CL command CRTSRVPGM must be used. In this way it is possible to combine
modules that are written in different programming languages into a single program or
service program.
Modules can be bound by copy or by reference to the program objects. Bind by copy
means that the module is physically copied into the program object. Every time a module
is changed all programs that contain this module must be rebound. When using bind by
reference, a module is bound into a service program and only the service program’s
signature is bound to the program object.
After a module is bound to a program or service program, the module object is no longer
needed and can be deleted.
When using CRTBNDRPG, a module is generated in the QTEMP library and then bound
to a program with the same name. If the compilation succeeds, the module will be deleted.
To compile an ILE Object with embedded SQL, an additional preceding step, the
precompilation, is necessary.
The SQL precompile creates an output source file member. By default, the precompile
process creates a temporary source file QSQLTxxxxx in QTEMP, or you can specify the
output source file as a permanent file name on the precompile command. If the precompile
process uses the QTEMP library, the system automatically deletes the file when the job
completes. A member with the same name as the program name is added to the output
source file.
This member contains the following items:
The embedded SQL statements are commented out and replaced by calls to the SQL
run-time support.
Parsed and syntax-checked SQL statement.
SQL Communications Area (SQLCA) is added in the Definition specifications; if not, SET
OPTION SQLCA = *NO is specified.
By default, the precompiler calls the host language compiler. When creating a program
CRTBNDRPG is used, while for modules and service programs CRTRPGMOD is used.