RPG Open Access Revisited

Print

For this month’s column, we thought we’d revisit the subject of RPG Open Access (OA). Why? Because during several conversations at recent conferences it became obvious to us that IBM’s initial decision to charge for the feature caused many people to simply ignore it. They took a quick look, decided that there was no immediate payback and therefore no way they could persuade their management to buy the product. They simply walked away.

By the time Rational saw the error of its ways and decided that OA should be available as part of the compiler, a decision we applaud, it was too late and the window of opportunity had passed.

Another factor is that so much of the emphasis at OA’s announcement was on updating 5250 applications that the wealth of other potential uses for it were completely missed, and that’s sad because OA has a lot to offer. We’ve also been told on many occasions that there’s a dearth of education in the realm of OA, so by going back to the beginning we’re hoping to remedy that situation in this new series.

Why OA?

We thought we’d start by looking at some of the questions we get asked when we discuss OA with RPGers. A common question is “Why did IBM bother with Open Access?” This is often hand-in-hand with “Why didn’t IBM simply add browser handling to RPG?” Ignoring for the moment that there’s nothing “simple” about adding browser support to the language, there are a number of points to make here.

First, the question tends to make the assumption that OA is only intended for 5250 replacement. We understand how people might get this impression because that’s where all the big publicity and the vendor activity has been. However, such an emphasis misses the point to a very large extent.

Second, the real answer to “Why OA?” is that IBM simply can’t get new features into our hands fast enough. Perhaps more to the point, even if it were to develop them faster, we as the user community tend to take far too long to adopt them. The result is that even if IBM were to identify a need in the marketplace, code and release it within a matter of months, it would still be some two to three years in total before a significant percentage of the user community could use it. Why? Because we typically take 12 to 24 months to deploy new releases. It is this reluctance that has caused IBM to look to Technology Refreshes as the preferred release mechanism, and of course to introduce OA.

Third, most modern languages have some form of API or other integration mechanism through which new features can be added. RPG of course also has such a mechanism; it’s known as Service Programs. But new interfaces presented in the form of subprocedures don’t “feel” like RPG to many folks. To understand why, think for a moment about what happens when you run an EXFMT. The compiler-generated code gathers all of the fields in the record format together, places them in the buffer along with any required indicators, sets up the user interaction with the device, and, following the user interaction, proceeds to distribute the input capable fields and indicators in the buffer to their respective storage locations back in the program again. Having done so, it then wakes up your program and continues running your logic.

That’s a lot of data gathering and distribution that, when you’re using an API model, you typically must code by hand. Admittedly, operation codes such as RPG’s recent EVAL-CORR (Evaluate Corresponding) can alleviate this tedium somewhat, but nevertheless there’s an amount of work involved that RPGers aren’t accustomed to doing. They basically expect to wave their magic wands (EXFMT, CHAIN, READE, etc.) and have data magically appear in the appropriate spots. With an API interface, that just doesn’t happen in the same way.

When the idea of an RPG browser implementation was first floated we admit that we felt that it was unnecessary and that using APIs just wasn’t that hard. Perhaps our experience with other languages that didn’t do as much work for you made us feel that way. In recent years though we’ve come to realize that it’s the ease-of-use of the RPG approach that in many ways characterized the language. We still strongly disagree with those who believe that IBM should add a browser interface to RPG. We think that OA is a much better choice because it opens so many more doors.

Our industry is changing so quickly that we need a flexible approach that will allow us to interface to any device. Not just the ones we know about today, but those that will join them tomorrow. OA gives us that potential. It doesn’t matter whether the device is a Web browser, a mobile phone, a Web service, an Excel spreadsheet, a simple CSV file or perhaps even a lightsaber. By implementing the appropriate handlers, it becomes possible for RPG to access such devices even if IBM has never even thought about them.

Since OA handlers are just programs (or subprocedures for that matter), they can do anything that the language in which they’re written permits. A handler could effectively be written in C or C++ or Java or PHP or, of course, RPG. In fact, the majority of the handlers we’ve written to date have been written in RPG although many of them do interface with C and Java functions.


Two Kinds of OA Handlers

Print

As we reported in previous articles, although we tend to use the term “handler” as if it were a single entity, there are in fact two completely different kinds of handlers that can be written.

The first is normally referred to as a buffer handler. In this instance, the data passed between the handler and your program is in the form of a simple buffer that matches the record format. In this sense, it’s very much like the interface used by the old SPECIAL files, with the exception that a lot more additional information is provided than was ever available with those files. It also doesn’t have the limitations of SPECIAL files in terms of the kinds of operations supported. OA can use virtually any type of file and any opcode that relates to that file.

The second kind of handler, and the one in which it’s easier to write generic handler routines, is known as a Name/Value (NV) handler. Rather than receive all of its data in one lump, an NV handler deals with one field at a time. If the handler is responsible for an output operation, it will receive the field name and its details together with the actual data for each output field in the record one after the other. If the handler is performing an input operation, then it’s expected to supply the contents of the requested fields based on the information provided for data type and size.

So how do you determine which type of handler you should write? We look at it this way:

Use a buffer handler if the processing requirements are so specific that they cannot readily be parameterized.

An example of this might be a handler for Web services. Since each type of Web service will have very different processing and data requirements, it’d probably be impractical to have a generic handler that could handle every single one. For example, the data required to perform a tracking operation with UPS is different from that required for getting a currency exchange rate or perform a Google search or charge to a credit card. Even using a generic handler for tracking packages may not be feasible since the UPS tracking has different requirements and format than the United States Postal Service or FedEx. The basic mechanisms (i.e. typically a SOAP Web service) are the same, but the differences would be difficult to parameterize. So you might choose to write a separate handler for each of these services using different record formats for each kind of request and response. You’d still use the same underlying software, for example Scott Klement’s HTTPAPI to perform the actual Web service operations.

Another case where you’d probably choose to use a buffer handler is any situation where the handler itself neither needs to know or care about the format of the data. It can simply treat it as a “blob.” An example of this would be something like a message queue handler. The basic mechanism by which the handler interacts with the message queue is the same no matter what the actual data content of the message. The job of the handler is simply to process the message it really doesn’t care what the contents are.

Use an NV handler when you want to adapt the output of an existing program, or where the behavior is consistent and/or readily parameterized.

For example, the IFS output handler we introduced in “Getting a Handle on RPG’s Open Access” uses the record format to determine the fields to be output. So by simply using a different record format layout, it’s able to produce a completely different CSV file.

Similarly, updating values in an Excel spreadsheet would be the same no matter what the spreadsheet. We could index into the “file” using the row and column identifiers as the key. It doesn’t matter what spreadsheet we use, we can still index it in the same way. In some cases, of course, we might also need to concern ourselves with the actual sheet as well, but even then the behavior is consistent.

Designing a Buffer Handler

So let’s talk a little bit more about how we’d design a buffer handler. For our example, think about a simple currency exchange rate Web service. In this case, a buffer handler appears to be the most obvious approach.

The first thing to consider is what opcodes and file type are the best fit in RPG terms. Consider how a Web service is used. You pass it a set of values and it returns information based upon those values.

In a currency exchange service, we pass it the identifiers for the two currencies and it returns the exchange rate between those currencies. Imagine that you already had information about all the current currency values in the world stored on your system through some mysterious mechanism. You might reasonably expect it to be in a database and that you could retrieve the data using the currency identifiers as the keys. In RPG terms, that means the file type would be DISK and we’d retrieve the data using a CHAIN. Sounds like a good model for our handler to use.

Having made that decision, all that remains is to determine the file name, its record layout and key fields. Once this is done, we can create a physical file that matches these requirements. The key fields will be used to provide information to the handler about what currencies are involved (and for some currency services the amount to be exchanged). The remaining field(s) in the record will be filled in by the handler to provide the current value just as a conventional RPG CHAIN would populate those fields from a database.

All that remains is to write the handler—and that will be the topic of our next article (but if you just can’t wait email us and we’ll be glad to send you an advance copy of the program).