The ILE RPG compiler supplies part of the logic for an RPG module.
Depending on the type of module you choose, this supplied logic will
control a large or small part of the control flow of your module.
By default, an RPG module will include the full RPG Cycle, which begins
with the *INIT phase and ends with the *TERM phase. The other two
types of RPG modules do not include the full RPG Cycle; the only remnant
of the RPG cycle is the module initialization, which is similar to
the *INIT phase. The ILE RPG compiler supplies additional implicit
logic that is separate from the RPG cycle; for example, the implicit
opening and closing of local files in subprocedures.
All ILE RPG modules can have one or more procedures.
The three types of RPG modules are distinguished by the nature
of the main procedure in the module.
A program or a service program can consist of multiple modules,
each of which can have an RPG main procedure. If an RPG module is
selected to be the program-entry module of a program, then you call
the main procedure using a program call. If an RPG module is not the
program-entry module of a program, or if it is a module in a service
program, then you call its main procedure using a bound call. Calling
a main procedure through a bound call is only available for cycle-main
procedures; if a module contains a linear-main procedure and that
module is not selected to be a program-entry module, than that procedure
cannot be called.
- A module with a cycle-main procedure
- The module contains a cycle-main procedure and zero or more subprocedures.
The cycle-main procedure includes the logic for the full RPG cycle.
A cycle-main procedure can be called through a bound call, or through
a program call. See Cycle Module and Program Cycle for more information.
- A module with a linear-main procedure
- The module contains a linear-main procedure and zero or more ordinary
subprocedures. The linear-main procedure is identified by the MAIN
keyword on the Control specification. The main procedure itself is
coded as a subprocedure (with Procedure specifications). The linear-main
procedure can only be called through a program call; it cannot be
called using a bound call.
Note: Other than the way it is called,
the linear-main procedure is considered to be a subprocedure.
The
module does not include the logic for the RPG cycle. See Linear Main Module for more information.
- A module with no main procedure
- The NOMAIN keyword on the Control specification indicates that
there is no main procedure in the module. The module contains only
subprocedures. The module does not include the logic for the RPG cycle.
This type of module cannot be the program-entry module of a program,
since it has no main procedure.
See NOMAIN Module for more information.
Table 1. Summary of RPG
module types| Module Type |
Keyword |
Cycle Features Allowed |
Main Procedure |
Initialization of global variables,
opening of global files, and locking of UDS data areas  |
Implicit closing of global files and unlocking
of data areas |
| Cycle-main |
|
Yes |
Implicitly defined in the main source section |
- When the first procedure in the module is called after the activation
group is created.
- When the main procedure is called, if the main procedure previously
ended with LR on, or ended abnormally.
|
When the main procedure ends with LR on, or
ends abnormally. |
| Linear-main |
MAIN |
No |
Explicitly defined with the MAIN keyword
and Procedure specifications |
When the main procedure is first called
after the activation group is created, or if somehow a sub-procedure
is called first. |
Never |
| No main |
NOMAIN |
No |
None, indicated by the presence of the NOMAIN
keyword |
When the first procedure in the module is
called after the activation group is created |
Never |