IBM RPG II
| Company type | Programming language |
|---|---|
| Industry | Computer programming |
| Founded | late 1960s |
| Headquarters | United States |
| Products | RPG II programming language |
RPG II represents an early and extensively adopted iteration of the IBM RPG programming language, created in the late 1960s to support IBM’s smaller computing systems such as the IBM 1130, System/3, System/32, System/34, and System/36. This language was also accessible on larger machines including the System/370, Singer System 10, Sperry Univac 90/25, 90/30, 90/40, System 80, and the 1100 mainframe series. Additionally, various manufacturers like ICL and Burroughs Corporation developed their own versions for respective platforms, while Digital Equipment Corporation released VAX RPG II tailored for VAX/VMS environments.
An upgraded variant named RPG III was launched in 1978.
RPG II is characterized by a fixed-format syntax demanding exact column positioning and functions within an implicit processing loop. This structure often results in programs that are challenging to interpret without a dedicated debugging layout.
Features
The fixed-column format of RPG II mandates that code be placed precisely within designated columns across eight specification categories, each with unique coding rules. A specialized debugging form assists users in deciphering program listings.
Execution occurs inside a built-in loop known as the program cycle, which processes each record from files sequentially. Every record is assessed against lines activated by "indicators," which are logical flags numbered from 01 to 99 or linked to specific file or report actions. Certain automatic variables like UDATE, UYEAR, and PAGE update dynamically during processing. Totals and output routines happen at "total time," triggered after detail lines when the L1/LR indicator is set through fixed logic.
This cyclical processing approach was well-suited to tabulating machines and efficiently managed input/output hardware beyond punched card readers.
For devices lacking predetermined record lengths (such as WORKSTN, KEYBORD, CONSOLE), the LR indicator can be manually enabled using SETON to mark the final record; however, once set, LR cannot be turned off.
From its 1977 System/34 release until the discontinuation of the Advanced/36 in 2000, RPG II underwent minimal changes. Key enhancements included conditional grouping statements (IFEQ/IFNE/IFGT/IFGE/IFLT/IFLE) and improved subroutine invocation allowing calls to external procedures. Internal subroutines no longer required SR codes in fixed columns.
Third-party vendors supplied more than 200 assembler routines to augment RPG II capabilities on System/36 and Advanced/36 systems. Despite this, constraints such as a maximum object code size of 64K and limits on file counts restricted development of large programs or arrays. Nevertheless, RPG II implementations on AS/400, iSeries, and IBM i platforms running OS/400 or i5/OS within S/36E mode substantially increased or removed these restrictions.
RPGII specifications
Within the System/36 version of RPG II, eight specification (spec) types exist—each a fixed-format line consisting of 80 characters—reflecting their origin from punched card inputs used in earlier IBM systems like the System/3. These specs must follow a strict sequence: U, T, H, F, E, L, I, C, then O.
The specification code is indicated in column 6 of an RPG-II specification line:
| Specification code | Description |
|---|---|
| U | Auto Report specification, applicable exclusively for Auto Report programs. |
| T | Telecommunications specification introduced in 1977. |
| H | Header specification positioned at the program’s start; it defines compiler options, program type (e.g., MRT), and output listing details. The object name appears in columns 75–80; if omitted, defaults to RPGOBJ. |
| F | File specifications describe files utilized—these may include disk files or devices such as printers, workstations, keyboards, or user-defined hardware. They specify record/block sizes and associated indicators. Programs can exclude F specs if not needed. |
| E | Extension specifications define arrays and tables derived from disk files, constants, or calculated values. |
| L | Line Counter specifications dictate printed form layouts including page length and print positions. |
| I | Input specifications describe data areas within files; they allow for field redefinition and indicator conditioning. |
| C | Calculation specifications manage total fields, complex arithmetic operations, string processing, and indicator conditioning. |
| O | Output specifications specify output record fields and their positions. |
In calculation specifications, operation codes occupy columns 28 through 32:
| Operation code | Description | |
|---|---|---|
| ADD | Add values | |
| SUB | Subtract values | |
| MULT | Multiply values | |
| DIV | Divide values | |
| Z-ADD | Zero and Add operation | |
| Z-SUB | Zero and Subtract (computes Factor 2 with reversed sign) | |
| MVR | Move Remainder (used immediately after DIV; stores integer remainder into result) | |
| MOVE | Move data | |
| MOVEL | Move Left operation | |
| MHLZO | Move High to Low Zone | |
| MLHZO | Move Low to High Zone | |
| MLLZO | Move Low to Low Zone | |
| MHHZO | Move High to High Zone | |
| BITON | Set Bit On | |
| BITOF | Set Bit Off | |
| TESTB | Test Bit status | |
| GOTO | Transfer control to specified location | |
| TAG | Destination label for GOTO | |
| EXSR | Execute Subroutine | |
| BEGSR | Begin Subroutine block | |
| ENDSR | End Subroutine block | |
| SETON | Set indicator On | |
| SETOF | Set indicator Off | |
| EXCPT | Exception handling | |
| EXIT | Exit program or subroutine | |
| RLABL | Redefine Label | |
| ULABL | User-defined Label | |
| CALL1 | Call external routine (introduced in Release 6.0/VASP) | |
| PARM1 | Pass parameter (introduced in Release 6.0/VASP) | |
| CHAIN | Retrieve record by key from indexed file | |
| READ | Read next record | |
| READE | Read equal key records | |
| READP | Read previous record | |
| REDPE | Read previous equal key records | |
| SETLL | Position index pointer at specified key location in file | |
| SET | Set indicator or assign value | |
| TIME | Retrieve current time (format: 000000-235959) | |
| DSPLY | Display data output | |
| SORTA | Sort array elements in place | |
| XFOOT | Sum array elements and store result | |
| MOVEA | Move contents of array | |
| LOKUP | Lookup value within an array |
- The CALL and PARM operations were added with RPG II Release 6.0 (VASP).
- CHAIN fetches a record matching a key from an indexed file.
- SETLL positions the file index pointer at a specified key location.
- SORTA sorts an array directly within memory.
- Z-SUB calculates Factor 2 with an inverted sign into the destination field.
- XFOOT sums elements of an array and moves the total into a target field.
- MVR must follow DIV to place the integer remainder into the result field.
Indicators
Indicators serve as binary flags within program definitions:
- Custom indicators, typically set manually for tailored use in I, C, and O specifications:
- 01 through 99
- Termination Indicators, manually activated in calculation C-specs to end a program and return a status code:
- H1 through H9
- Synchronization Indicators, linked to input I-spec fields, automatically triggered when reading records from multiple sources to align fields assuming sorted data:
- M1 through M9, signaling a match occurred
- Hierarchical Control Indicators, assigned to input I-spec fields to denote grouped field levels within a file’s record, presuming sequential sorted processing:
- L0 through L9
- Command Key Indicators, representing input from workstation keyboards analogous to PC function keys ( and ), used instead of :
- KA through KY (command keys 1 to 24; note the absence of )
- Initial Cycle Indicator, automatically set upon outputting the first page, mainly for printer files, managing elements like page breaks and headings:
- 1P
- Pagination Overflow Indicators, activated either automatically or manually when printer pagination limits are reached per file’s L-spec line counter; one indicator per up to eight output files:
- OA through OV
- End-of-File Indicator, automatically set at sequential file completion or manually for programs lacking sequential input, signaling program termination and returning control to the batch jobstream:
- LR
- External Indicators, provided by jobstream control scripts for specialized purposes:
- U1 through U8
Foldable plastic-coated templates were used to visually verify fixed-format source code against printed output. These were designed to align precisely with standard text spacing derived from punched card conventions and aided developers during code inspection. Notable templates included:
| 3 | H | header |
| 5 | F | files |
| 6 | F | extensions |
| 7 | E | extensions |
| 8 | L | line counters |
| 10 | I | file |
| 11 | I | fields |
| 12 | C | calculation |
| 13 | O | file |
| 14 | O | fields |
Sample code
F***************************************************************
F* THIS PROGRAM PROCESSES AN INVOICE HEADER FILE
F* AND PRINTS INVOICES FOR THE DATE SPECIFIED IN THE
F* LOCAL DATA AREA, INCLUDING LEVEL BREAKS AND STORE TOTALS.
F***************************************************************
F*
FINVHDR IP F 62 DISK
FPRINTER O F 132 OF PRINTER
IINVHDR NS 01 1NC
I 1 3 STORE L1
I 4 13 INVNO
I 14 20 CUSTNO
I 21 45 STNAM
I 46 53 INVDAT
I 54 622 TOTINV
I UDS
I 1 8 RPTDAT
C 01 INVDAT COMP RPTDAT 11
C 01 INVDAT ADD TOTINV L1TOT 92
C 01 INVDAT ADD TOTINV LRTOT 92
OPRINTER H 101 1P
O OR OF
O PAGE Z 106
O 102 'PAGE'
O 59 'VERY BIG'
O 72 'STORES, INC.'
O UDATE Y 17
O 8 'RUN DATE'
O H 1 1P
O OR OF
O 73 'DAILY SALES BY STORE'
O H 2 1P
O OR OF
O RPTDAT 83
O 63 'FOR DATE:'
O H 1 1P
O OR OF
O 6 'STORE'
O 18 'INVOICE'
O 28 'CUSTOMER'
O 58 'CUSTOMER'
O 78 'INVOICE'
O H 2 1P
O OR OF
O 6 'NUMBER'
O 18 'NUMBER'
O 28 'NUMBER'
O 58 'NAME'
O 78 'TOTAL'
O D 0 L1
O STORE 6
O D 1 INVNO
O INVNO 18
O D 2 CUSTNO
O CUSTNO 28
O D 3 STNAM
O STNAM 58
O D 4 TOTINV
O TOTINV B78
O T L1
O 45 'STORE TOTAL...'
O L1TOT B78
O T LR
O 45 'GRAND TOTAL...'
O LRTOT B78