RPG (Report Program Generator)

From Bauman National Library
This page was last modified on 8 June 2016, at 18:49.
RPGReport Program Generator
Paradigm Multi-paradigm
Developer IBM
Typing discipline Strong, static
Website {{#property:P856}}
RPG, RPG II, RPG III, RPG 400, RPG IV, RPG/ILE; RPG/Free, Baby/36, Baby/400, Lattice RPG

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
Specifications Description
Control Provides information about the program and selects compiler options. The Control Specification is optional.
Database Establishes the link between an RPG program and DMSII. The Database Specification is used to invoke a database. For more information about using DMSII in RPG, refer to Volume 2 of this manual.
File Describes files used in the program and associates them with hardware devices.
File Attribute Provides additional file information used by the operating system. These specifications immediately follow the File Specifications to which they refer.
Extension Describes vectors (tables and arrays) and record-address files used in the program.
Line Counter Provides information about the number of lines printed on each page of printer output. Also, line-channel equations can be specified to associate print lines with channel punches in a carriage control tape.
Telecommunications Establishes and maintains the link between the RPG program and a message control system (MCS).
Library Links RPG programs to library procedures written in any language that can be called by an RPG program.
Library Attribute Provides additional library information used by the operating system. These specifications immediately follow the Library Specifications to which they refer.
Input Describes the layout of records read by the program.
Calculation Describes the sequence and timing of calculations performed on data in the program. Calculation Specifications can also describe input and output control for some files.
Output Specifies the type and format of data written as output from the program.
Alternate Collating Sequence Modifies the EBCDIC collating sequence. Specifications records also can be used.
File Translation Translates characters between the EBCDIC character set and a user-specified character set. Can precede or follow the Alternate Collating Sequence Specifications. Specifications records also can be used.
Vector Data Loads compile-time vector data. Specifications records also canbe used.
Vector Data Elements Follow the Vector Data Specifications to provide the data for compile-time vectors.

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 pAddr1          S             30a
     D pAddr2          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                    pAddr1
     C                   parm                    pAddr2
     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
     C                   eval      pAddr1 = ARAd01
     C                   eval      pAddr2 = ARAd02
     C                   eval      pCity  = ARCy01
     C                   eval      pState = ARSt01
     C                   eval      pZip   = ARZp15
     C                   endif

      * RPG makes use of switches.  One switch "LR" originally stood for "last record"
      * LR flags the program and its dataspace as removable from memory 

     C                   eval      *InLR = *On

External links