The MAIN keyword indicates that this source program is for a linear-main
module and contains a linear-main procedure, identified by the main_procedure_name parameter, which will be the program entry procedure
for the module.
The main_procedure_name must be the name of
a procedure defined in the source program. The linear-main procedure
is intended to be called only through the program call interface and not as
a bound procedure call; if you make a recursive call to the linear-main procedure,
the call will be a dynamic program call.
Therefore, the following rules apply:
If a prototype is specified for the linear-main procedure,
it must specify the EXTPGM keyword.
If a prototype is not specified for the linear-main procedure,
and a procedure interface is specified, the
procedure interface must specify the EXTPGM keyword.
If the program has no parameters, and the program is
not called from an RPG program, neither a
prototype nor a procedure interface is required.
The procedure cannot be exported; the EXPORT keyword may not be specified
on the procedure-begin specification for main_procedure_name.
A linear-main module will not include logic for the RPG program cycle;
thus language features dependent on the cycle may not be specified.
Note: The NOMAIN keyword also allows you to create a module that does
not contain the RPG program cycle.
The following two examples show a linear-main program and its /COPY file.
The following example shows a linear main program
that does not require a prototype.
The program is named PRTCUSTRPT,
and the module has a linear-main procedure called PrintCustomerReport.
The program is intended to be the command processing program
for a *CMD object, so there is no need for an RPG prototype.
The Control specification MAIN keyword signifies that this is
a linear-main module, and identifies which procedure is the
special subprocedure which serves as the linear-main procedure,
which will act as the program-entry procedure.