Informing the IBM Community

RPG – What’s New in 7.3

0
(0)

 

As you probably know, IBM released 7.3 of the IBM i operating system in April 2016.  So now it has been over six months since the new release, let us take a look at what has changed in RPG for this release.

Remember that SEU has not been updated since Version 6.1 way back in 2008, so use the latest version of Rational Developer for i Version 9.5.1 to stop any annoying syntax errors when coding.

Total Free Format

The first point to note is that all the examples shown within this article are using the total free format that IBM introduced a couple of years ago.

For those that haven’t used total free form RPG, you will be impressed how RPG has changed into a language that programmers from other languages/platforms can easily read and maintain the code.

For our source to be totally free, we specify **FREE on the first line.  It can be in any position, forget about columns.  It must also be the only entry on line one.

By specifying **FREE it eradicates the need for us to code /FREE and /END-FREE.

By testing on 7.3 of the RPG compiler, it seems we can omit **FREE and the compiler will still assume we are using total free RPG, but we will not be able to use columns 1 to 5, so its good practice, get used to specifying **Free.

Users of other programming languages, like PHP and ASP, use directives like <?PHP and <% so we should get used to using the **Free statement.

It is also worth noting that if we have to use specifications that cannot be free, like Input and Output specs, we have to code these in a copybook.

Using free, we can place our source anywhere on a line, the only restriction on the length of each line is the source file our code resides in.  If you are storing your source on the IFS, there are no restrictions on line length.

New Built-in Functions

In this section we will show you how to use the new built-in functions (BIFs) in this release.

Scan

The %Scan BIF has been enhanced to allow you to specify the length of the scan to search for a particular string.

Scan Reverse

As I’m sure you can guess, the Scan Reverse function (%ScanR) looks for a string in its last position.

In the figure below we have:

Step 1 – A traditional %Scan example (Not new for this release)

Step 2 – Only search for a string in positions 20 – 29 (10 characters) – As the string wasn’t found, the function returned zero

Step 3 – Again, search for a string in positions 20 – 29 (10 characters) – This time getting the case correct!

Step 4 – Do a reverse scan, searching for a string from the right hand side

ay-dec16-01

ay-dec16-02-top-tip If you have problems trying to working out the sequence of parameters of the search BIFs, remember the first parameter is the needle, the second parameter is the haystack – hopefully that helps.

Alias

The Alias keyword, for the file definitions, will allow you to use the long names for the column/field names.

If our Employee table has the following columns;

ay-dec16-03

We can use either the short name for our employee surname (EMSUR) or the long name (Employee_Surname), making our coding more readable, and therefore, more maintainable.

In the figure below:

Step 1 – Define the file with the Alias keyword

Step 2 – Read the file in our calculations

Step 3 – Use the table alias names instead of the traditional short system names

ay-dec16-04

Maybe an enhancement in future will allow us to use the long names for files as well.

Data-Structure Enhancements

There has been a small change to data-structures that makes using them for IO operations easier.

If we define an externally defined data-structure with the *All parameter, we can now use this data-structure as the target for any IO operational code that supports placing the IO into a data-structure.

In the following example, we have defined the data-structure dsCarp as externally described based on our CARP file, and it can be used for all IO operations.

ay-dec16-05

A nice touch IBM, saves us having to define different data-structures for different IO operations.

Control Enhancements

The control section of our RPG (the H-specs to us old uns), has been enhanced to allow the PgmInfo keyword, to specify *DclCase as a parameter.

This parameter will generate PCML information in the same case as that specified in your program/module.

Another, very small enhancement, is to specify the control keyword DclOpt, with a parameter of *NoChgDsLen.  This additional parameter allows us to define a data-structure without a length even though one of the sub-fields is based on another field.

ay-dec16-06

Conclusion

Hopefully this article has given you an insight into what RPG has been about in this new release and the features that have been added to this very powerful language.  It has certainly come a long way from the System/34 RPG I started coding on.

To summarise, there were not a lot of RPG enhancements in 7.3, compared with previous releases, let’s hope for more in future TRs (Technology Refreshes) and new releases, obviously the move to total free was the broadest enhancement for some time.

I only wish my clients would upgrade their machines to allow me to ditch my RPG II skills (It will never happen!).

RPG has certainly come a long way since its Report Program Generator days (I can see the comments come flooding in, it normally does when I state that RPG is Report Program Generator, who is going to be first this time!)

Andy Youens is an IBM i consultant/instructor at Milton Keynes, UK-based FormaServe Systems.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.