IBM RPG II


RPG II is a very early and popular version of the IBM RPG programming language.
It was developed in the late 1960s and designed to work on the smallest IBM systems of the time such as the IBM 1130, IBM System/3, System/32, System/34, System/36. It was however also available for the System/370, The Singer System 10, Univac 90/25, 90/30, 90/40 and the Wang VS Series. ICL produced versions for its ICL 2903 system and for VME/K; and Burroughs Corporation produced an RPG II compiler with database extensions for its B1700 series of computers.
An enhanced version RPG III appeared in 1978.
It has a number of unusual features, including: an implied processing loop; and that it is a fixed-format programming language, so that programs are difficult to read without a special debugging template.

Features

RPG II is a fixed-format programming language, which means that code must be placed in exact column locations in order to generate correct results. There are eight different specification types, and separate coding forms are used to write each, and a special debugging template used as an aid to read program printouts.
Every RPG II program executes within an implied loop, the program cycle, which applies the program successively to every record of a file - this is documented via a "Logic Flow" diagram on the debugging template. Each record 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. Special variables such as UDATE, UYEAR, PAGE, and so forth, are filled when the program begins or when page overflow occurs, even though there is no explicit instruction for these activities. Total calculations and output are done at "total time," after the detail cycle when L1/LR has been set on by fixed logic.
The concept of RPG's program cycle fitted neatly with a cyclical machine that read cards, summarised their contents and prints a result, rather like a tabulating machine. The language was extended to handle other input and output devices and provides a fast and efficient method of programming.
Devices such as the workstation, the keyboard, or the console do not have a fixed number of records at the beginning of the job and therefore, in order to incorporate the fixed-logic RPG "Last Record" cycle, the LR indicator can be set on with a SETON instruction. LR cannot be set off.
RPG II did not evolve much from the 1977 implementation on the System/34 to 2000 when the Advanced/36 was discontinued from marketing. Changes that were made from the 1970s version included the IFEQ/IFNE/IFGT/IFGE/IFLT/IFLE and END grouping. Also, the call/parm to be able to call external subroutines. Another change was that for internal subroutines, you no longer had to put SR in columns 7 and 8 of the C specs.
Third-party providers sold more than 200 different assembler subroutines that could be used by System/36 and Advanced/36 programmers to exceed RPG II limitations. Some of the limitations of RPG II on the System/3, 32, 34 and 36 including the Advanced/36 was the 64K limit and the number of files you could have in a program. So if you had a lot of programming lines or had large arrays, it was easy to exceed the 64,000 bytes of object code. However, RPG II running on the AS/400 and its follow on iseries and IBM i those limits were either greatly expanded or removed.

RPGII specifications

In the popular System/36 implementation of RPG II, there are 8 different specification
types:

A ninth was added later in 1977:
Operation codes appear in columns 28-32 of an RPG-II calculation specification.

Operation codeName
ADDAdd
SUBSubtract
MULTMultiply
DIVDivide
Z-ADDZero and Add
Z-SUBZero and Subtract
MVRMove Remainder
MOVEMove
MOVELMove Left
MHLZOMove High to Low Zone
MLHZOMove Low to High Zone
MLLZOMove Low to Low Zone
MHHZOMove High to High Zone
BITONBit On
BITOFBit Off
TESTBTest Bit
GOTOGo To
TAGTag
EXSRExecute Subroutine
BEGSRBegin Subroutine
ENDSREnd Subroutine
SETONSet On
SETOFSet Off
EXCPTException
EXITExit
RLABLRedefine Label
ULABLUser Label
CALL1Call
PARM1Parameter
CHAINChain
READRead
READERead Equal
READPRead Previous
REDPERead Previous Equal
SETLLSet Lower Limits
SETSet
TIMETime of day
DSPLYDisplay
SORTASort Array
XFOOTCrossfoot
MOVEAMove Array
LOKUPLookup


  1. CALL/PARM was added to RPG II with Release 6.0.
CHAIN retrieves the record in the indexed file named in Factor 2 that matches the exact key specified by the value in Factor 1.
SETLL causes the index pointer for the file named in Factor 2 to be positioned at the location specified by the value in Factor 1.
SORTA causes the named array to be sorted in place; that is, the elements appear in order.
Z-SUB calculates Factor 2 with opposite sign and moved to result field.
XFOOT causes an array to be summed and the result moved to result field.
MVR must follow a DIV operation. The integer remainder of the DIV operation is placed in the result field. MVR following the DIV operation for "56 divided by 3" would place the value 2 in the result field.

Indicators

Indicators are either 'set' or not - so they are effectively a built-in series of "flags" or boolean data types.
3H
5F/files
6F/extensions
7E
8L
10I/header
11I/fields
12C
13O/header
14O/fields

Sample code


F***************************************************************
F* THIS PROGRAM READS THE CONTENTS OF AN INVOICE HEADER FILE
F* AND PRINTS THE INVOICES PROCESSED FOR THE DATE SET IN THE
F* LOCAL DATA AREA. THERE ARE LEVEL BREAKS AND TOTALS FOR
F* EACH STORE.
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 622TOTINV
I UDS
I 1 8 RPTDAT
C 01 INVDAT COMP RPTDAT 11
C 01 11 ADD TOTINV L1TOT 92
C 01 11 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 01 11
O INVNO 18
O CUSTNO 28
O STNAM 58
O TOTINV1B 78
O T 1 L1
O 45 'STORE TOTAL...'
O L1TOT 1B 78
O T 1 LR
O 45 'GRAND TOTAL...'
O LRTOT 1 78