Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
IBM RPG
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Report Program Generator programming language by IBM}} {{Infobox programming language | name = RPG<br />Report Program Generator | logo = IBM RPG logo.png | logo size = 230px | paradigm = [[Programming paradigm#Support for multiple paradigms|Multi-paradigm]] | year = {{Start date and age|1959}} | designer = | developer = [[IBM]] | latest_release_version = RPG IV version 7 release 4 | latest_release_date = {{Start date|2020|10|06}} | latest_test_version = | latest_test_date = | typing = [[Strong and weak typing|Strong]], [[Type system#STATIC|static]] | implementations = | 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 = [[IBM 709/90 9PAC|9PAC]], [[FARGO (programming language)|FARGO]] | operating_system = [[Control Program Facility|CPF]], [[System Support Program|SSP]], [[IBM i|OS/400]], [[IBM i]], [[OS/VS1]], [[z/OS]], [[VSE (operating system)|DOS/VSE]], [[VSE (operating system)|VSE/SP]], [[VSE (operating system)|VSE/ESA]], [[VSE (operating system)|z/VSE]], [[VS/9]], [[PRIMOS]], [[OpenVMS]], [[Wang Laboratories#The Wang VS computer line|Wang VS]], [[Burroughs MCP]], [[HP Multi-Programming Executive|HP MPE]], [[MS-DOS]], [[OS/2]], [[Microsoft Windows]] | license = | website = }} '''RPG''' is a [[high-level programming language]] for [[Business software|business application]]s, 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]].<ref>{{cite web|url=https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rzasc/rpgintro.htm|title=RPG ILE Introduction|date=June 2012|publisher=IBM|access-date=2021-03-16|archive-date=2024-02-29|archive-url=https://web.archive.org/web/20240229162212/https://www.ibm.com/docs/en/i/7.2?topic=guide-ile-rpg-introduction|url-status=live}}</ref> RPG has traditionally featured a number of distinctive concepts, such as the program cycle, and the column-oriented syntax.<ref>{{cite book|author1=Tony Baritz|author2=David Dunne|title=AS/400--concepts and Facilities|url=https://books.google.com/books?id=F6tQAAAAMAAJ|year=1991|publisher=McGraw-Hill|isbn=978-0-07-018301-8|access-date=2021-03-16|archive-date=2024-02-29|archive-url=https://web.archive.org/web/20240229162220/https://books.google.com/books?id=F6tQAAAAMAAJ|url-status=live}}</ref> The most recent version is '''RPG IV''', which includes a number of modernization features, including free-form syntax.<ref>{{cite web|url=https://www.itjungle.com/2020/08/24/is-it-time-to-rename-rpg/|title=Is It Time To Rename RPG?|author=Alex Woodie|date=2020-08-24|access-date=2021-03-16|website=itjungle.com|archive-date=2021-04-23|archive-url=https://web.archive.org/web/20210423084718/https://www.itjungle.com/2020/08/24/is-it-time-to-rename-rpg/|url-status=live}}</ref> ==Platforms== The RPG programming language originally was created by IBM for their 1401 systems. IBM later produced implementations for the [[IBM 7070|7070/72/74]]<ref>{{cite book | title = 7070/7074 Compiler Systems: Report Program Generator | id = C28-6113 | publisher = [[IBM]] }} </ref><ref>{{cite book |title = Programming Systems Analysis Guide - IBM 7070 Series Report Program Generator |id = C28-6192 |url = http://bitsavers.org/pdf/ibm/7070/C28-6192_7070_RPG_System_Analysis_Guide_1962.pdf |year = 1962 |publisher = [[IBM]] |access-date = January 19, 2024 |archive-date = January 19, 2024 |archive-url = https://web.archive.org/web/20240119173806/http://bitsavers.org/pdf/ibm/7070/C28-6192_7070_RPG_System_Analysis_Guide_1962.pdf |url-status = live }}</ref> and [[System/360]];<ref>{{cite book |title = IBM System/360 - Operating System - RPG Language Specifications - Program Number 380S-RG-038 (OS) |id = GC24-3337-6 |date = July 1973 |edition = Seventh |url = https://bitsavers.org/pdf/ibm/360/rpg/GC24-3337-6_RPG_Language_Specifications_Jul73.pdf |publisher = [[IBM]] |access-date = January 19, 2024 |archive-date = January 19, 2024 |archive-url = https://web.archive.org/web/20240119175859/https://bitsavers.org/pdf/ibm/360/rpg/GC24-3337-6_RPG_Language_Specifications_Jul73.pdf |url-status = live }}</ref> 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 [[Digital Equipment Corporation|DEC]] [[VAX]], Sperry Univac BC/7, Univac system 80, Siemens [[BS2000]], Burroughs B700, [[Burroughs B1700|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 Laboratories#The Wang VS computer line|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 [[VSE (operating system)|VSE]]<ref>{{cite web|url=https://21cs.com/vsen/|title=21CS VSEn|publisher=21st Century Software|access-date=2025-02-22}}</ref> and [[z/OS]] operating systems,<ref>{{cite web|url=https://www-03.ibm.com/services/supline/products/sl2ci162.html|title=Supported product list|date=2021-03-16|access-date=2021-03-17|publisher=IBM|archive-date=2021-05-02|archive-url=https://web.archive.org/web/20210502121456/http://www-03.ibm.com/services/supline/products/sl2ci162.html|url-status=dead}}</ref> [[Unisys]] [[Burroughs MCP|MCP]],<ref>{{cite web|url=https://assets.unisys.com/Documents/Global/ProductInformationSheets/PI_170396_ClearPathMCPExpressRelease18.pdf|title=ClearPath MCP Express|publisher=Unisys|date=2017|access-date=2021-03-17|archive-date=2020-11-12|archive-url=https://web.archive.org/web/20201112024037/https://assets.unisys.com/Documents/Global/ProductInformationSheets/PI_170396_ClearPathMCPExpressRelease18.pdf|url-status=live}}</ref> [[Microsoft Windows]]<ref>{{cite web |title=Visual RPG for .NET |url=https://asna.com/us/products/visual-rpg |website=asna.com |publisher=ASNA |access-date=3 April 2022 |archive-date=3 April 2022 |archive-url=https://web.archive.org/web/20220403145810/https://asna.com/us/products/visual-rpg |url-status=live }}</ref> and [[OpenVMS]].<ref>{{cite web|url=http://www.migrationspecialties.com/Migration-RPG.html|title=Migration RPG|website=migrationspecialties.com|access-date=2021-03-17|archive-date=2021-05-17|archive-url=https://web.archive.org/web/20210517003651/http://www.migrationspecialties.com/Migration-RPG.html|url-status=live}}</ref> ==History== ===Background=== Originally developed by [[International Business Machines|IBM]] in 1959, the name ''Report Program Generator'' was descriptive of the purpose of the language: generation of reports from data files.<ref>[http://www-03.ibm.com/ibm/history/documents/pdf/HistoryofIBMDataProcessing.pdf ''"...IBM 1401 and the Report Program Generator (RPG) contributed significantly to this success..."''] {{Webarchive|url=https://web.archive.org/web/20120124182914/http://www-03.ibm.com/ibm/history/documents/pdf/HistoryofIBMDataProcessing.pdf |date=2012-01-24 }}, IBM 1401 Data Processing System / 1959</ref> [[FOLDOC]] accredits Wilf Hey with work at IBM that resulted in the development of RPG.<ref>but it says 1965, rather than the 1959 mentioned here.</ref> [[FARGO Programming Language|FARGO]] ('''F'''ourteen-o-one '''A'''utomatic '''R'''eport '''G'''eneration '''O'''peration) 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 [[plugboard|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.<ref>{{cite book | title = 7070/7074 Compiler Systems: Report Program Generator | id = C28-6113 | publisher = [[IBM]] }} </ref><ref>{{cite book |title = Programming Systems Analysis Guide - IBM 7070 Series Report Program Generator |id = C28-6192 |url = http://bitsavers.org/pdf/ibm/7070/C28-6192_7070_RPG_System_Analysis_Guide_1962.pdf |year = 1962 |publisher = [[IBM]] |access-date = January 19, 2024 |archive-date = January 19, 2024 |archive-url = https://web.archive.org/web/20240119173806/http://bitsavers.org/pdf/ibm/7070/C28-6192_7070_RPG_System_Analysis_Guide_1962.pdf |url-status = live }}</ref> The alternative languages generally available at the time were [[Assembly language|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=== {{main|RPG II}} ''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]]). [[International Computers Limited|ICL]] also produced a version on its [[ICL VME|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|Data Definition Specification]]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 structure]]s and reports can be defined externally, mostly eliminating the need to hand code input and output ("[[Input/output|I/O]]") specifications. ===RPG III=== {{main|RPG III}} ''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 [[subroutine]]s. 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==== ''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==== ''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 and ILE RPG=== ''RPG IV'', a.k.a. ''RPG ILE'',<ref>[https://archive.today/20121217164248/https://www-304.ibm.com/support/docview.wss?uid=nas1f23d225573c211a186256a240067a3da "Generating Random Numbers in ILE RPG Using the CEERAN0 API"], IBM.com</ref> was released in 1994 as part of the V3R2 release of [[OS/400]] (now known as IBM i).<ref>[http://www.ibmsystemsmag.com/Blogs/iDevelop/April-2015/How-Did-We-Miss-RPG-IV-s-Coming-of-Age-/ "How did we miss RPG IV's Coming of Age?"] {{Webarchive|url=https://web.archive.org/web/20170303042652/http://www.ibmsystemsmag.com/Blogs/iDevelop/April-2015/How-Did-We-Miss-RPG-IV-s-Coming-of-Age-/ |date=2017-03-03 }}, ibmsystemsmag.com</ref> <ref>{{cite web |title=RPG/400 |url=https://www.ibm.com/docs/en/rdfi/9.6.0?topic=languages-rpg400 |website=IBM.com | date=8 May 2018 |publisher=International Business Machines Corporation |access-date=4 April 2022 |archive-date=3 April 2022 |archive-url=https://web.archive.org/web/20220403171745/https://www.ibm.com/docs/en/rdfi/9.6.0?topic=languages-rpg400 |url-status=live }}</ref> 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|Integrated Language Environment framework]] is known as ILE RPG, and user guides explain the nuances of both.<ref>{{cite web |title=ILE RPG Reference |url=https://www.ibm.com/docs/en/rdfi/9.6.0?topic=reference-ile-rpg |website=IBM.com | date=June 2012 |publisher=International Business Machines Corporation |access-date=4 April 2022 |archive-date=3 April 2022 |archive-url=https://web.archive.org/web/20220403170239/https://www.ibm.com/docs/en/rdfi/9.6.0?topic=reference-ile-rpg |url-status=live }}</ref><ref>{{cite web |title=ILE RPG Programmer's Guide |url=https://www.ibm.com/docs/en/rdfi/9.6.0?topic=guide-ile-rpg-programmers |website=IBM.com | date=June 2012 |publisher=International Business Machines Corporation |access-date=4 April 2022 |archive-date=3 April 2022 |archive-url=https://web.archive.org/web/20220403171745/https://www.ibm.com/docs/en/rdfi/9.6.0?topic=guide-ile-rpg-programmers |url-status=live }}</ref><ref>{{cite web |title=Who Should Use This Guide |url=https://www.ibm.com/docs/en/rdfi/9.6.0?topic=airpg-who-should-use-this-guide |website=IBM.com | date=June 2012 |publisher=International Business Machines Corporation |access-date=4 April 2022 |archive-date=3 April 2022 |archive-url=https://web.archive.org/web/20220403171743/https://www.ibm.com/docs/en/rdfi/9.6.0?topic=airpg-who-should-use-this-guide |url-status=live }}</ref> RPG IV and ILE RPG are supported by IBM in the current IBM i platform.<ref>{{cite web |title=High Level Languages |url=https://www.ibm.com/docs/en/rdfi/9.6.0?topic=information-high-level-languages |website=IBM.com | date=8 May 2018 |publisher=International Business Machines Corporation |access-date=4 April 2022 |archive-date=3 April 2022 |archive-url=https://web.archive.org/web/20220403171742/https://www.ibm.com/docs/en/rdfi/9.6.0?topic=information-high-level-languages |url-status=live }}</ref> In 2001, with the release of [[IBM i|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.<ref>{{cite web|title=Totally Free RPG|url=http://ibmsystemsmag.blogs.com/idevelop/2013/10/as-you-may-have-already-heard-there-was-a-major-technology-refresh-tr-announcement-yesterday-check-out-fellow-blogger-st.html|publisher=IBM Systems Magazine|access-date=8 March 2014|author=Paris, Jon|author-link=Jon Paris|author2=Gantner, Susan|archive-date=8 March 2014|archive-url=https://web.archive.org/web/20140308153010/http://ibmsystemsmag.blogs.com/idevelop/2013/10/as-you-may-have-already-heard-there-was-a-major-technology-refresh-tr-announcement-yesterday-check-out-fellow-blogger-st.html|url-status=live}}</ref> 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),<ref>{{cite web |title=IBM Rational Developer for i |url=https://www.ibm.com/products/rational-developer-for-i |website=IBM.com |publisher=International Business Machines Corporation |access-date=3 April 2022 |archive-date=3 April 2022 |archive-url=https://web.archive.org/web/20220403060839/https://www.ibm.com/products/rational-developer-for-i |url-status=live }}</ref> an [[Eclipse (software)|Eclipse]]-based [[Integrated Development Environment]], is recommended by IBM for RPG development.<ref>{{cite web |title=5770-WDS IBM Rational Development Studio for i V7.4 |url=https://www.ibm.com/common/ssi/ShowDoc.wss?docURL=/common/ssi/rep_sm/s/877/ENUS5770-WDS/index.html |website=IBM.com |publisher=International Business Machines Corporation |access-date=3 April 2022 |archive-date=3 April 2022 |archive-url=https://web.archive.org/web/20220403060839/https://www.ibm.com/common/ssi/ShowDoc.wss?docURL=/common/ssi/rep_sm/s/877/ENUS5770-WDS/index.html |url-status=live }}</ref> The Source Entry Utility (SEU) text editor is no longer recommended for RPG development, and development ceased after IBM i 6.1.<ref>{{cite web |title=5770-WDS IBM Rational Development Studio for i V7.4 |url=https://www.ibm.com/common/ssi/ShowDoc.wss?docURL=/common/ssi/rep_sm/s/877/ENUS5770-WDS/index.html |website=IBM.com |publisher=International Business Machines Corporation |access-date=4 April 2022 |archive-date=3 April 2022 |archive-url=https://web.archive.org/web/20220403060843/https://www.ibm.com/common/ssi/ShowDoc.wss?docURL=/common/ssi/rep_sm/s/877/ENUS5770-WDS/index.html |url-status=live }}</ref> Other legacy developer tools include CODE/400 (based on IBM WorkFrame/2) and [[VisualAge|VisualAge for RPG]]. ====Continuing language enhancements==== IBM continues to enhance the RPG language<ref>{{cite web |last1=IBM |title=RPG Cafe |url=https://www.ibm.com/support/pages/node/1106229 |website=IBM.com |publisher=International Business Machines Corporation |access-date=3 April 2022 |archive-date=3 April 2022 |archive-url=https://web.archive.org/web/20220403042552/https://www.ibm.com/support/pages/node/1106229 |url-status=live }}</ref> via software releases and intra-release “technology refreshes” (TRs).<ref>{{cite web |last1=IBM |title=IBM i Technology Updates |url=https://www.ibm.com/support/pages/node/1119129/ |website=IBM.com |publisher=International Business Machines Corporation |access-date=3 April 2022 |archive-date=12 April 2022 |archive-url=https://web.archive.org/web/20220412041649/https://www.ibm.com/support/pages/node/1119129 |url-status=live }}</ref><ref>{{cite web |last1=IBM |title=IBM i Technology Refresh |url=https://www.ibm.com/support/pages/ibm-i-technology-refresh |website=IBM.com |publisher=International Business Machines Corporation |access-date=3 April 2022 |archive-date=3 April 2022 |archive-url=https://web.archive.org/web/20220403042552/https://www.ibm.com/support/pages/ibm-i-technology-refresh |url-status=live }}</ref> More built-in functions (BIFs) have been added. It has the ability to link to [[Java (programming language)|Java]] objects,<ref>{{cite web|title=RPG/400 User's Guide|url=https://www.ibm.com/support/knowledgecenter/en/ssw_i5_54/books/c0918160.pdf|website=Ibm.com|access-date=6 August 2017|archive-date=7 August 2017|archive-url=https://web.archive.org/web/20170807070650/https://www.ibm.com/support/knowledgecenter/en/ssw_i5_54/books/c0918160.pdf|url-status=live}}</ref> and IBM i [[Application programming interface|API]]s; it can be used to write [[Common Gateway Interface|CGI]] programs with the help of IBM's [[Cgidev2]] Web toolkit,<ref>{{cite web|url=https://www.easy400.net/cgidev2/start|title=EASY400 CGIDEV2|website=Easy400.net|access-date=26 March 2019|archive-date=26 March 2019|archive-url=https://web.archive.org/web/20190326190652/https://www.easy400.net/cgidev2/start|url-status=live}}</ref> the [[Linoma Software|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.<ref>{{cite web|url=https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/rzasm/roaIntro.htm|title=Rational Open Access: RPG Edition|publisher=IBM|access-date=2021-03-17|archive-date=2024-02-29|archive-url=https://web.archive.org/web/20240229162204/https://www.ibm.com/docs/en/i/7.2?topic=edition-rational-open-access-rpg|url-status=live}}</ref> ==Data types== RPG supports the following data types. '''Note:'''<br />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. {| class="wikitable sortable" style="width:100%;" |- !style="width:10%"| Data type !style="width:20%"| Name !style="width:25%"| Length !style="width:45%"| Description |- | style="text-align:center"|<code>A</code> | Alphanumeric character | 1 to 16,773,104 bytes (fixed)<br />1 to 16,773,100 bytes (varying-length) | Alphanumeric character |- | style="text-align:center"|<code>B</code> | Binary numeric | 1 byte (8-bit)<br />2 byte (16-bit)<br />4 bytes (32-bit)<br />8 bytes (64-bit) | Signed binary integer |- | style="text-align:center"|<code>C</code> | UCS-2 character | 1 to 8,386,552 characters (fixed)<br />1 to 8,386,550 characters (varying) | 16-bit UCS-2 character ([[DBCS]] or EGCS) |- | style="text-align:center"|<code>D</code> | Date | 10 bytes | Date: year, month, day |- | style="text-align:center"|<code>F</code> | [[Floating point]] numeric | 4 bytes (32-bit)<br />8 bytes (64-bit) | Signed binary floating-point real |- | style="text-align:center"|<code>G</code> | Graphic character | 1 to 8,386,552 characters (fixed)<br />1 to 8,386,550 characters (varying) | 16-bit graphic character ([[DBCS]] or EGCS) |- | style="text-align:center"|<code>I</code> | Integer numeric | 1 byte (8-bit)<br />2 bytes (16-bit)<br />4 bytes (32-bit)<br />8 bytes (64-bit) | Signed binary integer |- | style="text-align:center"|<code>N</code> | [[Character indicator]] | 1 byte | '1' = TRUE<br />'0' = FALSE |- | style="text-align:center"|<code>O</code> | Object | Size undisclosed | Object reference |- | style="text-align:center"|<code>P</code> | [[Packed decimal]] numeric | 1 to 63 digits,<br />2 digits per byte plus sign | Signed fixed-point decimal number with integer and fraction digits |- | style="text-align:center"|<code>S</code> | [[Zoned decimal]] numeric | 1 to 63 digits,<br />1 digit per byte | Signed fixed-point decimal number with integer and fraction digits |- | style="text-align:center"|<code>T</code> | Time | 8 bytes | Time: hour, minute, second |- | style="text-align:center"|<code>U</code> | Integer numeric | 1 byte (8-bit)<br />2 bytes (16-bit)<br />4 bytes (32-bit)<br />8 bytes (64-bit) | Unsigned binary integer |- | style="text-align:center"|<code>Z</code> | [[Timestamp]] | 26 bytes | [[System time|Date and time]]:<br /> year, month, day, hour, minute, second, microseconds |- | style="text-align:center"|<code>*</code> | [[Pointer (computer programming)#Based pointer|Basing-Pointer]]<br />[[Pointer (computer programming)#Function pointer|Procedure-Pointer]]<br />[[System-Pointer]] | 16 bytes | Address to Data<br />Address to Activated Procedure<br />Address to Object |} ==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. <pre> * 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 </pre> The same program using free calculations available starting in V5R1: <pre> * "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 </pre> Assume the ARMSTF1 example table was created using the following SQL Statement: <syntaxhighlight lang="sql"> 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)) </syntaxhighlight> The same program using free calculations and embedded SQL: <pre> * 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 </pre> 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: <syntaxhighlight lang="sql"> 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 </syntaxhighlight> 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: <syntaxhighlight lang="sql"> 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; </syntaxhighlight> ==References== {{Reflist}} ==Further reading== *{{cite web | title=9PAC, Report Generator | url=http://hopl.murdoch.edu.au/showlanguage2.prx?exp=35 | year=2006 | publisher=History of Programming Languages (HOPL), Murdoch University, AU | access-date=2008-04-01 | archive-url=https://web.archive.org/web/20101224021048/http://hopl.murdoch.edu.au/showlanguage2.prx?exp=35 | archive-date=2010-12-24 | url-status=dead }} *{{cite web | title=RPG, Report Program Generator | url=http://hopl.murdoch.edu.au/showlanguage2.prx?exp=207 | year=2006 | publisher=History of Programming Languages (HOPL), Murdoch University, AU | access-date=2008-04-01 | archive-url=https://web.archive.org/web/20110415045221/http://hopl.murdoch.edu.au/showlanguage2.prx?exp=207 | archive-date=2011-04-15 | url-status=dead }} *{{cite web | title=Pulling data out of computers in the mid-twentieth and early twenty-first centuries | url=http://www.snee.com/bobdc.blog/2006/02/pulling_data_out_of_computers.html | last=DuCharme | first=Bob | date=2006-02-26 }} *{{cite web | title=The Modern RPG IV Language | url=http://mc-store.com/5080.html | last=Cozzi | first=Robert | year=1996 }} *{{cite book | first=Gary B. | last=Shelly | author2=Thomas J. Cashman | year=1977 | title=Introduction to Computer Programming RPG | location=Fullerton, California | publisher=Anaheim Publishing Company | isbn=0-88236-225-9 | url=https://archive.org/details/introductiontoco0000shel/ | url-access=registration }} ==External links== * {{cite web | last = Smith | first = Brian R. | author2=Martin Barbeau | author3=Susan Gantner | author4=Jon Paris | author5=Zdravko Vincetic | author6=Vladimir Zupka | title = Who Knew You Could Do That with RPG IV? A Sorcerer's Guide to System Access and More | publisher = IBM International Technical Support Organization | date = April 25, 2000 | url = https://www.redbooks.ibm.com/redbooks/pdfs/sg245402.pdf | access-date = 2012-02-18 }} "This redbook is focused on RPG IV as a modern, thriving, and rich application development language for the 21st century." *[http://www.midrange.com/ Midrange.com] — A large number of code examples are available here *[https://www.rpgpgm.com/ RPGPGM.COM] — An extensive resource of articles giving examples of RPG code and related programming *[https://web.archive.org/web/20240227062509/http://www.coztools.com/iOpen RPG Open] — Free (open source) resources for RPG IV and IBM i application development. *{{cite book | last = IBM | title = IBM 1401 RPG manual | url = https://www.bitsavers.org/pdf/ibm/1401/C24-3261-1_1401_diskRPG.pdf | year = 1964 | id = C24-3261-1 }} *{{cite book | last = IBM | title = ILE RPG Programmer's Guide | url = https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/rzasc/sc092507.pdf | year = 2016 | id = SC09-2507-10 }} * [https://web.archive.org/web/20120314093748/http://gsf-soft.com/Documents/RPG-ZOS.shtml RPG II for MVS, OS/390 and z/OS] — Status of the IBM RPG II product in z/OS {{IBM}} {{Programming languages}} {{Authority control}} {{DEFAULTSORT:Ibm Rpg}} [[Category:High-level programming languages]] [[Category:Data-centric programming languages|RPG]] [[Category:Procedural programming languages|RPG]] [[Category:IBM software|RPG]] [[Category:Programming languages created in 1959]] [[Category:Statically typed programming languages]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Authority control
(
edit
)
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:IBM
(
edit
)
Template:Infobox programming language
(
edit
)
Template:Main
(
edit
)
Template:Programming languages
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Webarchive
(
edit
)