Open Access and new built-in functions top the list
Did you hear there was an IBM i 7.1 announcement recently? In some IBM i announcement events in recent years, trying to glean any information about RPG language enhancements among the deluge of new features was difficult, if not impossible. That, and the fact that many shops don’t even think about installing a new release until it has "aged" a few months (or years), has caused some RPGers to barely pay attention when a new OS is released.
The 7.1 announcement is a bit different. The new Rational Open Access: RPG Edition (ROARE, anyone?) has the application-development industry abuzz with excitement. Several ISVs have already announced new tools that can take advantage of this new RPG feature and many others are working to launch their own products to exploit the new support. But if anyone thinks that with such a "big" new feature being added to the language, that’s all the Toronto-based team of RPG compiler developers had time to do, think again! Even if Open Access doesn’t float your boat, you may be interested in some of the other nice new goodies the RPG language has to offer in 7.1.
Open Access for RPG
First, let’s take a look at the Open Access announcement. Open Access is support that opens up the RPG language for people outside (or even inside) IBM to provide tighter integration between their solutions and RPG. RPG has always been about integration, flexibility and simplicity. RPG is "our" language—it belongs to IBM i programmers. Sure, IBM i can run COBOL, Java and PHP applications—and it does so very well. But if there were to be a designated "native language" on the system, many would say it should be RPG. RPG has grown up with IBM i. Today’s modern flavor of RPG is barely recognizable as the same old language of fixed column logic, lumbered with the use (and abuse) of 99 numbered indicators and a logic cycle that was well suited for printing reports on paper! Today’s RPG has kept pace with IBM i itself, which is also barely recognizable as the same platform that ran on those early white AS/400 boxes rolling off the line in Rochester. So RPG and IBM i have a lot in common; One thing is different—RPG is still called RPG (albeit RPG IV these days). The operating system—well, let’s not go there today.
But what is Open Access exactly? It’s a way of extending the RPG language using the native-language I/O operations such as READ, CHAIN, WRITE, EXFMT to perform functions way outside their traditional use with database, display and printer files. What kind things can you do with these operations using Open Access? The sky’s the limit! Because Open Access means that anyone—from major software vendors to that clever bit-twiddling programmer who works down the hall—can write programs or procedures that get control when an RPG program issues a READ or EXFMT operation to a file.
So, an EXFMT may end up displaying a browser screen instead of a traditional green-screen display file. A READ may bring in data from the IFS instead of database. A CHAIN may access random elements in an XML document. A WRITE may send an e-mail. How can all this happen? Has IBM enabled direct browser, IFS, XML and e-mail support into RPG? No, it’s done much better than that. It’s supplied the "hooks" necessary to enable anyone to write the "handlers" for those and endless other options and to integrate them into simple I/O operation codes.
Now this may be sounding familiar to those of you who’ve been following our recent articles in IBM i EXTRA. Our last two EXTRA articles have talked about how this kind of integration can already be done—in a more limited fashion—via the use of the Special Files support that’s been in RPG for decades. The new Open Access support does away with many of the old Special File limitations and makes it far easier to write truly generic handlers, thanks to the compiler supplying much more information to the OA handler than was available to Special File programs.
What would it look like to an RPG programmer writing a program that uses an OA handler? Something like this:
FMyFile OF E Disk Handler('OASRVPGM(SENDEMAIL)')
They’d then perhaps build the contents of the e-mail in the logic, supplying the salutation, e-mail address and other content details via fields in the externally described "MyFile" file. Then when the "record" is written, the SENDEMAIL procedure in the OASRVPGM would get control and use the information to create and send the e-mail.
To the writer of the handler, this new support supplies the contents of the "record" that was written and the operation (i.e., OPEN, WRITE, CLOSE, etc.) that was performed, just as the old Special File support did. However, it also can supply the external record description, complete with the definition details of each field—way beyond what a Special File program received. And as you can see in this example, an OA handler can be either a program or a subprocedure in a service program. OA handlers are also not limited to sequential access operations as Special Files are.
So open up your minds to the possibilities of what Open Access could mean for you and your applications. For that matter, you may even discover that you can actually realize many of the items on your wish list by using the existing Special File support, long before you may be in a position to install Open Access.
By the way, the Open Access support is available for 6.1 systems as well as 7.1, so you may not have to wait as long as you thought to be able to explore the possibilities.
We should mention that the new Open Access support has an extra charge associated with it—it’s not included with the RPG compiler at 7.1. But for the flexibility and simplicity of interface that it provides, the price shouldn’t be a stumbling block to forward-thinking shops.
Open Access and new built-in functions top the list
What Else?
What about those other RPG language goodies—the ones that will be included in the 7.1 compiler?
There’s new support for sorting and searching data in Data Structure Arrays. So imagine, for example, that you have subfile data stored in a Data Structure Array and you want to allow the user to see the data in sequence by any field in the subfile. It might look like this.
D ProductInfo DS Dim(1000)
D Qualified
D Name 8
D UnitPrice 5p 2
D QtyInStock 5p 0
If SortByName;
SortA ProductInfo(*).Name;
ElseIf SortByQty;
SortA ProductInfo(*).QtyInStock;
ElseIf SortByPrice;
SortA ProductInfo(*).UnitPrice;
EndIf;
The * indicates the level at which the sorting should occur. Of course, in this example, it’s pretty obvious, since it’s the only level where sorting is possible. But this sorting capability also works with nested Data Structures, so even very complicated structures can be sorted. Additionally, two new operation extenders are available for SORTA—A for ascending and D for descending, which makes the sort capability even more flexible.
%LookUp is also enhanced to work with data structure arrays. So given the DS in the example above, you could search on the name field using:
Element = %LookUp( 'ABC': ProductInfo(*).Name);
A new built-in function, %SCANRPL, combines the functions of %SCAN followed by a %REPLACE, making it easier than ever to send out mail-merge letters or e-mails, replacing placeholders in the text with the appropriate content of database fields, for example.
Some enhancements relating to subprocedures are also very nice. The best of these is that the compiler will no longer require prototypes for subprocedures that are internal to the module from which they’re called. That will make life a little easier for those of you who, like us, use subprocedures as subroutine replacements.
Additionally, if your subprocedures return very large values, such as returning the content of an entire record format, you now have the option to have the return value be treated as if it were a "regular" parameter (i.e., a pointer is passed instead of the data itself). This is accomplished by specifying the RTNPARM keyword on the Procedure Interface and Prototype, and can result in significant performance improvements, especially when very large return values are involved.
When you specify RTNPARM, the return value is passed as the first parameter in the parameter list. Therefore, if your subprocedure currently makes use of %PARMS to determine if optional (i.e., *NoPass) parameters have been passed, you’ll also want to make use of another new built-in, %PARMNUM. It takes a parameter of the name of the parameter, so that the following code would check to see if any optional parameters were passed:
If %Parms >= %ParmNum(FirstOptionalParm);
If FirstOptionalParm was the third parameter, then %ParmNum would return 3 if RTNPARM were not in effect, but it would return 4 if RTNPARM were specified.
Those of you who delight in the fact that we can now create longer field names than the traditional RPG six-character names may appreciate the fact that RPG will now be able to access and use the longer ALIAS names that can be specified either in DDS or via SQL. Of course, since I and O specs are generated by default for files on any F spec (and I and O specs still have size limitations for the names), if you want to use the longer ALIAS names instead, you must either specify QUALIFIED on the F spec in addition to the ALIAS keyword or define the file in a subprocedure. The ALIAS keyword may also be used when defining an externally described DS
More Later
A few other RPG enhancements were announced as well, but we’ll save those for a later edition of EXTRA. We picked out here the new features that we felt were going to be most useful to the majority of RPGers.
We’ll provide more details on the new functions in RPG as soon as we get a chance to read the manuals and delve into the details ourselves.
In the meantime, check out Special Files and think about the kinds of things you may be able to do already today that can be made even better tomorrow with the Open Access support. For some inspiration, see “The Ever-Evolving Role of RPG” and “Get More from RPG.”