HP RPG/XL Programmer's Guide (30318-90001)

1-1
Chapter 1 How RPG Works
RPG programs can be thought of as having two different authors. You are
the primary author. You enter the RPG program
specifications
that
describe the input and output data and the calculations to perform on
that data. For example, if you want to print a total line on a report,
you must describe the format of the total line and define the
calculations that will produce it. The RPG compiler is the second author
of RPG programs. When you compile an RPG program, the compiler
determines when, and the order in which your specifications are executed.
Thus, it supplies the logic framework of the RPG program. This
framework, the RPG
logic cycle
, reads and writes files and prints detail
and total lines on reports. The RPG logic cycle notifies you of events
that it controls by means of
indicators
. For example, when RPG reads the
last record in an input file, it turns on the last-record (LR) indicator.
You can then use this indicator in your specifications to direct
processing. Conversely, you can use indicators to control certain RPG
logic cycle events. For example, you can cause a program to end
immediately by turning on the last-record indicator.
The next sections in this chapter go into more detail about
specifications, the RPG logic cycle and indicators. Specifications are
presented first to give you a clear idea of the types of events that they
control. Next, an overview of the RPG-supplied logic is presented in the
section, "The Basic RPG Logic Cycle." Indicators are discussed in the
section, "RPG Indicators." You can see how indicators provide the
communications link between the RPG logic cycle and your specifications.
The last section, "More About the RPG Logic Cycle," completely describes
each step of the logic cycle. The section discusses all of the
specifications and indicators that are used during the cycle.
RPG Specifications
Specifications are the source code for RPG programs. There are different
kinds of specifications, each used for a particular function. For
example, you use Output Specifications to define and describe data to be
printed on a report. The specifications are listed below in the order
that you enter them into a program:
Specification Description
Header (H) Sets RPG compiler options, certain
indicators and the collating sequence.
File Description (F) Describes the files used in the program.
File Extension (E) Defines arrays and tables, and gives
additional information about certain
types of files.
Line Counter (L) Defines printer page lengths, overflow
lines and channel numbers.
Input (I) Defines input records and data fields
used in the program.
Calculation (C) Defines computations and other operations
to be performed.
Output (O) Defines output records and data fields
used in the program.
Array/Table File Name (A) Names a file which contains a
compile-time array or table.