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:
A linear-main module will not include logic for the RPG program cycle; thus language features dependent on the cycle may not be specified.
See Linear Module for more information.
The following two examples show a linear-main program and its /COPY file.
* The prototype for the linear-main procedure must have
* the EXTPGM keyword with the name of the actual program.
D DisplayCurTime PR EXTPGM('DSPCURTIME')
* The program is named DSPCURTIME, and the module has
* a linear-main procedure called DisplayCurTime.
* 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.
H MAIN(DisplayCurTime)
* Copy in the prototype for the program
/COPY DSPCURTIME
*--------------------------------------------------
* Procedure name: DisplayCurTime
*--------------------------------------------------
P DisplayCurTime B
D DisplayCurTime PI
/FREE
dsply ('It is now ' + %char(%time()));
/END-FREE
P DisplayCurTime E
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.
H MAIN(PrintCustomerReport)
*--------------------------------------------------
* Program name: PrintCustomerReport (PRTCUSTRPT)
*--------------------------------------------------
P PrintCustomerReport...
P B
F ... file specifications
D PI EXTPGM('PRTCUSTRPT')
D custName 25A CONST
... calculations, using the custName parameter
P PrintCustomerReport...
P E