RPG programming language
From Free net encyclopedia
RPG is a native programming language for IBM's iSeries servers - the latest generation of midrange servers which included System/38, System/36, AS/400, iSeries and System i5 systems. Its latest incarnation is RPG IV which includes prototyped functions and procedures, static and dynamic binding, access to C routine libraries, dynamic link libraries, and fully recursive and re-entrant code.
Contents |
Overview
RPG (aka RPG IV aka RPGLE) is the mainstay programming language of the IBM iSeries platform. Originally designed as a query tool, IBM has enhanced the language to become a full-fledged, powerful programming language.
An RPG program typically starts off with a File Specification, listing all files being written to, read from or updated, followed by a Data Definition Specification containing program elements such as Data Structures and dimensional arrays (much like a "Working-Storage" section of a COBOL program or var statements in a C program). This is followed by the Calculation Specification, which contains the actual meat of the code. Output Specifications can follow which can be used to determine the layout of a report or the report can be defined externally.
In the early days of RPG, its major strength was known as the program 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. Today, most RPG programmers avoid using the cycle in favor of controlling the flow of the program with standard looping constructs.
History
RPG is one of the few languages created for punch card machines that is still in common use today. This is because the language has evolved considerably over time. 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/360 - as RPG II.
Because the language syntax was based on the plug-boards used to program unit record equipment, and the System/3 was initially developed as a successor to plug-board 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 tighter integration with the integrated database. This language became 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 1994, RPG IV (aka RPGLE aka RPG/ILE) was released and the name, officially, was no longer an acronym. RPG IV offered a greater variety of expressions within its new Extended Factor-2 Calculation Specification.
In 2001, with the release of OS/400 V5R1, RPG IV offered even 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 does 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.
Today, RPG IV is a considerably more robust language. Editing can still be done via the simple editor or it can edited via PC using IBM's Websphere Development Studio. IBM is continually extending its capabilities and adding more built-in functions (BIFs). It has the ability to link to Java objects (See IBM's RPG Reference Manual ), and OS/400 APIs; it can be used to write CGI programs with the help of IBM's Cgidev2 web toolkit, RPG xTools [1] CGILIB and other commercial Web enabled packages. Even with the changes it retains a great deal of backward compatibility, so an RPG program written 35 years ago could run today with little or no modification.
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
The same program using free calculations:
* "F" (file) specs define files and other i/o devices FARMstF1 UF E Disk Rename(ARMST:RARMST) * "D" 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" stands for // "last record". This ends program execution. *InLR = *On; /end-free
Platforms
As stated above, the RPG programming language originally was introduced by IBM for their proprietary 1401, /32, /34, /36, /38, AS/400, and iSeries systems. But there have also been implementations for the Digital VAX, Sperry Univac BC/7, Univac system 80, Siemens BS2000, Burroughs B1700, Hewlett Packard HP3000, ICL 2900 series, and WANG VS, as well as miscellaneous compilers for Unix-based systems (Unibol) and PCs (Baby/400, Lattice-RPG).
RPG II applications are still supported under the HP OpenVMS operating system on VAX, Alpha, and Integrity processors by the third party Migration RPG compiler.
Template:Major programming languages smallde:RPG (Programmiersprache) es:Lenguaje de programación RPG fr:Générateur automatique de programmes it:RPG (linguaggio di programmazione) nl:RPG (programmeertaal) pl:RPG (język programowania)