RPG programming language

RPG or RPG IV is a native programming language for IBM's iSeries (aka AS400) minicomputer system. Its latest incarnation includes prototyped functions and procedures, static and dynamic binding, access to C routine libraries, dynamic link libraries, and fully recursive and re-entrant code.

Overview

An RPG program typically starts off with a File Specification, listing all files being written to, read from or updated, followed by an Input Specification containing program elements such as Data Structures and dimensional arrays. This is followed by the Calculation Specification, which contains the actual meat of the code, and finally the Output Specifications which can be used to determine the layout of the report.

The major strength of RPG is known as "The Cycle": every RPG program executes within an implied loop, which can apply the program to every record of a file. Alternately, "The Cycle" can make an interactive program continue to run until explicitly stopped.

The other distinguishing characteristic of RPG is that it, to a far greater extent than COBOL or FORTRAN, is column-dependent.

History

RPG, is one of the few languages created for punch card machines that is still in common use today. It was originally developed by IBM in the 1960s and ran on the popular IBM 1401. Originally, RPG was an acronym for Report program generator, descriptive of the purpose of the language: generation of reports from data files, including matching record and sub-total reports.

The alternative languages generally available at the time were either COBOL or BASIC, one verbose, the other a poor tool for development, so RPG became pre-eminent on IBM hardware.

RPG was further developed by IBM for their range of mainframe systems, especially the S/390 - as RPG II.

Because the language syntax was based on the plugboards used to program unit record equipment, and the System/3 was initially developed as a successor to plugboard-programmable unit record machines, RPG II was ported to the System/3, System/32, System/34, and System/36, while an improved version of the language, RPG III, was created for the System/38 and its successor the AS/400 (a mid-range machine, now evolved into the eServer iSeries) and became RPG/400 with a much cleaner syntax, and better file/database reading capabilities. This language was the mainstay of development on the AS/400, and its editor was a simple line editor with prompt templates for each specification (type of instruction).

RPG III significantly departed from the original language, providing modern structured constructs like IF-ENDIF blocks, DO loops, and subroutines.

In 1998 RPG IV (aka RPG/LE aka RPG/ILE) was released and the name, officially, was no longer an acronym. RPG IV offered a free-format text-capable source entry, as an alternative to the orignal column-dependent source format, and a greater variety of expressions within its new Extended Calculation Specification.

RPG has thrived on the object-oriented API of the OS/400 operating system to such an extent that everything is a file (somewhat similar to the Unix philosophy): the terminal screen can be updated (with sub windows) by simply writing to a file (of type *DISPLAY).

Example code

The following program receives a customer number as an input parameter and returns the name and address as output parameters.


      * Historically RPG is columnar in nature, though free-formatting
      * is 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
     FARMstF1   UF   E             Disk    Rename(ARMST:RARMST)

      * "D" specs are used to define variables
     D pCusNo          S              6p 0
     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" stands for 
      * "last record".  This ends program execution.
     C                   eval      *InLR = *On
 
de:RPG (Programmiersprache)

es:RPG (lenguaje de programación) it:RPG (linguaggio di programmazione) nl:Programmeertaal RPG pl:RPG (język programowania)

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools