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,
or their free-form equivalents. 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.
Fully free-format specifications are allowed for
Control,
File Description,
Definition, and
Procedure statements.
Fully free-format specifications are also
allowed for calculation statements with those operation codes
which support an extended-factor 2; see
Free-Form Calculation Statement.
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 1. Any of the specification types can be absent, but at least one from the main source section must be present.
File Description and Definition specifications may
be intermixed. 
| Source Section | Order of Specifications |
|---|---|
| Main Source Section |
|
| Subprocedure Section |
|
| Program Data when the ** form is used | ** |
| Program Data when the **TYPE form is used | (Specified in any order) |