There are three groups of source records that may be coded in an RPG IV program: the main source section, the subprocedure section, and the program data section. The main source section consists of the first set of H, F, D, I, C, and O specifications in a module. If MAIN or NOMAIN is specified on a Control specification, this section does not contain a cycle-main procedure, and so it cannot contain any executable calculations. If the keyword MAIN or NOMAIN is not specified, this corresponds to a standalone program or a cycle-main procedure. Every module requires a main source section independently of whether subprocedures are coded.
The subprocedure section contains specifications that define any subprocedures coded within a module. The program data section contains source records with data that is supplied at compile time.
The RPG IV language consists of a mixture of position-dependent code and free form code. Those specifications which support keywords (control, file description, definition, and procedure) allow free format in the keyword fields. The calculation specification allows free format with those operation codes which support an extended-factor 2. Otherwise, RPG IV entries are position specific. To represent this, each illustration of RPG IV code will be in listing format with a scale drawn across the top.
The following illustration shows the types of source records that may be entered into each group and their order.
The RPG IV source must be entered into the system in the order shown in Table 42. Any of the specification types can be absent, but at least one from the main source section must be present.
Main Source Section H Control F File Description D Definition I Input C Calculation O Output |
Subprocedure Section (Repeated for each procedure) P Procedure F File Description D Definition C Calculation P Procedure |
Program Data when the ** form is used ** File Translation Records ** Alternate Collating Sequence Records ** Compile-Time Array and Table Data |
Program Data when the **TYPE form is used (Specified in any order) **CTDATA ARRAY1 Compile-Time Array Data **FTRANS File Translation Records **CTDATA TABLE2 Compile-Time Table Data **ALTSEQ Alternate Collating Sequence Records **CTDATA ARRAY3 Compile-Time Array Data |