RPG programming language
Encyclopedia
RPG is a high-level programming language (HLL)
High-level programming language
A high-level programming language is a programming language with strong abstraction from the details of the computer. In comparison to low-level programming languages, it may use natural language elements, be easier to use, or be from the specification of the program, making the process of...

 for business applications.

It has a long history, having been developed by IBM in 1959 as the Report Program Generator - a tool to replicate card processing on the IBM 1401
IBM 1401
The IBM 1401 was 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 electromechanical unit record equipment for processing data stored on punched cards...

 then updated to RPG II for the IBM System/3 in the late 1960s, and since evolved into an HLL equivalent to COBOL
COBOL
COBOL is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....

 and PL/I
PL/I
PL/I is a procedural, imperative computer programming language designed for scientific, engineering, business and systems programming applications...

. It remains a popular programming language on the IBM Power i platform where the current version, RPG IV (aka ILE RPG), provides a modern programming environment.

While IBM is the creator and primary vendor of RPG the language is available from other mainframe
Mainframe computer
Mainframes are powerful computers used primarily by corporate and governmental organizations for critical applications, bulk data processing such as census, industry and consumer statistics, enterprise resource planning, and financial transaction processing.The term originally referred to the...

 and microcomputer
Microcomputer
A microcomputer is a computer with a microprocessor as its central processing unit. They are physically small compared to mainframe and minicomputers...

 manufacturers, including Unisys
Unisys
Unisys Corporation , headquartered in Blue Bell, Pennsylvania, United States, and incorporated in Delaware, is a long established business whose core products now involves computing and networking.-History:...

.

Overview

An RPG program typically starts off with File Specifications, listing all files being written to, read from or updated, followed by Data Definition Specifications containing program elements such as Data Structures and dimensional arrays, much like a "Working-Storage" section of a COBOL
COBOL
COBOL is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....

 program or var statements in a Pascal program. This is followed by Calculation Specifications, which contain the actual meat of the code. 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 specifications.

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. 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" — from 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.

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 punched card
Punched card
A punched card, punch card, IBM card, or Hollerith card is a piece of stiff paper that contains digital information represented by the presence or absence of holes in predefined positions...

 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 1959. The name Report Program Generator was descriptive of the purpose of the language: generation of reports from data files, including matching record and sub-total reports.

FARGO
FARGO Programming Language
FARGO was the predecessor to the popular RPG programming language . FARGO was more of a utility program than a programming language, whereas RPG had a program generation process that produced an executable object.- A Transitional Tool :The idea behind FARGO was to facilitate ease of transition...

(Fourteen-o-one Automatic Report Generation Operation) was the predecessor to RPG on the IBM 1401
IBM 1401
The IBM 1401 was 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 electromechanical unit record equipment for processing data stored on punched cards...

 . Both languages were intended to facilitate ease of transition for IBM tabulating machine
Tabulating machine
The tabulating machine was an electrical device designed to assist in summarizing information and, later, accounting. Invented by Herman Hollerith, the machine was developed to help process data for the 1890 U.S. Census...

 (Tab) unit record equipment
Unit record equipment
Before the advent of electronic computers, data processing was performed using electromechanical devices called unit record equipment, electric accounting machines or tabulating machines. Unit record machines were as ubiquitous in industry and government in the first half of the twentieth century...

 technicians to the then new computers.

Tab machine technicians were accustomed to plugging wires into control panels
Plugboard
A plugboard, or control panel , is an array of jacks, or hubs, into which patch cords can be inserted to complete an electrical circuit. Control panels were used to direct the operation of some unit record equipment...

 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
Assembly language
An assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...

, COBOL
COBOL
COBOL is one of the oldest programming languages. Its name is an acronym for COmmon Business-Oriented Language, defining its primary domain in business, finance, and administrative systems for companies and governments....

 or FORTRAN. COBOL was a natural language-like business oriented language and FORTRAN was a language that facilitated mathematical applications. Other languages of the era included ALGOL
ALGOL
ALGOL is a family of imperative computer programming languages originally developed in the mid 1950s which greatly influenced many other languages and became the de facto way algorithms were described in textbooks and academic works for almost the next 30 years...

 and Autocoder
Autocoder
Autocoder was the name given to certain assemblers for a number of IBM computers of the 1950s and 1960s.The first Autocoders appear to have been the earliest assemblers to provide a macro facility....

 and a few years later PL/1. Assembler and COBOL were more common in mainframe business operations (System/360
System/360
The IBM System/360 was a mainframe computer system family first announced by IBM on April 7, 1964, and sold between 1964 and 1978. It was the first family of computers designed to cover the complete range of applications, from small to large, both commercial and scientific...

 models 30 and above) and RPG more commonly used by customers who were in transition from tabulating equipment (System/360 model 20).

Language evolution

RPG II
RPG II
RPG II is a version of the IBM RPG programming language. It was developed in the late 1960s and was offered on a number of different computers, including the IBM System/3, System/32, System/34, System/36, System/370, The Singer System 10, and the Wang VS Series. ICL also produced versions for its...

was introduced with the System/3
System/3
The IBM System/3 was a low-end business computer aimed at new customers and organizations that still used IBM 1400 series computers or unit record equipment...

 series of computers. It was later used on System/32
System/32
The IBM System/32 introduced in January 1975 was a low-end business computer. It was used primarily by small to midsize businesses for accounting applications.RPGII was the programming language for the machine....

, System/34
System/34
The IBM System/34 was a minicomputer marketed by IBM beginning in 1978. It was a multi-user, multi-tasking successor to the single-user System/32. Most notably, it included two very different processors, one based on System/32 and the second based on older System/3. Like the System/32 and the...

, and System/36
System/36
The IBM System/36 was a minicomputer marketed by IBM from 1983 to 2000. It was a multi-user, multi-tasking successor to the System/34. Like the System/34 and the older System/32, the System/36 was primarily programmed in the RPG II language...

, with an improved version of the language. ICL also produced a version on its VME/K operating system

RPG III was created for the System/38
System/38
The System/38 was a midrange computer server platform manufactured and sold by the IBM Corporation. The system offered a number of innovative features, and was the brainchild of IBM engineer Dr. Frank Soltis...

 and its successor the AS/400 . RPG III significantly departed from the original language, providing modern structured constructs like IF-ENDIF blocks, DO loops, and subroutine
Subroutine
In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....

s (RPG2 Supported Subroutines). RPG III was also available for larger systems including the IBM System/370 mainframe running OS/VS1
OS/VS1
Operating System/Virtual Storage 1, or OS/VS1,was an IBM mainframe computer operating system designed to be run on IBM System/370 hardware....

. It was also available from Unisys
Unisys
Unisys Corporation , headquartered in Blue Bell, Pennsylvania, United States, and incorporated in Delaware, is a long established business whose core products now involves computing and networking.-History:...

 for the VS/9
VS/9
VS/9 was a computer operating system available for the Univac 90/60, 90/70 and 90/80 mainframe during the late 1960s through 1980s. The 90/60 and 90/70 were repackaged Univac 9700 computers...

 operating system running on the Univac 90/60
UNIVAC 90/60
The Univac 90/60 series computer was a mainframe class computer manufactured by Sperry Corporation as a competitor to the IBM System 360 series of mainframe computers...

 mainframe.

DE/RPG or Data Entry RPG was exclusively available on the IBM 5280 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
System/38
The System/38 was a midrange computer server platform manufactured and sold by the IBM Corporation. The system offered a number of innovative features, and was the brainchild of IBM engineer Dr. Frank Soltis...

 and its successors. Instead, the DDS part had to be included into the RPG source itself.

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

RPG IV (aka RPGLE, aka ILE RPG) was released in 1994 and the name, officially, was 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 is the only version of RPG supported by IBM on its long-line of successors to the AS/400 system.

RPG IV, a modern language

In 2001, with the release of OS/400
OS/400
IBM i is an EBCDIC based operating system that runs on IBM Power Systems. It is the current evolution of the operating system named i5/OS which was originally named OS/400 when it was introduced with the AS/400 computer system in 1988....

 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. However, the free format only applies to the calculation specifications. F and D specifications still need to be in column-dependent format.

Today, RPG IV is a considerably more robust language. Editing can still be done via the simple green screen editor (even though syntax checking is not supported for features introduced from OS 7.1 onwards) or it can be edited via PC using IBM's Websphere Development Studio now named RDi (Rational Development Studio for i) a customized implementation of Eclipse. IBM is continually extending its capabilities and adding more built-in functions (BIFs). It has the ability to link to Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 objects, and i5/OS APIs; it can be used to write CGI
Common Gateway Interface
The Common Gateway Interface is a standard method for web servers software to delegate the generation of web pages to executable files...

 programs with the help of IBM's Cgidev2
Cgidev2
CGIDEV2 is a free and open source iSeries based program development toolkit that facilitates the development of interactive web-based programs using RPG ILE or Cobol as the back-end Common Gateway Interface language...

 web toolkit, RPGLIB (a collection of hundreds of pre-written RPG IV routines), CGILIB, the RPG Toolbox
Linoma Software
Linoma Software is the developer of managed file transfer and encryption solutions. Linoma Software’s customers are primarily made up of mid-sized companies, large enterprises and government entities including city, county and state government...

, 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.

Furthermore, with the implementation of the SQL Precompiler, current RPG developers can take advantage of IBM's cost-based SQE (SQL Query Engine). As opposed to the traditional F-Spec approach, where a developer identified a specific access path to a data set, a developer can now implement standard embedded SQL statements directly in the program. When compiled, the SQL Precompiler transforms the invalid embedded SQL statements into valid RPG statements that call the database manager programs that ultimately implement the query request.

OS/400
OS/400
IBM i is an EBCDIC based operating system that runs on IBM Power Systems. It is the current evolution of the operating system named i5/OS which was originally named OS/400 when it was introduced with the AS/400 computer system in 1988....

 was later renamed i5/OS to correspond with the new IBM
IBM
International Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...

 System i5 branding initiative; the 5 was later dropped in favor of just System i. In March 2008 i5/OS was renamed IBM i as part of the Power Systems
IBM Power Systems
Power Systems is the name of IBM's Power Architecture-based server line.Before the Power Systems line was announced on April 2, 2008, IBM had two distinct Power-based lines: the System i running IBM i - and the System p series running AIX or Linux.- History :IBM had two discrete Power Architecture...

 consolidation of System i and System p product lines. The new Power Systems also adopt more mainstream version numbers, substituting 6.1 for the twenty year old V1R1M0 notation. The latest release is now referred to as IBM i 7.1 and fully supports the RPG IV language, as well as many others. WebSphere Development Studio Client (WDSC) is now referred to as Rational Developer for i (RDi), of which three product levels are available. They are called Rational Developer for i (RDi), RDi Service Oriented Architecture (RDi SOA), and Rational Application Developer (RAD). The new lineup provides in more granular packaging all of the development tools and support previously offered by WDSC and WDSC Advanced Edition.

Some of the more unmodern features of the language include the dependency on the EBCDIC character sets which means that use of UTF-8 requires considerable effort and is quite risky (the programmer has to take responsibility not to get his/her character data mixed up with a single byte CCSID), whereas 16 bit characters (eg UTF-16) are supported directly via a separate datatype (Graphic).
The threadsafeness of the language is also a bit odd as the compiler team has solved this by giving each thread its own static storage, rather than make the RPG run-time environment re-entrant. This has been noted to meddle up the distinction between a thread and a process (making RPG IV threads a kind of hybrid between threads and processes).

Data types

RPG supports the following data types.
Data type Name Length Description
A Alphanumeric character 1 to 32,766 bytes Alphanumeric character
B Binary numeric 2 byte (16-bit)
4 bytes (32-bit)
Signed binary integer
D Date 10 bytes Date: year, month, day
F Floating point
Floating point
In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...

 numeric
4 bytes (32-bit)
8 bytes (64-bit)
Signed binary floating-point real
G Graphic character 1 to 32,766 bytes 16-bit graphic character (DBCS
DBCS
A double-byte character set is a character set that represents each character with 2 bytes. The DBCS supports national languages that contain a large number of unique characters or symbols...

 or EGCS)
I Integer numeric 1 byte (8-bit)
2 bytes (16-bit)
4 bytes (32-bit)
8 bytes (64-bit)
Signed binary integer
U Integer numeric 1 byte (8-bit)
2 bytes (16-bit)
4 bytes (32-bit)
8 bytes (64-bit)
Unsigned binary integer
P Packed decimal numeric 1 to 30 digits,
2 digits per byte plus sign
Signed fixed-point decimal number with integer and fraction digits
S Zoned decimal numeric 1 to 30 digits,
1 digit per byte
Signed fixed-point decimal number with integer and fraction digits
T Time 6, 12, or 14 bytes Time: hour, minute, second, microseconds
Z Timestamp
Timestamp
A timestamp is a sequence of characters, denoting the date or time at which a certain event occurred. A timestamp is the time at which an event is recorded by a computer, not the time of the event itself...

26 bytes Date and time:
  year, month, day, hour, minute, second, microseconds

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
F ARMstF1 IF E K 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" originally stood for "last record"
* LR actually flags the program and its dataspace as removable from memory.
C eval *InLR = *On


The same program using free calculations:

* "F" (file) specs define files and other i/o devices
FARMstF1 IF E K 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" 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" 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
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


As of V7R1 of the operating system, the above program could be (correctly, 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

Platforms

As stated above, the RPG programming language originally was introduced by IBM for their proprietary 1401, /360, /3, /32, /34, /36, /38 AS/400 and System i systems. There have also been implementations for the Digital VAX, Sperry Univac BC/7, Univac system 80, Siemens BS2000
BS2000
BS2000 is a mainframe computer operating system developed by Fujitsu Technology Solutions.Unlike other mainframe systems, BS2000/OSD provides exactly the same user and programming interface in all operating modes and regardless of whether it is running natively or as a guest system in a virtual...

, Burroughs B700, B1700, Hewlett Packard HP3000, ICL 2900 series, Honeywell 6220 and 2020, Four-Phase IV/70 and IV/90 series and WANG VS, as well as miscellaneous compilers & runtime environments for Unix-based systems (INFINITE 36 (formerly UNIBOL36)) and PCs (Baby/400, Lattice-RPG).

The latest platform to receive an RPG compiler is Windows .Net through the WINRPG compiler. This version contains extensions to RPG IV beyond that of the base IBM compiler. These extensions provide Windows and .Net hooks.

RPG II applications are still supported under the IBM z/VSE and z/OS
Z/OS
z/OS is a 64-bit operating system for mainframe computers, produced by IBM. It derives from and is the successor to OS/390, which in turn followed a string of MVS versions.Starting with earliest:*OS/VS2 Release 2 through Release 3.8...

 operating systems, HP MPE operating system on HP3000 and the OpenVMS
OpenVMS
OpenVMS , previously known as VAX-11/VMS, VAX/VMS or VMS, is a computer server operating system that runs on VAX, Alpha and Itanium-based families of computers. Contrary to what its name suggests, OpenVMS is not open source software; however, the source listings are available for purchase...

 operating system on VAX, Alpha, and Unisys
Unisys
Unisys Corporation , headquartered in Blue Bell, Pennsylvania, United States, and incorporated in Delaware, is a long established business whose core products now involves computing and networking.-History:...

 MCP
MCP (Burroughs Large Systems)
The MCP is the proprietary operating system of the Burroughs large systems including the Unisys Clearpath/MCP systems....

.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK