IBM RPG II

Last updated

RPG II is a very early and popular version of the IBM RPG programming language.

Contents

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, Sperry Univac 90/25, 90/30, 90/40, System 80, 1100 mainframe series [1] 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. Digital Equipment Corporation had their own implementation named VAX RPG II for VAX/VMS systems. [2]

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. [3]

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 [3] 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. [3] 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" — 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 (WORKSTN), the keyboard (KEYBORD), or the console (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 (calculation) 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 running OS/400 or i5/OS in what is called S/36E (execution environment)) those limits (the 64K bytes and the number of files) were either greatly expanded or removed.

RPGII specifications

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

U - Auto Report spec is only required for Auto Report programs.
H - Header spec is at the top of the program and describes compiler options such as maximum compile size, whether the program is an MRT (Multiple Requestor Terminal) program, and what type of listing is generated when the program is compiled. The object name of the program created is located in columns 7580; if a source does not have an H spec, the name RPGOBJ is used.
F - File spec(s) are next, and describes the files used in the program. Files may be disk files (DISK) or may be devices such as a printer (PRINTER), the workstation (WORKSTN), keyboard (KEYBORD), unformatted display (CRT or DISPLAY), or user-defined (SPECIAL). Record size, block size, overflow indicators, and external indicators are described. It is possible that an RPG program will not use any F specs.
E - Extension spec(s) are next, and describe arrays and tables, which may be prefetched from disk files (an Input table), drawn from constants placed at the end of the source between ** and /* symbols, or built from calculations.
L - Line Counter spec(s) are next, and if present, describe the form to be printed. It defines the number of lines in a page and the positions where printing begins and ends.
I - Input specs are next, and describe the data areas within files. RPG II permits redefinition of data areas so that a field named FLDA might occupy the same area as an array AR that contains 8 elements of 1 character each. Non-record areas such as data structures can be described. Depending on the values of the input record, indicators may be conditioned.
C - Calculation spec(s) are next. Total fields may be described and accumulated. Complex computations and string manipulations are possible. Indicators may be conditioned.
O - Output specifications, which describe the output record in terms of fields and output positions.

A ninth was added later in 1977: [4]

T - Telecommunications

Operation codes appear in columns 2832 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 (destination of a GOTO)
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 (000000-235959)
DSPLYDisplay
SORTASort Array
XFOOTCrossfoot
MOVEAMove Array
LOKUPLookup (find in array)
  1. CALL/PARM was added to RPG II with Release 6.0 (also known as the VASP).

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.

01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
H1 H2 H3 H4 H5 H6 H7 H8 H9
M1 M2 M3 M4 M5 M6 M7 M8 M9 MR
L0 L1 L2 L3 L4 L5 L6 L7 L8 L9
KA KB KC KD KE KF KG KH KI KJ KK KL KM KN KP KQ KR KS KT KU KV KW KX KY
These indicators refer to command keys 1 to 24, in that order. Note that there is no KO indicator.
1P
LR
OA OB OC OD OE OF OG OV
U1 U2 U3 U4 U5 U6 U7 U8
System/36 SEU templates
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  

Related Research Articles

AWK (awk) is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool. Like sed and grep, it is a filter, and is a standard feature of most Unix-like operating systems.

Forth is a procedural, stack-oriented programming language and interactive environment designed by Charles H. "Chuck" Moore and first used by other programmers in 1970. Although not an acronym, the language's name in its early years was often spelled in all capital letters as FORTH, but Forth is more common.

Fortran General-purpose programming language

Fortran is a general-purpose, compiled imperative programming language that is especially suited to numeric computation and scientific computing.

PL/I is a procedural, imperative computer programming language developed and published by IBM. It is designed for scientific, engineering, business and system programming. It has been used by academic, commercial and industrial organizations since it was introduced in the 1960s, and is still used.

IBM 1620 IBM scientific computer released in 1959

The IBM 1620 was announced by IBM on October 21, 1959, and marketed as an inexpensive "scientific computer". After a total production of about two thousand machines, it was withdrawn on November 19, 1970. Modified versions of the 1620 were used as the CPU of the IBM 1710 and IBM 1720 Industrial Process Control Systems.

BOS/360

BOS/360 was an early IBM System/360 operating system.

In computer science, self-modifying code is code that alters its own instructions while it is executing – usually to reduce the instruction path length and improve performance or simply to reduce otherwise repetitively similar code, thus simplifying maintenance. Self-modification is an alternative to the method of "flag setting" and conditional program branching, used primarily to reduce the number of times a condition needs to be tested. The term is usually only applied to code where the self-modification is intentional, not in situations where code accidentally modifies itself due to an error such as a buffer overflow.

The C programming language provides many standard library functions for file input and output. These functions make up the bulk of the C standard library header <stdio.h>. The functionality descends from a "portable I/O package" written by Mike Lesk at Bell Labs in the early 1970s, and officially became part of the Unix operating system in Version 7.

IBM 1130 16-bit IBM minicomputer introduced in 1965

The IBM 1130 Computing System, introduced in 1965, was IBM's least expensive computer at that time. A binary 16-bit machine, it was marketed to price-sensitive, computing-intensive technical markets, like education and engineering, succeeding the decimal IBM 1620 in that market segment. Typical installations included a 1 megabyte disk drive that stored the operating system, compilers and object programs, with program source generated and maintained on punched cards. Fortran was the most common programming language used, but several others, including APL, were available.

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. RPG has traditionally featured a number of distinctive concepts, such as the program cycle, and the column-oriented syntax. The most recent version is RPG IV, which includes a number of modernization features, including free-form syntax.

IBM System/3

The IBM System/3 was an IBM midrange computer introduced in 1969, and marketed until 1985. It was produced by IBM Rochester in Minnesota as a low-end business computer aimed at smaller organizations that still used IBM 1400 series computers or unit record equipment. The first member of what IBM refers to as their "midrange" line, it also introduced the RPG II programming language. It is the first ancestor in the product line whose current version is the IBM i series and includes the highly successful AS/400.

In computer science, a calling convention is an implementation-level (low-level) scheme for how subroutines receive parameters from their caller and how they return a result. Differences in various implementations include where parameters, return values, return addresses and scope links are placed, and how the tasks of preparing for a function call and restoring the environment afterwards are divided between the caller and the callee.

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.

This is an overview of Fortran 95 language features. Included are the additional features of TR-15581:Enhanced Data Type Facilities, which have been universally implemented. Old features that have been superseded by new ones are not described – few of those historic features are used in modern programs although most have been retained in the language to maintain backward compatibility. The current standard is Fortran 2018; many of its new features are still being implemented in compilers. The additional features of Fortran 2003, Fortran 2008 and Fortran 2018 are described by Metcalf, Reid and Cohen.

IBM System/34 BASIC was an interpreter for the IBM System/34 midrange computer.

IBM System/36 BASIC was an interpreter for the IBM System/36 midrange computer.

Screen Design Aid (SDA) is a utility for the IBM System/34 and System/36 midrange computers. Programmers can use SDA to create menus, display formats, or WSU skeleton programs. The System/38, and IBM i platforms also have a utility Screen Design Aid, but it syntax and functionality is different.

In computer programming, a subroutine is a sequence of program instructions that performs a specific task, packaged as a unit. This unit can then be used in programs wherever that particular task should be performed.

The write is one of the most basic routines provided by a Unix-like operating system kernel. It writes data from a buffer declared by the user to a given device, such as a file. This is the primary way to output data from a program by directly using a system call. The destination is identified by a numeric code. The data to be written, for instance a piece of text, is defined by a pointer and a size, given in number of bytes.

<i>The Preparation of Programs for an Electronic Digital Computer</i> First book on computer programming (1951)

The Preparation of Programs for an Electronic Digital Computer was the first book on computer programming. Published in 1951, it was written by Maurice Wilkes, David Wheeler, and Stanley Gill of Cambridge University. The book was based on the authors' experiences constructing and using EDSAC, one of the first practical computers in the world.

References

  1. "Sperry Univac 1100/60 System" (PDF). Retrieved 18 January 2021.
  2. "VAX/VMS Software Language and Tools Handbook" (PDF). bitsavers.org. 1985. Retrieved 2020-12-31.
  3. 1 2 3 "IBM RPG Debugging Template", Computer History Museum
  4. "IBM System/3 Model 8, Model 10, Model 12, and Model 15 RPG II Compilers", IBM Program Product Specifications, November 1977, p. 3