MAIN キーワードは、このソース・プログラムがリニア・メイン・モジュールのためのものであり、リニア・メイン・プロシージャーを含んでいることを示します。 リニア・メイン・プロシージャーは、main_procedure_name パラメーターで指定され、モジュールのプログラム入り口プロシージャーとなります。
main_procedure_name は、ソース・プログラムで定義されているプロシージャーの名前でなければなりません。 リニア・メイン・プロシージャーは、プログラム呼び出しインターフェースを介してのみ呼び出されるものであり、結合プロシージャー呼び出しでは呼び出せません。 リニア・メイン・プロシージャーに対して再帰呼び出しを行うと、その呼び出しは動的プログラム呼び出しになります。
以下の 2 つの例では、リニア・メイン・プログラムとその /COPY ファイルを示します。
* 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
以下の例では、プロトタイプを必要としないリニア・メイン・プログラムを示します。 プログラムの名前は PRTCUSTRPT で、モジュールには、リニア・メイン・プロシージャーの PrintCustomerReport が含まれています。 このプログラムは、*CMD オブジェクトのコマンド処理プログラムになるものであるため、RPG プロトタイプは必要ありません。 制御仕様書の MAIN キーワードでは、これがリニア・メイン・モジュールであることを示し、 プログラム入り口プロシージャーとして機能するリニア・メイン・プロシージャーとなる、特殊なサブプロシージャーであるプロシージャーを識別します。
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