Procedures and the Program Logic Cycle

A procedure is a collection of statements that can be called and run.

There are three kinds of procedures in RPG: regular subprocedures, linear-main procedures and cycle-main procedures. RPG source programs can be compiled into one of three kinds of modules depending on the types of procedures present, and as indicated by the presence of the NOMAIN or MAIN keyword on the Control specification: Cycle, Nomain, or Linear-main modules.

The term "subprocedure" is used to denote both regular subprocedures and linear-main procedures.

An RPG source program can be divided into these sections which contain procedures:
  • Main source section: The source lines from the first line in the source program up to the first Procedure specification. In a cycle module, this section may contain calculation specifications (standard or free-form) which make up a cycle-main procedure. A cycle-main procedure is implied even if there are no calculation specifications in this section. This kind of procedure does not have Procedure-Begin and Procedure-End specifications to identify it.

    A cycle module may be designed without sub-procedures, and thus have no separate Procedure section.

  • Procedure section: Zero or one linear-main procedures, and one or more regular sub-procedures, defined within the source program. Each procedure begins with a Procedure-Begin specification, and ends with a Procedure-End specification.

    The linear-main procedure is indicated by the use of the MAIN keyword on a Control specification, making it a special kind of sub-procedure.