This tip is an excerpt from the May 2001 issue of Inside Version 5. It is provided courtesy of The 400 Group.
Take a little bit of C, a pinch of Java, a hint of CL, and a dash of common sense, and you get the new version of RPG that IBM cooked up in V5R1. This latest release is a major improvement. But, of course, I might be a bit biased, since IBM finally "fixed" some of my long-time pet peeves with the language. Nonetheless, I suspect most folks will likewise find the new version of RPG a refreshing change for the better.
Many programmers have a fear of C. To the uninitiated, C's use of symbols like [], ->, **, & and . might make C look cryptic. But believe me, C has a lot to offer, and IBM has steadily realized this over the years and has made many improvements in RPG based on features of the C language.
The latest is the LIKEDS keyword and its requisite qualified data structure subfield names. The LIKEDS keyword allows you to define one data structure based on another data structure. The new LIKEDS keyword is to data structures what the LIKE keyword is to fields. This allows you to create data structure templates. Hooray!
True, I would have liked it much better if IBM had followed C a bit closer and implemented this by allowing programmers to create their own data types (i.e., user-defined data types), but you take what you can get.
No matter how it's done, defining a data structure based on another data structure requires that you can qualify the subfield names. This is done by using the new QUALIFY keyword on the data structure specification. The subfield names will then be qualified with the data structure name and a period as in DS.SF.
In this age of APIs, with their frequent use of complex data structures, these new features are a big plus.
A pinch of Java
Improved Java-RPG interoperability has been a big thing to IBM for some time now. I'm not quite sure the installed base is quite up to that speed, but it sure sounds good in a marketing piece. Any which way, the process is about complete with the latest improvements.
Calls between Java and RPG can now use the Java Native Interface (JNI). You can also now define object-type variables.
The new Object data type allows you to define a variable as an object and the new CLASS keyword allows you to specify which class to use to create the object. Details are still sketchy as to what exactly you will be able to do with objects besides pass them to Java procedures. We'll keep you posted.
A hint of CL
It can hardly be said that CL is a state-of-the-art programming language, but for the most part, it does get the job done. It also has a pretty good exception-handling model. It should, since it closely mirrors the lower-level MI exception-handling model.
The CL exception-handling model allows you to put a "monitor" on a single statement, or on the entire program that will monitor for one or more message IDs. You do this by using a MONMSG command. If one of the messages identified on the MONMSG command is generated, you can branch the program to do whatever type of recovery or message-percolation you want (using the EXEC parameter on the MONMSG command).
Those programmers who appreciate CL's exception-handling devices will be happy to learn that IBM has added a similar model to RPG. True, since the inception of the ILE exception-handling (a.k.a. condition-handling) APIs, you could replicate and even improve upon the CL exception-handling model in RPG. However, with the introduction of three new op-codes -- MONITOR, ON-ERROR, and ENDMON -- in V5R1, you'll be able to do it intrinsically without having to mess with procedure pointers and registering condition-handling procedures.
The MONITOR and ENDMON op-codes are used together (like the IF and ENDIF op-codes) to surround a group executable statements and monitor them for exception. Should one occur, the ON-ERROR op-code is used like the EXEC parameter on the MONMSG command to tell the system what to do. RPG's new exception-handling implementation actually more closely resembles that of MI than CL since MI allows this type of statement group (whereas CL's MONMSG command only lets you monitor the entire program or just a single statement).
RPG makes exception-handling so easy, maybe more programmers might actually do it now. One can hope.
========================
MORE INFORMATION
========================