IBM RPG
   HOME

TheInfoList



OR:

RPG is a
high-level programming language In computer science, a high-level programming language is a programming language with strong abstraction from the details of the computer. In contrast to low-level programming languages, it may use natural language ''elements'', be easier to us ...
for business applications, introduced in 1959 for the
IBM 1401 The IBM 1401 is a variable-wordlength decimal computer that was announced by IBM on October 5, 1959. The first member of the highly successful IBM 1400 series, it was aimed at replacing unit record equipment for processing data stored on pu ...
. It is most well known as the primary programming language of IBM's
midrange computer Midrange computers, or midrange systems, were a class of computer systems that fell in between mainframe computers and microcomputers. This class of machine emerged in the 1960s, with models from Digital Equipment Corporation ( PDP line), Data Ge ...
product line, including the IBM i
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also i ...
. RPG has traditionally featured a number of distinctive concepts, such as the program cycle, and the column-oriented syntax. The most recent version is RPG IV, which includes a number of modernization features, including free-form syntax.


Platforms

The RPG programming language originally was created by IBM for their 1401 systems. They also produced an implementation for the System/360, and it became the primary programming language for their
midrange computer Midrange computers, or midrange systems, were a class of computer systems that fell in between mainframe computers and microcomputers. This class of machine emerged in the 1960s, with models from Digital Equipment Corporation ( PDP line), Data Ge ...
product line, (the
System/3 The IBM System/3 was an IBM midrange computer introduced in 1969, and marketed until 1985. It was produced by IBM Rochester in Minnesota as a low-end business computer aimed at smaller organizations that still used IBM 1400 series computers or u ...
,
System/32 The IBM System/32 (IBM 5320) introduced in January 1975 was a midrange computer with built-in display screen, disk drives, printer, and database report software. It was used primarily by small to midsize businesses for accounting applications. R ...
, System/34,
System/38 The System/38 is a discontinued minicomputer and midrange computer manufactured and sold by IBM. The system was announced in 1978. The System/38 has 48-bit addressing, which was unique for the time, and a novel integrated database system. It w ...
,
System/36 The IBM System/36 (often abbreviated as S/36) was a midrange computer marketed by IBM from 1983 to 2000 - a multi-user, multi-tasking successor to the System/34. Like the System/34 and the older System/32, the System/36 was primarily prog ...
and
AS/400 The IBM AS/400 (Application System/400) is a family of midrange computers from IBM announced in June 1988 and released in August 1988. It was the successor to the System/36 and System/38 platforms, and ran the OS/400 operating system. Lower-cos ...
). There have also been implementations for DEC
VAX VAX (an acronym for Virtual Address eXtension) is a series of computers featuring a 32-bit instruction set architecture (ISA) and virtual memory that was developed and sold by Digital Equipment Corporation (DEC) in the late 20th century. The V ...
, Sperry Univac BC/7, Univac system 80, Siemens
BS2000 BS2000 is an operating system for IBM 390-compatible mainframe computers developed in the 1970s by Siemens (Data Processing Department EDV) and from early 2000s onward by Fujitsu Technology Solutions. Unlike other mainframe systems, BS2000 p ...
, Burroughs B700,
B1700 The Burroughs B1000 Series was a series of mainframe computers, built by the Burroughs Corporation, and originally introduced in the 1970s with continued software development until 1987. The series consisted of three major generations which were t ...
, Hewlett Packard
HP 3000 The HP 3000 series is a family of 16-bit and 32-bit minicomputers from Hewlett-Packard. It was designed to be the first minicomputer with full support for time-sharing in the hardware and the operating system, features that had mostly been limite ...
, the ICL 2900 series, Honeywell 6220 and 2020, Four-Phase IV/70 and IV/90 series, Singer System 10 and
WANG VS Wang Laboratories was a US computer company founded in 1951 by An Wang and G. Y. Chu. The company was successively headquartered in Cambridge, Massachusetts (1954–1963), Tewksbury, Massachusetts (1963–1976), and finally in Lowell, Massachusett ...
, as well as miscellaneous compilers and runtime environments for Unix-based systems, such as Infinite36 (formerly Unibol 36), and PCs (Baby/400, Lattice-RPG). RPG II applications are still supported under the IBM
z/VSE VSEn (''Virtual Storage Extended'') is an operating system for IBM mainframe computers, the latest one in the DOS/360 lineage, which originated in 1965. DOS/VSE was introduced in 1979 as a successor to DOS/VS; in turn, DOS/VSE was succeeded by ...
and
z/OS z/OS is a 64-bit operating system for IBM z/Architecture mainframes, introduced by IBM in October 2000. It derives from and is the successor to OS/390, which in turn was preceded by a string of MVS versions.Starting with the earliest: * ...
operating systems,
Unisys Unisys Corporation is an American multinational information technology (IT) services and consulting company headquartered in Blue Bell, Pennsylvania. It provides digital workplace solutions, cloud, applications, and infrastructure solutions, ...
MCP, Microsoft Windows and OpenVMS.


History


Background

Originally developed by IBM in 1959, the name ''Report Program Generator'' was descriptive of the purpose of the language: generation of reports from data files.
FOLDOC The Free On-line Dictionary of Computing (FOLDOC) is an online, searchable, encyclopedic dictionary of computing subjects. History FOLDOC was founded in 1985 by Denis Howe and was hosted by Imperial College London. In May 2015, the site was up ...
accredits Wilf Hey with work at IBM that resulted in the development of RPG. FARGO (Fourteen-o-one Automatic Report Generation Operation) was the predecessor to RPG on the
IBM 1401 The IBM 1401 is a variable-wordlength decimal computer that was announced by IBM on October 5, 1959. The first member of the highly successful IBM 1400 series, it was aimed at replacing unit record equipment for processing data stored on pu ...
. Both languages were intended to facilitate ease of transition for IBM
tabulating machine The tabulating machine was an electromechanical machine designed to assist in summarizing information stored on punched cards. Invented by Herman Hollerith, the machine was developed to help process data for the 1890 U.S. Census. Later model ...
(Tab)
unit record equipment Starting at the end of the nineteenth century, well before the advent of electronic computers, data processing was performed using electromechanical machines collectively referred to as unit record equipment, electric accounting machines (EAM) or ...
technicians to the then-new computers. Tab machine technicians were accustomed to plugging wires into control panels to implement input, output, control and counter operations (add, subtract, multiply, divide). Tab machines programs were executed by impulses emitted in a machine cycle; hence, FARGO and RPG emulated the notion of the machine cycle with the program cycle. RPG was superior to and rapidly replaced FARGO as the report generator program of choice. The alternative languages generally available at the time were
Assembler Assembler may refer to: Arts and media * Nobukazu Takemura, avant-garde electronic musician, stage name Assembler * Assemblers, a fictional race in the ''Star Wars'' universe * Assemblers, an alternative name of the superhero group Champions of ...
, COBOL or FORTRAN. Assembler and COBOL were more common in mainframe business operations ( System/360 models 30 and above) and RPG more commonly used by customers who were in transition from tabulating equipment (System/360 model 20).


RPG II

''RPG II'' was introduced with the
System/3 The IBM System/3 was an IBM midrange computer introduced in 1969, and marketed until 1985. It was produced by IBM Rochester in Minnesota as a low-end business computer aimed at smaller organizations that still used IBM 1400 series computers or u ...
series of computers. It was later used on
System/32 The IBM System/32 (IBM 5320) introduced in January 1975 was a midrange computer with built-in display screen, disk drives, printer, and database report software. It was used primarily by small to midsize businesses for accounting applications. R ...
, System/34, and
System/36 The IBM System/36 (often abbreviated as S/36) was a midrange computer marketed by IBM from 1983 to 2000 - a multi-user, multi-tasking successor to the System/34. Like the System/34 and the older System/32, the System/36 was primarily prog ...
, with an improved version of the language. RPG II was also available for larger systems, including the
IBM System/370 The IBM System/370 (S/370) is a model range of IBM mainframe computers announced on June 30, 1970, as the successors to the System/360 family. The series mostly maintains backward compatibility with the S/360, allowing an easy migration path ...
mainframe running DOS/VSE (then VSE/SP, VSE/ESA, and
z/VSE VSEn (''Virtual Storage Extended'') is an operating system for IBM mainframe computers, the latest one in the DOS/360 lineage, which originated in 1965. DOS/VSE was introduced in 1979 as a successor to DOS/VS; in turn, DOS/VSE was succeeded by ...
). ICL also produced a version on its VME/K operating system. In the early days of RPG, its major strength was the ''program cycle''. A programmer would write code to process an individual record, and the program cycle would execute the change against every record of a file, taking care of the control flow. At that time each record (individual punched card) would be compared to each line in the program, which would act upon the record, or not, based upon whether that line had an "indicator" turned "on" or "off". The indicator consisted of a set of logical variables numbered 01–99 for user-defined purposes, or other smaller sets based upon record, field, or report processing functions. The concept of level breaks and matching records is unique to the RPG II language, and was originally developed with card readers in mind. The matching record feature of the cycle enabled easy processing of files having a header-to-detail relationship. RPG programs written to take advantage of the program cycle could produce complex reports with far fewer lines of computer code than programs written in COBOL and other business-centric languages. The program File Specifications, listed all files being written to, read from or updated, followed by
Data Definition Specification In computing, a data definition specification (DDS) is a guideline to ensure comprehensive and consistent data definition. It represents the attributes required to quantify data definition. A comprehensive data definition specification encompasses ...
s containing program elements such as Data Structures and dimensional arrays, much like a "Working-Storage" section of a COBOL program. This is followed by Calculation Specifications, which contain the executable instructions. Output Specifications can follow which can be used to determine the layout of other files or reports. Alternatively files, some data structures and reports can be defined externally, mostly eliminating the need to hand code input and output (" I/O") specifications.


RPG III

''RPG III'' was created for the
System/38 The System/38 is a discontinued minicomputer and midrange computer manufactured and sold by IBM. The system was announced in 1978. The System/38 has 48-bit addressing, which was unique for the time, and a novel integrated database system. It w ...
and its successor the
AS/400 The IBM AS/400 (Application System/400) is a family of midrange computers from IBM announced in June 1988 and released in August 1988. It was the successor to the System/36 and System/38 platforms, and ran the OS/400 operating system. Lower-cos ...
. RPG III significantly departed from the original language, providing modern structured constructs like IF-ENDIF blocks, DO loops, and subroutines. RPG III was also available for larger systems including the
IBM System/370 The IBM System/370 (S/370) is a model range of IBM mainframe computers announced on June 30, 1970, as the successors to the System/360 family. The series mostly maintains backward compatibility with the S/360, allowing an easy migration path ...
mainframe running
OS/VS1 Operating System/Virtual Storage 1, or OS/VS1, is a discontinued IBM mainframe computer operating system designed to be run on IBM System/370 hardware. It was the successor to the Multiprogramming with a Fixed number of Tasks (MFT) option of Sys ...
. It was also available from
Unisys Unisys Corporation is an American multinational information technology (IT) services and consulting company headquartered in Blue Bell, Pennsylvania. It provides digital workplace solutions, cloud, applications, and infrastructure solutions, ...
for the
VS/9 VS/9 is a computer operating system for the UNIVAC Series 90 mainframes (90/60, 90/70, and 90/80), used during the late 1960s through 1980s. The 90/60 and 90/70 were repackaged Univac 9700 computers. After the RCA acquisition by Sperry, it ...
operating system running on the
UNIVAC Series 90 The Univac 90/60 system front panel The Univac Series 90 is an obsolete family of mainframe class computer systems from UNIVAC first introduced in 1973. The low end family members included the 90/25, 90/30 and 90/40 that ran the OS/3 operating s ...
mainframes. Since the introduction of the
IBM System/38 The System/38 is a discontinued minicomputer and midrange computer manufactured and sold by IBM. The system was announced in 1978. The System/38 has 48-bit addressing, which was unique for the time, and a novel integrated database system. It w ...
in 1979 most RPG programmers discontinued use of the cycle in favor of controlling program flow with standard looping constructs, although IBM has continued to provide backward compatibility for the cycle.


DE/RPG

''DE/RPG'' or Data Entry RPG was exclusively available on the
IBM 5280 The IBM 5280 was designed to compete with the data entry products that were available at the time. The IBM 3740 was the major data entry capability available to convert the data collected at the source, whether high volume, distributed or locally g ...
series of data-entry workstations in the early '80s. It was similar to RPG III but lacking external Data Descriptions (DDS) to describe data(files) like on the System/38 and its successors. Instead, the DDS part had to be included into the RPG source itself.


RPG/400

''RPG/400'' was effectively RPG III running on AS/400. IBM renamed the RPG compiler as "RPG/400" but at the time of its introduction it was identical to the RPG III compiler on System/38. Virtually all IBM products were rebranded as xxx/400 and the RPG compiler was no exception. RPG III compiled with the RPG/400 compiler offered nothing new to the RPG III language until IBM began development of new operation codes, such as SCAN, CAT and XLATE after several years of AS/400 availability. These enhancements to RPG III were not available in the System/38 version of RPG III.


RPG IV and ILE RPG

''RPG IV'', a.k.a. ''RPGLE'' ) was released in 1994 as part of the V3R2 release of
OS/400 IBM i (the ''i'' standing for ''integrated'') is an operating system developed by IBM for IBM Power Systems. It was originally released in 1988 as OS/400, as the sole operating system of the IBM AS/400 line of systems. It was renamed to i5/OS ...
(now known as IBM i). With the release of RPG IV, the RPG name was officially no longer an initialism. RPG IV offered a greater variety of expressions within its Extended Factor-2 Calculation Specification and, later in life, its free-format Calculation Specifications and Procedure syntax. RPG IV in the Integrated Language Environment framework in known at ILE RPG, and user guides explain the nuances of both. RPG IV and ILE RPG are supported by IBM in the current IBM i platform. In 2001, with the release of
OS/400 IBM i (the ''i'' standing for ''integrated'') is an operating system developed by IBM for IBM Power Systems. It was originally released in 1988 as OS/400, as the sole operating system of the IBM AS/400 line of systems. It was renamed to i5/OS ...
V5R1, RPG IV offered greater freedom for calculations than offered by the Extended Factor-2 Calculation Specification: a ''free-format'' text-capable source entry, as an alternative to the original column-dependent source format. The "/FREE" calculation did not require the operation code to be placed in a particular column; the operation code is optional for the EVAL and CALLP operations; and syntax generally more closely resembles that of mainstream, general-purpose programming languages. Until November 2013, the free format applied exclusively to the calculation specifications. With the IBM i V7R1 TR7 upgrade to the language, the "/free" and "/end-free" calculations are no longer necessary, and the language has finally broken the ties to punched cards. IBM Rational Developer for i (RDi), an Eclipse-based
Integrated Development Environment An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of at least a source code editor, build automation tools ...
, is recommended by IBM for RPG development. RDi is part of IBM Rational Development Studio for i, a family of Integrated Language Environment (ILE) compilers. The Source Entry Utility (SEU) text editor is no longer recommended for RPG development, and development ceased after IBM i 6.1. Other legacy developer tools include CODE/400 (based on IBM WorkFrame/2) and VisualAge for RPG.


Continuing Language Enhancements

IBM continues to enhance the RPG language via software releases and intra-release “technology refreshes” (TRs). More built-in functions (BIFs) have been added. It has the ability to link to
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mos ...
objects, and IBM i
API An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how ...
s; it can be used to write CGI programs with the help of IBM's Cgidev2 Web toolkit, the RPG Toolbox, and other commercial Web-enabled packages. Even with the changes, it retains a great deal of backward compatibility, so an RPG program written 37 years ago could run today with little or no modification. The SQL precompiler allows current RPG developers to take advantage of IBM's cost-based SQE (SQL Query Engine). With the traditional F-Spec approach a developer had to identify a specific access path to a data set, now they can implement standard embedded SQL statements directly in the program. When compiled, the SQL precompiler transforms SQL statements into RPG statements which call the database manager programs that ultimately implement the query request. The RPG IV language is based on the
EBCDIC Extended Binary Coded Decimal Interchange Code (EBCDIC; ) is an eight- bit character encoding used mainly on IBM mainframe and IBM midrange computer operating systems. It descended from the code used with punched cards and the corresponding ...
character set, but also supports UTF-8, UTF-16 and many other character sets. The threadsafe aspects of the language are considered idiosyncratic by some as the compiler team has addressed threads by giving each thread its own static storage, rather than make the RPG run-time environment re-entrant. This has been noted to muddle the distinction between a thread and a process (making RPG IV threads a kind of hybrid between threads and processes). In 2010, IBM launched ''RPG Open Access'', also known as ''Rational Open Access: RPG Edition''. It allows new I/O handlers to be defined by a programmer - enabling data to be read from and written to sources which RPG does not provide inbuilt support for.


Data types

RPG supports the following data types. Note:
The character in the ''data type'' column is the character that is encoded on the Definition Specification in the column designated for data type. To compare, in a language like C where definitions of variables are free-format and would use a keyword such as int to declare an integer variable, in RPG, a variable is defined with a fixed-format Definition Specification. In the Definition Specification, denoted by a letter D in column 6 of a source line, the data type character would be encoded in column 40. Also, if the ''data type'' character is omitted, that is, left blank, the default is A if no decimal positions are specified, P when decimal positions are specified for stand-along fields, and S (ZONED) when decimal positions are specified within a data structure.


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. The same program is shown later with gradually more modern versions of the syntax and gradually more relaxed rules.
      * 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" (data) 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
The same program using free calculations available starting in V5R1:
      * "F" (file) specs define files and other i/o devices
     FARMstF1   IF   E        K     Disk    Rename(ARMST:RARMST)

      * "D" (data) specs are used to define variables and parameters
      * The "prototype" for the program is in a separate file
      * allowing other programs to call it
      /copy cust_pr
      * The "procedure interface" describes the *ENTRY parameters
     D getCustInf      PI
     D  pCusNo                        6p 0   const
     D  pName                        30a
     D  pAddr1                       30a
     D  pAddr2                       30a
     D  pCity                        25a
     D  pState                        2a
     D  pZip                         10a
      /free
        // The "chain" command is used for random access of a keyed file
        chain pCusNo ARMstF1;

        // If a record is found, move fields from the file into parameters
        if %found;
           pName  = ARNm01;
           pAddr1 = ARAd01;
           pAddr2 = ARAd02;
           pCity  = ARCy01;
           pState = ARSt01;
           pZip   = ARZp15;
        endif;

      // RPG makes use of switches.  One switch "LR" originally stood for "last record"
      // LR actually flags the program and its dataspace as removable from memory.
        *InLR = *On;
      /end-free
Assume the ARMSTF1 example table was created using the following SQL Statement: create table armstf1 (arcnum decimal(7,0), arname char(30), aradd1 char(30), aradd2 char(30), arcity char(25), arstte char(2), arzip char(10)) The same program using free calculations and embedded SQL:
      * RPG IV no longer requires the use of the *INLR indicator to terminate a program.
      * by using the MAIN keyword on the "H" (Header) spec, and identifying the "main" or
      * entry procedure name, the program will begin and end normally without using the
      * decades-old RPG Cycle and instead a more "C like" begin and end logic.
     H  MAIN(getCustInf)
      * "D" (data) specs are used to define variables and parameters
      * The "prototype" for the program is in a separate file
      * allowing other programs to call it
      /copy cust_pr
      * The "procedure interface" describes the *ENTRY parameters
     P getCustInf      B
     D getCustInf      PI
     D  pCusNo                        6p 0   const
     D  pName                        30a
     D  pAddr1                       30a
     D  pAddr2                       30a
     D  pCity                        25a
     D  pState                        2a
     D  pZip                         10a
      /free
        exec sql select arName, arAddr1, arAdd2, arCity, arStte, arZip
                 into  :pName, :pAddr1, :pAddr2, :pCity, :pState, :pZip
                 from   ARMstF1
                 where  arCNum = :pCusNo
                 for fetch only
                 fetch first 1 row only
                 optimize for 1 row
                 with CS;
      /end-free
     P GetCustInf      E
As of V7R1 of the operating system, the above program would not necessarily need the prototype in a separate file, so it could be completely written as: H main(GetCustInf) D ARMSTF1 E DS P GetCustInf B D GetCustInf PI extpgm('CUS001') D inCusNo like(arCNum) const D outName like(arName) D outAddr1 like(arAdd1) D outAddr2 like(arAdd2) D outCity like(arCity) D outState like(arStte) D outZip like(arZip) /free exec sql select arName, arAdd1, arAdd2, arCity, arStte, arZip into :outName, :outAddr1, :outAddr2, :outCity, :outState, :outZip from ARMSTF1 where arCNum = :inCusNo fetch first 1 row only with CS use currently committed; /end-free P GetCustInf E Lastly, if you apply the compiler PTFs related Technology Refresh 7 (TR7) to your 7.1 operating system, then the above program can be coded completely in free-form, as follows: ctl-opt main(GetCustInf); dcl-ds ARMSTF1 ext end-ds; dcl-proc GetCustInf; dcl-pi *n extpgm('CUS001'); inCusNo like(arCNum) const; outName like(arName); outAddr1 like(arAdd1); outAddr2 like(arAdd2); outCity like(arCity); outState like(arStte); outZip like(arZip); end-pi; exec sql select arName, arAdd1, arAdd2, arCity, arStte, arZip into :outName, :outAddr1, :outAddr2, :outCity, :outState, :outZip from ARMSTF1 where arCNum = :inCusNo fetch first 1 row only with CS use currently committed; return; end-proc;


See also

*
IBM RPG II RPG II is a very early and popular version of the IBM RPG programming language. It was developed in the late 1960s and designed to work on the smallest IBM systems of the time such as the IBM 1130, IBM System/3, System/32, System/34, System/36. ...


References


Further reading

* * * * *


External links

* "This redbook is focused on RPG IV as a modern, thriving, and rich application development language for the 21st century."
Midrange.com
nbsp;— A large number of code examples are available here
RPGPGM.COM
nbsp;— An extensive resource of articles giving examples of RPG code and related programming
RPG Open
nbsp;— Free (open source) resources for RPG IV and IBM i application development. * *
RPG II for MVS, OS/390 and z/OS
nbsp;— Status of the IBM RPG II product in z/OS {{DEFAULTSORT:Ibm Rpg High-level programming languages RPG RPG RPG Programming languages created in 1959