RPG or RPG IV is a native programming language for IBM's iSeries (aka AS400) minicomputer system. In 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.
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.
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.
RPG II was ported to the 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 E-Server 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) was released and the name, officially, was no longer an acronym. RPG IV replaced the limiting punch-card type layout with free-format text-capable entry, 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).
The following program receives a customer number as an input parameter and returns the name and address as output parameters.
FARMstF1 UF E Disk Rename(ARMST:RARMST)
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 *entry plist C parm pCusNo C parm pName C parm pAddr1 C parm pAddr2 C parm pCity C parm pState C parm pZip
C pCusNo chain ARMstF1
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
C eval *InLR = *On