📜 ⬆️ ⬇️

First look at the RPG: it turns out, this is not only role-playing games

Many of you have heard of one of the oldest programming languages ​​COBOL, as well as the fact that COBOL programmers are now needed to support the old code. There is another “old-timer” about which few know, which is used now and will be used for quite a long time to write programs in various spheres of human activity (financial, banking, etc.). The name of this language is IBM RPG.

Picture 3

Once upon a time ...


RPG is a proprietary high-level programming language owned by IBM for building business applications. The latest language versions are only available for the IBM i operating system (and its previous versions under the old name OS / 400).

RPG has more than half a century of history. By the end of the 50s, IBM released a huge number of electromechanical machines, called tabs. The latest serial tabulator is the IBM 407 Accounting Machine:
')

Figure 1. IBM 407 in the US Army Arsenal in 1961.

Figure 1. IBM 407 in the US Army Arsenal in 1961.

By the way, renting such a tabulator, depending on the model, cost from $ 800 to $ 920 per month (in terms of the modern dollar - from $ 8100 to $ 9300), and their sale was stopped on December 17, 1976.

As you know, technical progress did not stand still, and by the end of the 50s, transistor computers began to appear. The first such computer for IBM was IBM 1401, released in 1959:

Figure 2. IBM 1401 at the Endicott Center for History and Heritage.

Figure 2. IBM 1401 at the Endicott Center for History and Heritage.

In the Museum of Computer History there is a working copy, I think you will be interested to see how it all worked (especially the words “ We need a little bit of cooling ” are “delivered” at 4:41 ):



To simplify the transition of its customers to new transistor computers in 1959, two tools were also invented at once that simulate the processing of punched cards on a computer - FARGO (Fourteen-o-one Automatic Report Generation Operation) and RPG (Report Program Generator). The syntax of both languages ​​was similar to the command language of electromechanical tabs. In addition, FARGO and RPG repeated an important feature of tabs: they emulated their cyclic mode of operation (program cycle), during which the tabulators read data from punch cards, summarized them and printed the results. IBM and to date provides backward compatibility with the software cycle, even in the last dialect of RPG IV.

Although the RPG was created under the influence of FARGO, after a few years the RPG supplanted its predecessor as a more promising option. And the next system, where the RPG was brought in, was the IBM System / 360 Model 20 mainframe:

Figure 3. IBM System / 360 Model 20 in the German Museum.

Figure 3. IBM System / 360 Model 20 in the German Museum.

A couple of years later (the end of the 60s), IBM provides the following dialect of the language - RPG II - for the average System / 3 computer:

Figure 4. The average IBM System / 3 Model 10 computer with an operator.

Figure 4. The average IBM System / 3 Model 10 computer with an operator.

Since then, the RPG has evolved into a high-level analogue of the COBOL and PL / I languages. A distinctive feature of the language (compared to modern) was the "fixed format" syntax, which made it difficult to read programs without a special debug pattern.

Figure 5. Debug pattern.

Figure 5. Debug pattern.

Programs began with file specifications (File Specifications) —a list of all files to be read, written, or updated. They were followed by a Data Definition Specification (Data Definition Specifications) - a list of program elements, such as data structures or arrays. This block resembles the Working-Storage section in COBOL or the commands with the “var” keyword in Pascal. To indicate the type of a variable, the corresponding symbol is written in column 40 of the definition specification (see the table below). If it is omitted, i.e. instead there is a space, then the default type is A , provided that no decimal places are specified. Otherwise, the default type is P.
Data type
Title
Length
Description
*
Pointer to based variable

Procedure pointer

System index
16 bytes
Access to data

Appeal to the activated procedure

Accessing an object file
A
Alphanumeric character
From 1 to 16 773 104 bytes (fixed length)

From 1 to 16 773 100 bytes (variable length)
Letter or number
B
Binary number
1 byte (8-bit)

2 bytes (16-bit)

4 bytes (32-bit)

8 bytes (64-bit)
Binary signed integer
C
UCS-2 character
1 to 8,386,552 characters (fixed length)

1 to 8,386,550 characters (variable length)
16-bit UCS-2 character encoding (DBCS or EGCS character set)
D
date
10 bytes
Date: year, month, day
F
Floating point number
4 bytes (32-bit)

8 bytes (64-bit)
Floating point binary number signed
G
Graphic symbol
1 to 8,386,552 characters (fixed length)

1 to 8,386,550 characters (variable length)
16-bit graphic character (DBCS or EGCS character set)
I
Integer
1 byte (8-bit)

2 bytes (16-bit)

4 bytes (32-bit)

8 bytes (64-bit)
Binary signed integer
N
Symbol indicator
1 byte
'1' = TRUE

'0' = FALSE
O
Object file
Size unknown
Object file link
P
Packed Decimal
1 to 63 digits

2 digits per byte plus sign
Decimal number with a fixed point, signed, with integer and fractional parts
S
Unpacked decimal number
1 to 63 digits

1 digit per byte
Decimal number with a fixed point, signed, with integer and fractional parts
T
Time
8 bytes
Time: hour, minute, second
U
Integer
1 byte (8-bit)

2 bytes (16-bit)

4 bytes (32-bit)

8 bytes (64-bit)
Unsigned integer
Z
Time stamp
26 bytes
Date and time: year, month, day, hour, minute, second, microseconds

Next, specify the specifications of calculations (Calculation Specifications) - a list of commands for execution. Output specifications could also be added, defining the type of output files or reports.

I will also provide additional information on all types of specifications:


And now a small example for warming up your eyes (file specifications and data definitions are omitted):

*  (*)   7  - *   6    . , *      (,  , *  , ...). *  "C" (calculation) -  C HOURS IFLE 40 C HOURS MULT RATE PAY C ELSE C RATE MULT 40 PAY 72 C HOURS SUB 40 OTIME 30 C RATE MULT 1.5 OTRATE 94 C OTRATE MULT OTIME OTPAY 72 C ADD OTPAY PAY C END 

The code is hard to read, is it? And here, only a payroll tax is calculated for an employee with hourly wages (employees who have processed 40 hours receive a one-and-a-half rate).

In 1978, IBM introduced both the System / 38 medium computer and the new dialect of the language - RPG III - for it:

Figure 6. The average IBM System / 38 computer

Figure 6. The average IBM System / 38 computer

From this point on, the limitations of the language are somewhat relaxed and it is allowed to write specifications of calculations in a “free format”:

  /free If Hours <= 40; Pay = Hours * Rate; Else; Pay = (40 * Rate) + ((Hours - 40) * (Rate * 1.5)); EndIf; /end-free 

And finally, the latest version of the dialect - RPG IV (aka RPGLE, ILE RPG) - was released in 1994. The three main “features” can be called built-in functions, procedures and “free format” of programming. Until November 2013, the free format was available only for computing specifications. In the V7R1 TR7 update, the commands "/ free" and "/ end-free" were abolished, and the language was finally freed from the heritage of the era of punched cards.

I also suggest that you read this brochure , in which IBM shows how much the dialect of the language has changed. The language itself is now widely used under the IBM i OS on the IBM Power i hardware platform:

Figure 7. IBM Power i server line

Figure 7. IBM Power i server line

In total, the RPG language managed to visit such computers as 1401, System / 360, System / 3, System / 32, System / 34, System / 36, System / 38, AS / 400 and System i. There were also implementations for Digital VAX, Sperry Univac BC / 7, Univac system 80, Siemens BS2000, Burroughs B700, B1700, Hewlett Packard HP3000, ICL 2900 series, Honeywell 6220 and 2020, Four-Phase IV / 70 and IV / 90 platforms , Singer System 10 and WANG VS, as well as a variety of compilers and execution environments for Unix systems, for example, Infinite36 (formerly Unibol 36), and PC (Baby / 400, Lattice-RPG).

By now, the RPG language has developed into a strong, viable language. Programs can still be written in the usual editor in black and green colors (green-screen):

Figure 8. Green-screen.

Figure 8. Green-screen.

However, many other tools have appeared. Among them - Visual Age for RPG, developed by IBM and promoted by John Paris (Jon Paris) and others. The most popular editor at the moment is IBM Websphere Development Studio, later renamed RDi (Rational Developer for i), which is a custom implementation of Eclipse:

Figure 9. Rational Developer for i.

Figure 9. Rational Developer for i.

The RPG compiler is also implemented for the Microsoft .NET platform. In addition to the basic version, it includes additional RPG IV language extensions, which allows Microsoft Windows and .NET to use the Native and System / 36 environment, as well as to port DB / 2 files to Microsoft Access and Microsoft SQL Server databases via the ODBC interface.

Conclusion


Although the language is an exotic, we understand that a lot of code is written on it for financial, banking and other activities. It is quite diverse: there are 4 dialects, fixed and free forms of syntax. The need to support the old and writing new code forces companies to look for RPG-programmers , who, apparently, are already listed in the Red Book. In such conditions, there is a need to use additional code quality control tools, such as, for example, a static analyzer.

Perhaps the reader has already guessed why we decided to write this article, and what we are getting at. Yes, we are thinking of creating a static code analyzer for the RPG language. I think such an analyzer will be a great help to those who continue to accompany and develop programs in this language. However, the decision has not yet been made. I think you understand that this is a very specific direction.

Therefore, if you want the PVS-Studio analyzer to learn how to look for errors in RPG programs, write to us. We are looking for you, dear potential customers of PVS-Studio RPG. Write to us!



If you want to share this article with an English-speaking audience, then please use the link to the translation: Phillip Khandeliants. First look at RPG: turns out not only Role-Playing Games

Source: https://habr.com/ru/post/345064/


All Articles