# RPG (Report Program Generator)

Paradigm Multi-paradigm IBM Strong, static {{#property:P856}} RPG, RPG II, RPG III, RPG 400, RPG IV, RPG/ILE; RPG/Free, Baby/36, Baby/400, Lattice RPG RPG II

The RPG language is machine-independent. Its design enables applications programmers to prepare computer programs without a thorough knowledge of the operating system. Because of program logic cycle (PLC) processing, the programmer can focus on the problem to be solved by the system, rather than on the details of system operation. Basically, RPG specifies the type of data to be processed and the type of output desired. The compiler translates the specifications into instructions that do all that is necessary to produce the required output.

## RPG Applications

RPG programs are often used to produce customized reports from data contained in files; however, RPG can be used for a variety of data processing applications that do not involve report production in the traditional sense. Primarily, these other applications update data files stored on magnetic tape, disk, or other machine-readable media.

RPG offers the following advantages to the user:

• Simple, generative syntax for ease of program implementation
• Ease of conversion through standard implementation
• Comprehensive documentation
• Computing power

## File Creation

The Command and Edit (CANDE) message control system (MCS) creates the program file. CANDE facilitates the editing and management of programs. Additional information on CANDE is provided in the CANDE Operations Reference Manual.

Either of the following methods can be used to compile and run the program:

• The CANDE message control system (MCS).
• The Work Flow Language (WFL). WFL is a powerful language that can be used to construct jobs that run tasks and control their execution. Additional information on the WFL job control language is provided in the Task Attributes Programming Reference Manual.

## RPG Dialects

RPG for MCP based systems supports two dialects: RPG I and RPG II. The RPG I dialect is compatible with the IBM 360/20 RPG. The RPG II dialect is compatible with the IBM System/36 RPG II. Both dialects support MCP based extensions. If RPG I features are needed, a 1 must be entered in the Source Dialect field (column 51) of the Control Specification; otherwise, this column should be blank. The source program is not checked against the syntax of the chosen dialect; this option is used only to resolve conflicts between the dialects. Provided that no conflict exists, RPG II features can be used when the RPG I dialect is specified; similarly, RPG I features can be used when the RPG II dialect is specified. In this manual, all references to RPG that do not specify a particular dialect refer to RPG II.

## RPG Source Program

A program written in the RPG language is called an RPG source program. The RPG compiler verifies that the source program is syntactically correct and converts this source program into a machine-language program (machine code), which in this manual is called an object program. After compilation, the object program is ready for execution by the system. Compiler control records (CCRs) accommodate system-dependent features. These specifications can appear anywhere in the source program, unless otherwise specified.

## Source File Organization

An RPG source program is divided into different types of specifications as illustrated by Figure 1

Figure 1

## Example code

The following program receives a customer number as an input parameter and returns the name and address as output parameters. This is the most primitive version of RPG IV syntax.

      * Historically RPG was columnar in nature, though free-formatting
* was allowed under particular circumstances.
* The purpose of various lines code are determined by a
* letter code in column 6.
* An asterisk (*) in column 7 denotes a comment line

* "F" (file) specs define files and other i/o devices
F ARMstF1   IF   E       K     Disk    Rename(ARMST:RARMST)

* "D" specs are used to define variables
D pCusNo          S              6p
D pName           S             30a
D pCity           S             25a
D pState          S              2a
D pZip            S             10a

* "C" (calculation) specs are used for executable statements
* Parameters are defined using plist and parm opcodes
C     *entry        plist
C                   parm                    pCusNo
C                   parm                    pName
C                   parm                    pCity
C                   parm                    pState
C                   parm                    pZip

* The "chain" command is used for random access of a keyed file
C     pCusNo        chain     ARMstF1

* If a record is found, move fields from the file into parameters
C                   if        %found
C                   eval      pName  = ARNm01