RPG
IBM's Report Program Generator - the primary programming language of the IBM i (AS/400) platform, powering business applications at enterprises worldwide since 1959.
Created by IBM
RPG (Report Program Generator) is one of the longest-lived programming languages in computing history. Developed at IBM around 1959 for the IBM 1401 computer, it has evolved from a simple report-generating utility into a full-featured business programming language that remains the primary development language on the IBM i platform.
History & Origins
RPG’s origins lie in the world of tabulating machines - the electromechanical devices that processed punched cards before electronic computers became widespread. IBM operators configured these machines by wiring plugboards to define input, calculations, and output. RPG was designed to make that same workflow accessible on the new IBM 1401 computer.
From Plugboards to Programs
The key insight behind RPG was that thousands of IBM customers already knew how to express business logic through tabulating machine operations: read a record, perform calculations, produce output. RPG formalized this into a specification-based programming model that tabulating machine operators could learn without becoming programmers in the traditional sense.
The development team, reportedly led by Wilf Hey at IBM’s San Jose laboratory, deliberately designed RPG so that operators with Electronic Accounting Machine (EAM) and plugboard wiring experience could transition to programming electronic computers without formal programming training.
The Program Cycle
RPG introduced a unique concept called the program cycle - an implicit main loop that:
- Reads a record from input
- Processes calculations based on indicators
- Produces output
- Repeats until end of file
This cycle mirrored how tabulating machines operated and made RPG natural for batch processing of business data.
Evolution Through IBM Hardware
RPG’s history is tightly coupled with IBM’s midrange hardware:
- RPG (1959-1960s) - Original version for the IBM 1401
- RPG II (1969) - Released with the IBM System/3, adding subroutines and expanded indicator support
- RPG III (1978) - Introduced with the IBM System/38, bringing structured programming (IF-ENDIF, DO loops)
- RPG/400 (1988) - Shipped with the IBM AS/400, adding embedded SQL and new built-in functions
- RPG IV (1994) - Major modernization for OS/400 V3R2, with new data types, subprocedures, and longer identifiers
Modern RPG: Free-Form Revolution
The most significant change in RPG’s recent history has been the move to free-form syntax. Traditional RPG used fixed-format “specifications” where the meaning of each character depended on its column position - a direct descendant of the punched card era.
Fixed-Format (Classic Style)
| |
In fixed format, column positions determined meaning:
- Columns 6: Form type (H, F, D, C, O, P)
- Columns 7-8: Control level indicators
- Columns 12-25: Factor 1
- Columns 26-35: Operation code
- And so on…
Free-Format (Modern Style)
**FREE
dcl-s msg char(50) inz('Hello, World!');
dsply msg;
*inlr = *on;
The journey to free-form happened in stages:
- 2001: Free-format for calculation specifications (
/FREE…/END-FREE) - 2013: Free-format extended to header, file, and definition specifications
- 2015: Fully free-form with
**FREEdirective - no column restrictions at all
Modern RPG IV code looks remarkably different from its fixed-format ancestors while maintaining full backward compatibility.
What Makes RPG Different
1. Specification-Based Design
Traditional RPG organized programs into specification types:
- H-spec (Control): Program-level options
- F-spec (File): File declarations
- D-spec (Definition): Variable and data structure declarations
- C-spec (Calculation): Program logic
- O-spec (Output): Output formatting
- P-spec (Procedure): Subprocedure boundaries
In modern free-form RPG, these become keyword-based declarations:
**FREE
ctl-opt main(main); // H-spec equivalent
dcl-f custFile usage(*input); // F-spec equivalent
dcl-s custName char(50); // D-spec equivalent
2. Indicators
RPG uses numbered indicators (*IN01 through *IN99) as boolean flags - a direct inheritance from tabulating machine indicator lights:
**FREE
// Set indicator on
*in50 = *on;
// Use indicator in logic
if *in50;
dsply 'Indicator 50 is on';
endif;
Special indicators include:
- *INLR (Last Record) - Signals program termination
- *INOF (Overflow) - Page overflow for printing
- *IN01-*IN99 - General purpose
3. Built-in Business Data Types
RPG excels at business data with native support for:
- Packed decimal - Efficient storage for financial calculations
- Zoned decimal - Compatible with mainframe data formats
- Date, Time, Timestamp - Built-in date arithmetic
- Variable-length characters - Efficient string handling
**FREE
dcl-s amount packed(11:2); // 11 digits, 2 decimal places
dcl-s orderDate date(*iso); // ISO format date
dcl-s custName varchar(100); // Variable-length string
dcl-s active ind; // Indicator (boolean)
4. Embedded SQL
RPG IV integrates directly with DB2 for i:
**FREE
dcl-s custName varchar(100);
exec sql
SELECT name INTO :custName
FROM customers
WHERE id = 1001;
dsply custName;
The IBM i Platform
RPG is inseparable from IBM i (formerly known as AS/400, iSeries, and System i). This platform provides:
- Single-level storage - Objects addressed the same way regardless of storage location
- Object-based architecture - Everything is an object with a type
- Integrated database (DB2 for i) - Database built into the OS
- Machine Interface (MI) - Hardware abstraction layer enabling forward compatibility
- Integrated Language Environment (ILE) - Allows mixing RPG, COBOL, C, and CL in the same program
Programs compiled on older IBM i versions generally run without recompilation on newer versions, providing remarkable stability for business applications.
Platform Availability
RPG is exclusively tied to the IBM i operating system:
| Platform | Support |
|---|---|
| IBM i (Power Systems) | Full - native environment |
| Windows | No native compiler |
| macOS | No native compiler |
| Linux | No native compiler |
| Docker | No image available |
The RPG IV compiler is proprietary to IBM and only runs on IBM i. Unlike COBOL (GnuCOBOL) or Fortran (gfortran), there is no open-source RPG compiler for other platforms.
Accessing IBM i
To write and run RPG programs, you need access to an IBM i system:
- IBM Power Virtual Server - Cloud-based IBM i instances
- PUB400.COM - Free public IBM i system for learning
- IBM i Access - Client software for connecting to IBM i
Development Tools
- RDi (Rational Developer for i) - Eclipse-based IDE from IBM
- Code for IBM i - Free VS Code extension for RPG development
- SEU (Source Entry Utility) - Traditional green-screen editor
- abapGit-style tools - Community tools like iForGit for Git integration
RPG Today
According to the 2023 Fortra IBM i Marketplace Report, RPG is used by approximately 89% of IBM i shops for new development. The language continues to evolve through IBM i Technology Refreshes, with recent additions including enumerations (2023) and additional built-in functions delivered via subsequent Technology Refreshes.
The IBM i platform reportedly powers critical systems at a significant portion of Fortune 500 companies, particularly in banking, insurance, retail, and manufacturing.
Getting Started
RPG source files on IBM i are traditionally stored in source physical files (typically QRPGLESRC) rather than as stream files with extensions. When stored in the IFS (Integrated File System), the conventional extension is .rpgle for ILE RPG source.
Continue to the Hello World tutorial to see RPG code in action.
Timeline
Notable Uses & Legacy
Banking and Finance
Core banking systems, transaction processing, account reconciliation, and audit trails at financial institutions worldwide.
Retail and Distribution
Point-of-sale systems, inventory management, and order fulfillment for major retailers running on IBM i.
Manufacturing
ERP systems, plant operations, supply chain management, and material requirements planning.
Healthcare
Hospital billing, insurance claims processing, and patient records management systems.
Insurance
Policy management, claims processing, and actuarial systems at insurance companies.
Language Influence
Influenced By
Running Today
Run examples using the official Docker image:
docker pull noneExample usage:
# RPG requires IBM i - no Docker image available