After a first analysis about the ILE RPG components and the binding logic, see the previous post at the link https://linkedibmi.com/2018/05/02/rpgile-components/ , I want to have a look deeply inside the use of the code, trying to discover and explain the main differences between old RPG and ILE RPG.
PROGRAMMING STYLE – OLD AND NEW CODES
I discussed previously about the advantages of ILE RPG in term of readability: extended rows and indented code are only a few of the advantages available to improve the code readability.
In general, the best way to use ILE RPG is the complete free-form style: this avoid mixture of code and keep the code more readable. In addition to this it is important to code in a modern style avoiding bad and old habits and practices: in the modern language a lot of obsolete codes has been removed to use new modern codes. For example the following codes has been removed and are no longer available:
MOVE, MOVEL, GOTO, DOXX, WHXX, IFXX, ANDXX, ORXX
For a good programming style you should also avoid numeric indicator (*IN01-*IN99) and special indicator (*INU1-*INU8), because they are not self-explanatory and you should use Boolean variables to show better the meaning of the conditions.
If the program defines a display/print file with resulting indicators, you could define an Indicator Data Structure to remap them inside the program with meaningful names.
OLD A NEW SPECIFICATIONS
One of the stronger changes in free-form language of ILE RPG, from the 7.2 version, was to provide alternatives for all data declarations and for many file declarations.
This release removes too the need for the /Free and /End-Free directives. The compiler assumes that the source line is in free-form if columns 6 and 7 are left blanks.
F and D spec entries become declarations. A declaration starts by the string DCL and is followed by the type of declaration. All the new declarations follow the same basic format, in the following order:
- the name of the item (file, DS, field ….)
- keywords to replace the column-sensitive entries
- any keywords that are in the D and F spec option columns
- a semi-colon (; ) that terminates the definition
Another important change is the introduction of a number of defaults: for example all files are assumed external unless otherwise specified; all numeric fields are assumed to have zero decimal unless otherwise specified and so on.
I realized the following table that resumes the different kind of specifications used in the old and new languages. It could be not perfect or exhaustive but it will let you have an idea of the language evolution:
|OLD Version of positional RPG||H SPEC
Records, fields, DS, Constant
|ILE RPG positional||H SPEC
| D SPEC
Fields, Constants, DS
|Free form ILE RPG||ctl-opt
| dcl-s dcl-ds
Fields, Constants, DS
In the same way of file declaration you could define prototypes, interfaces and procedures by using the declarations:
And everyone of these have the corresponding END-XX tag.
Now, with more details, we could analyze a bit the new kind of specifications:
A) H Specifications become ctl-opt but it has similar meaning and use, for example:
B) F specifications become ctl-f
You don’t need to tell the compiler that files are externally described even if RPG let you specify *EXT as a parameter to the device type keyword. With the new default you can omit the device type and the compiler assumes an input DISK file. In the same way you don’t need to specify that a PRINTER file is an output file. The default file usage is related to the device type and you could specify it only when you want to change the default value.
So the following declarations are equivalent:
Dcl-F File_name Disk;
Dcl-F File_name Disk(*Ext) Usage(*Input);
The following tables show you the default types and their usage:
C) D Specifications become dcl-s or dcl-ds
D specifications are replaced by the following, showed in this table:
The important thing is that now we use keyword instead of code. For example alphanumeric fields are now declared by the expression:
and packed by:
PACKED(digits : decimals)
For a complete list of fixed form and free form data definition correspondences, see the following tables:
NEW AND OLD OPERATION CODES LIST
In the following tables that I got from the “Rational Development Studio for i
ILE RPG Language Reference” we have the list of the OPERATION CODES both in Free-Form Syntax (based on version 7.1 of the operating system) and the Traditional Syntax. Tables are enriched by Exenders to add meaning.
The next table lists all operation codes about TRADITIONAL SYNTAX: