Paradigm | Multi-paradigm |
---|---|
Developer | IBM |
First appeared | 1959 |
Stable release | RPG IV version 7 release 4 / October 6, 2020 |
Typing discipline | Strong, static |
OS | CPF, SSP, OS/400, IBM i, OS/VS1, z/OS, DOS/VSE, VSE/SP, VSE/ESA, z/VSE, VS/9, PRIMOS, OpenVMS, Wang VS, Burroughs MCP, HP MPE, MS-DOS, OS/2, Microsoft Windows |
Dialects | |
RPG, RPG II, RPG III, RPG 400, RPG IV, RPG/ILE; RPG/Free, Baby/36, Baby/400, Lattice RPG, VAX RPG II | |
Influenced by | |
9PAC, FARGO |
RPG is a high-level programming language for business applications, introduced in 1959 for the IBM 1401. It is most well known as the primary programming language of IBM's midrange computer product line, including the IBM i operating system. [1] RPG has traditionally featured a number of distinctive concepts, such as the program cycle, and the column-oriented syntax. [2] The most recent version is RPG IV, which includes a number of modernization features, including free-form syntax. [3]
The RPG programming language originally was created by IBM for their 1401 systems. IBM later produced implementations for the 7070/72/74 [4] [5] and System/360; [6] RPG II became the primary programming language for their midrange computer product line, (the System/3, System/32, System/34, System/38, System/36 and AS/400). There have also been implementations for DEC VAX, Sperry Univac BC/7, Univac system 80, Siemens BS2000, Burroughs B700, B1700, Hewlett Packard HP 3000, the ICL 2900 series, Honeywell 6220 and 2020, Four-Phase IV/70 and IV/90 series, Singer System 10 and WANG VS, 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 [7] and z/OS operating systems, [8] Unisys MCP, [9] Microsoft Windows [10] and OpenVMS. [11]
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. [12] FOLDOC accredits Wilf Hey with work at IBM that resulted in the development of RPG. [13] FARGO (Fourteen-o-one Automatic Report Generation Operation) was the predecessor to RPG on the IBM 1401.
Both languages were intended to facilitate ease of transition for IBM tabulating machine (Tab) unit record equipment 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.
IBM later implemented RPG(7070-RG-902), but not FARGO, on the IBM 7070/72/74. [14] [15]
The alternative languages generally available at the time were Assembler, 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 was introduced about 1969 with the System/3 series of computers. It was later used on System/32, System/34, and System/36, with an improved version of the language. RPG II was also available for larger systems, including the IBM System/370 mainframe running DOS/VSE (then VSE/SP, VSE/ESA, and z/VSE). 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 Specifications 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 was created for the System/38 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 subroutines. RPG III was also available for larger systems including the IBM System/370 mainframe running OS/VS1. It was also available from Unisys for the VS/9 operating system running on the UNIVAC Series 90 mainframes.
Since the introduction of the IBM System/38 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 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 and its successors. Instead, the DDS part had to be included into the RPG source itself.
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 System/38 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, a.k.a. RPG ILE [16] ) was released in 1994 as part of the V3R2 release of OS/400 (now known as IBM i). [17] [18]
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 is known as ILE RPG, and user guides explain the nuances of both. [19] [20] [21] RPG IV and ILE RPG are supported by IBM in the current IBM i platform. [22]
In 2001, with the release of OS/400 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. [23] 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), [24] an Eclipse-based Integrated Development Environment, is recommended by IBM for RPG development. [25] The Source Entry Utility (SEU) text editor is no longer recommended for RPG development, and development ceased after IBM i 6.1. [26] Other legacy developer tools include CODE/400 (based on IBM WorkFrame/2) and VisualAge for RPG.
IBM continues to enhance the RPG language [27] via software releases and intra-release “technology refreshes” (TRs). [28] [29] More built-in functions (BIFs) have been added. It has the ability to link to Java objects, [30] and IBM i APIs; it can be used to write CGI programs with the help of IBM's Cgidev2 Web toolkit, [31] 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 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. [32]
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.
Data type | Name | Length | Description |
---|---|---|---|
A | Alphanumeric character | 1 to 16,773,104 bytes (fixed) 1 to 16,773,100 bytes (varying-length) | Alphanumeric character |
B | Binary numeric | 1 byte (8-bit) 2 byte (16-bit) 4 bytes (32-bit) 8 bytes (64-bit) | Signed binary integer |
C | UCS-2 character | 1 to 8,386,552 characters (fixed) 1 to 8,386,550 characters (varying) | 16-bit UCS-2 character (DBCS or EGCS) |
D | Date | 10 bytes | Date: year, month, day |
F | Floating point numeric | 4 bytes (32-bit) 8 bytes (64-bit) | Signed binary floating-point real |
G | Graphic character | 1 to 8,386,552 characters (fixed) 1 to 8,386,550 characters (varying) | 16-bit graphic character (DBCS or EGCS) |
I | Integer numeric | 1 byte (8-bit) 2 bytes (16-bit) 4 bytes (32-bit) 8 bytes (64-bit) | Signed binary integer |
N | Character indicator | 1 byte | '1' = TRUE '0' = FALSE |
O | Object | Size undisclosed | Object reference |
P | Packed decimal numeric | 1 to 63 digits, 2 digits per byte plus sign | Signed fixed-point decimal number with integer and fraction digits |
S | Zoned decimal numeric | 1 to 63 digits, 1 digit per byte | Signed fixed-point decimal number with integer and fraction digits |
T | Time | 8 bytes | Time: hour, minute, second |
U | Integer numeric | 1 byte (8-bit) 2 bytes (16-bit) 4 bytes (32-bit) 8 bytes (64-bit) | Unsigned binary integer |
Z | Timestamp | 26 bytes | Date and time: year, month, day, hour, minute, second, microseconds |
* | Basing-Pointer Procedure-Pointer System-Pointer | 16 bytes | Address to Data Address to Activated Procedure Address to Object |
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:
createtablearmstf1(arcnumdecimal(7,0),arnamechar(30),aradd1char(30),aradd2char(30),arcitychar(25),arsttechar(2),arzipchar(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:
Hmain(GetCustInf)DARMSTF1EDSPGetCustInfBDGetCustInfPIextpgm('CUS001')DinCusNolike(arCNum)constDoutNamelike(arName)DoutAddr1like(arAdd1)DoutAddr2like(arAdd2)DoutCitylike(arCity)DoutStatelike(arStte)DoutZiplike(arZip)/freeexecsqlselectarName,arAdd1,arAdd2,arCity,arStte,arZipinto:outName,:outAddr1,:outAddr2,:outCity,:outState,:outZipfromARMSTF1wherearCNum=:inCusNofetchfirst1rowonlywithCSusecurrentlycommitted;/end-freePGetCustInfE
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-optmain(GetCustInf);dcl-dsARMSTF1extend-ds;dcl-procGetCustInf;dcl-pi*nextpgm('CUS001');inCusNolike(arCNum)const;outNamelike(arName);outAddr1like(arAdd1);outAddr2like(arAdd2);outCitylike(arCity);outStatelike(arStte);outZiplike(arZip);end-pi;execsqlselectarName,arAdd1,arAdd2,arCity,arStte,arZipinto:outName,:outAddr1,:outAddr2,:outCity,:outState,:outZipfromARMSTF1wherearCNum=:inCusNofetchfirst1rowonlywithCSusecurrentlycommitted;return;end-proc;
COBOL is a compiled English-like computer programming language designed for business use. It is an imperative, procedural, and, since 2002, object-oriented language. COBOL is primarily used in business, finance, and administrative systems for companies and governments. COBOL is still widely used in applications deployed on mainframe computers, such as large-scale batch and transaction processing jobs. Many large financial institutions were developing new systems in the language as late as 2006, but most programming in COBOL today is purely to maintain existing applications. Programs are being moved to new platforms, rewritten in modern languages, or replaced with other software.
A fourth-generation programming language (4GL) is a high-level computer programming language that belongs to a class of languages envisioned as an advancement upon third-generation programming languages (3GL). Each of the programming language generations aims to provide a higher level of abstraction of the internal computer hardware details, making the language more programmer-friendly, powerful, and versatile. While the definition of 4GL has changed over time, it can be typified by operating more with large collections of information at once rather than focusing on just bits and bytes. Languages claimed to be 4GL may include support for database management, report generation, mathematical optimization, GUI development, or web development. Some researchers state that 4GLs are a subset of domain-specific languages.
Structured Query Language (SQL) is a domain-specific language used to manage data, especially in a relational database management system (RDBMS). It is particularly useful in handling structured data, i.e., data incorporating relations among entities and variables.
In computer science, Backus–Naur form is a notation used to describe the syntax of programming languages or other formal languages. It was developed by John Backus and Peter Naur. BNF can be described as a metasyntax notation for context-free grammars. Backus–Naur form is applied wherever exact descriptions of languages are needed, such as in official language specifications, in manuals, and in textbooks on programming language theory. BNF can be used to describe document formats, instruction sets, and communication protocols.
Db2 is a family of data management products, including database servers, developed by IBM. It initially supported the relational model, but was extended to support object–relational features and non-relational structures like JSON and XML. The brand name was originally styled as DB2 until 2017, when it changed to its present form.
In computing, Open Database Connectivity (ODBC) is a standard application programming interface (API) for accessing database management systems (DBMS). The designers of ODBC aimed to make it independent of database systems and operating systems. An application written using ODBC can be ported to other platforms, both on the client and server side, with few changes to the data access code.
IBM i 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 in 2004, before being renamed a second time to IBM i in 2008. It is an evolution of the System/38 CPF operating system, with compatibility layers for System/36 SSP and AIX applications. It inherits a number of distinctive features from the System/38 platform, including the Machine Interface which provides hardware independence, the implementation of object-based addressing on top of a single-level store, and the tight integration of a relational database into the operating system.
The IBM System/36 was a midrange computer marketed by IBM from 1983 to 2000 - a multi-user, multi-tasking successor to the System/34.
RPG II is a very early and popular version of the IBM RPG programming language.
Autocoder is any of a group of 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.
IBM 7070 is a decimal-architecture intermediate data-processing system that was introduced by IBM in 1958. It was part of the IBM 700/7000 series, and was based on discrete transistors rather than the vacuum tubes of the 1950s. It was the company's first transistorized stored-program computer.
RPG III is a dialect of the RPG programming language that was first announced with the IBM System/38 in 1978. An upgraded version, RPG IV, was introduced in 1994. In 2001 RPG was again updated to remove a number of column restrictions. RPG continues to be upgraded on a regular basis. The last fixed form restrictions were removed in 2015. Other than sharing some opcodes and terminology, modern RPG IV is visually very different from RPG III.
System Support Program (SSP) was the operating system of the IBM System/34 and System/36 minicomputers. SSP was a command-based operating system released in 1977.
Donald D. Chamberlin is an American computer scientist who is one of the principal designers of the original SQL language specification with Raymond Boyce. He also made significant contributions to the development of XQuery.
CGIDEV2 is a free and open source IBM i 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. The functionality of this toolset is incorporated into an RPG ILE program by means of a service program that contains all of the procedures required to read input from a browser, generate and send the appropriate response back to the browser. CGIDEV2 is commonly used to generate static or interactive HTML/DHTML pages but it can also produce CSV, XML, Excel-XML and other text based files.
SQL/XML or XML-Related Specifications is part 14 of the Structured Query Language (SQL) specification. In addition to the traditional predefined SQL data types like NUMERIC, CHAR, TIMESTAMP, ...
it introduces the predefined data type XML
together with constructors, several routines, functions, and XML-to-SQL data type mappings to support manipulation and storage of XML in a SQL database.
Input/Output Control System (IOCS) is any of several packages on early IBM entry-level and mainframe computers that provided low level access to records on peripheral equipment. IOCS provides functionality similar to 1960s packages from other vendors, e.g., File Control Processor (FCP) in RCA 3301 Realcom Operating System, GEFRC in GECOS, and to the later Record Management Services (RMS) in DEC VAX/VMS
Distributed Data Management Architecture (DDM) is IBM's open, published software architecture for creating, managing and accessing data on a remote computer. DDM was initially designed to support record-oriented files; it was extended to support hierarchical directories, stream-oriented files, queues, and system command processing; it was further extended to be the base of IBM's Distributed Relational Database Architecture (DRDA); and finally, it was extended to support data description and conversion. Defined in the period from 1980 to 1993, DDM specifies necessary components, messages, and protocols, all based on the principles of object-orientation. DDM is not, in itself, a piece of software; the implementation of DDM takes the form of client and server products. As an open architecture, products can implement subsets of DDM architecture and products can extend DDM to meet additional requirements. Taken together, DDM products implement a distributed file system.