Main Procedures and Subprocedures

An ILE RPG module consists of zero or more subprocedures and optionally, a main procedure. A main procedure is a procedure that can be specified as the program entry procedure (and so receive control when an ILE program is first called). A cycle-main procedure can be defined in the main source section, which is the set of H, F, D, I, C, and O specifications that begin a module; a linear-main procedure can be specified in the subprocedure section and specially-designated with the MAIN keyword on a Control specification. For additional information about procedures and the program logic cycle, refer to the "WebSphere Development Studio ILE RPG Reference".

A subprocedure is a procedure that is specified after the main source section. A subprocedure differs from a main procedure primarily in that:

Subprocedures can provide independence from other procedures because the data items are local. Local data items are normally stored in automatic storage, which means that the value of a local variable is not preserved between calls to the procedure.

Subprocedures offer another feature. You can pass parameters to a subprocedure by value, and you can call a subprocedure in an expression to return a value. Figure 12 shows what a module might look like with multiple procedures.

Figure 12. An ILE RPG Cycle-module with Multiple Procedures

As the picture suggests, you can now code subprocedures to handle particular tasks. These tasks may be needed by the main procedures or by other modules in the application. Furthermore, you can declare temporary data items in subprocedures and not have to worry if you have declared them elsewhere in the module.



[ Top of Page | Previous Page | Next Page | Contents | Index ]