The workhorses behind the majority of applications in IBM i shops remain RPG and DB2* database software. That’s not to say, though, that these are your father’s tools.
Today’s RPG IV, for example, is barely recognizable as the same language as the original column-oriented, indicator-laden version that launched over 20 years ago. The power, flexibility and simplicity of today’s free-format RPG IV are often under-valued. In its latest incarnation it is a powerful, business-oriented language readily embraced by today’s programmers, whether their background be Java*, PHP, C# or any of the myriad other languages vying for attention.
RPGers who don’t feel they need to understand or deal with CCSIDs today will almost certainly need to in the future.
RPG is not alone. Major updates have greatly extended the scope and usability of DB2 for i. These include some surprising recent enhancements that surface system information previously only obtainable through APIs and outfiles.
Other areas of the system have also grown radically. The original AS/400 supported RPG, COBOL, PL/I, Basic and Fortran. Today’s IBM i has added Java and PHP to that list, and more recently, Node.js and Python. And it doesn’t stop there. Along with PHP, ZendDb (Zend’s implementation of MySQL for IBM i) opened the door to high-quality open-source software such as Drupal, WordPress and SugarCRM.
The latest addition arrived late last year when IBM announced the availability of the GNU Compiler Collection (GCC) on IBM i. Why is this important? Because nearly all open-source language implementations were written with these compilers in mind. Similarly, many open-source packages rely on GCC tooling, all of which can now be readily ported to the system.
The downside is that developers can no longer hope to keep current with everything happening on the platform. As a result, we have been forced to narrow our focus and concentrate primarily on application development in RPG, PHP and DB2 SQL. Of course, we also make extensive use of the Rational* Developer for IBM i (RDi) tool set. Even so, it’s hard to keep up with everything happening in this restricted sphere. Just in case you find it as hard to keep up as we do, here’s our summary of the recent major happenings in the worlds of RPG and SQL.
Freeing RPG
The most noticeable changes made to RPG in recent years are related to free-format coding capability. The ability to code the logic in free format came about in 2001. Most RPGers took to it like a duck to water and have never looked back—except, perhaps, when forced to maintain old code that hasn’t been converted yet.
Free-format logic’s most important impact was in the ability to attract/convert new RPGers, particularly those with experience in another language and/or platform. While the old fixed format coding syntax wasn’t any more difficult to learn, it looked strange compared to any other language. Plus, it was clearly more difficult to maintain, especially without special tools built into the editor to help with deciphering nested logic. Free-format logic meant RPG looked much like PHP, Java, C++ or other languages programmers are likely to know.
For many years, logic was as far as the free-format transformations went. Other significant features were added to RPG in the meantime. But for quite a while, some began to think that when it came to free-format RPG, logic was as far as it would go. Then, late in 2013, RPGers everywhere received an early Christmas gift when it was announced that the rest of the RPG language would go free format as well.
With data, file and procedure declarations all in free format, RPG began to look and feel like many other programming languages, and the last major hurdle in teaching it disappeared. Our first experience teaching this new version of RPG was to a group of Java programmers who not only found it easy to learn, but were also surprised at the ease of developing powerful business logic. By the end of class, they were beginning to create a list of Java programs they wanted to rewrite into RPG because its business focus simplified many aspects of the code.
Finally, late last year, another enhancement removed one last remnant of RPG’s fixed format heritage. Even though virtually all aspects of RPG could be written in free format, we had still been limited to coding between columns eight and 80—a legacy of RPG’s humble beginnings in the days of the punch card. With the latest support, our code can begin in the first column and extend as far as the developer decides to make available. Now, RPGers can join the ongoing debates about the ideal length of source lines.
Most existing RPGers may not be in a rush to take advantage of this extra freedom, but it does remove one of the last oddities about the language in the eyes of programmers coming over from other languages.
What Else Is up With RPG?
The format of the source code is not the only thing new in RPG-land. The XML parsing support using the simple and powerful XML-INTO operation, originally introduced in OS/400* V5R4, has become even more flexible and usable in recent releases. Support options exist for dealing with namespaces (using options ns and nsprefix) as well as handling XML names with characters invalid in RPG (the case option). It also provides simple ways to retrieve counts of repeating elements (using option countprefix) and the capability to handle both attributes and text for an XML element (using option datasubf).
Support for handling and converting CCSIDs in RPG is already critical to applications in many parts of the world. RPGers who don’t feel they need to understand or deal with CCSIDs today will almost certainly need to in the future.
With Web and mobile applications that can be accessed from anywhere in the world, users’ names, addresses and other data will often contain characters not in the default set on the system where the program is running. Unicode provides the ability to deal with any type of character our programs are likely to encounter. RPG’s built-in support for unicode, specifically, and CCSIDs, in general, was strengthened in the IBM i 7.1 timeframe, and 7.2 provides even stronger support, including the capability to declare character fields as CCSID(*UTF8)—a unicode encoding widely used in Web applications.
The current CCSID support in RPG is too extensive to go into the details here. But you will need to understand this someday, if not already. Do yourself a favor and read up on character sets and unicode if you don’t understand them. Then check out the latest in RPG support in the What’s New section of the Integrated Language Environment (ILE) RPG Reference manual (ibm.co/1Q2JyKy). Be thankful that RPG has simplified the handling of different character sets for you!
Many other new features were added to RPG. Some make our code more readable, such as the capability to use the longer alias names for fields created using SQL (or, for that matter, using the ALIAS keyword in DDS). Others have the power to simplify our logic, such as the capability to both sort and search data stored in data structure arrays, or the new built-in function to scan and replace characters in a character field (%SCANRPL). The option to omit prototypes in some circumstances, such as for internal subprocedures and programs that will not be called from RPG, removed an annoyance that bothered many prototype fans.
Some enhancements were aimed at improving application performance in specific circumstances. These include the return as parameter (RTNPARM) keyword for large values being returned from subprocedures and a control keyword that turns off validation checking for dates, times and timestamps (VALIDATE).
RPG Open Access (OA) may not be new, but it deserves attention here because it is so often under-utilized. OA got off to a rough start in life because there was originally an extra charge for it. A few years ago, it became a no-charge part of the compiler. Still, not many RPGers writing code for their companies seem to have latched onto the potential of OA to simplify everyday RPG logic. We’ve written about OA a few times, as have many others. If you’re an RPGer who hasn’t given it a try, listen to Paul Tuohy’s interview of Jon on the subject (ibmsystemsmag.com/ibmi/trends/iTALK-WITH-TUOHY/paris-open-access/), and think of ways to utilize it in your own applications. When you’ve thought of a killer use for OA, you can get a head start on writing your first handler using templates Jon created and describes in an article titled “Open Access Made Easy With Templates” (ibmsystemsmag.com/ibmi/developer/rpg/open-access-templates).
How to Edit Modern RPG Code
RDi is the only editor from IBM that supports the latest RPG language enhancements. The green-screen editor (SEU, typically accessed via PDM) is stuck back in 6.1 for language support. This means there’s no support in that editor for any of the newer features that have been described. If you’re still coding your RPG from a green screen, the first step to modernize your RPG is to modernize your development toolset.
If getting support for new language functionality is your primary reason to move to RDi, you’ll soon find dozens of even better reasons that will make you wonder why you didn’t make the move years ago! There’s the ability to see 2-3x more code at once; have different source members open for edit at once; find and fix compile-time errors quickly with no compile listing needed; and filter the source in numerous ways—and then there’s the outline view. For guidance in getting started with RDi, download our RSE Quick Start Guide (systemideveloper.com/downloadRSEQuickStartGuide.html).
What’s New With DB2 for i?
Enhancements to DB2 technology in recent years include extensions to the database’s handling of XML and the addition of JSON. A significant SQL extension was the introduction of the OFFSET and LIMIT clauses. This improves the ease with which SQL can page through result sets—a cumbersome task in SQL. Below is an example of an SQL statement utilizing the new support.
SELECT CUSTNO, NAME, CITY, STATE FROM CUSTOMERS ORDER BY CUSTOMER LIMIT :Max OFFSET :Start
The variable :Start says which row in the result set is the first to be returned, and :Max is the maximum number of rows (conceptually, the subfile page size, even though this may well be a Web application!) that are to be returned. This makes handling the results a page at a time a trivial task. Alternate syntax options can be used, with more details listed on the IBM developerWorks* website (ibm.co/1J5f21f).
Prior to the introduction of OFFSET, to achieve the same result required SQL similar to that shown here:
SELECT * FROM (SELECT CUSTOMER, NAME, CITY, STATE, ROW_NUMBER()
OVER (ORDER BY CUSTOMER) AS ROWNUMBER
FROM PCUSTOMERS
ORDER BY CUSTOMER)
AS TEMPCUST
WHERE ROWNUMBER > :Start AND
ROWNUMBER <= (:Start+:Max)
It’s not hard to see why we were so happy with this change.
The DB2 Approach to APIs
Some of the more interesting changes in DB2 technology include the introduction of SQL views and user-defined table functions (UDTFs) that supply system information. Previously, to obtain such information required the use of APIs or commands that produced outfiles. If you think about it, the surprising thing in many ways is that this didn’t happen sooner. Our single-level store system is basically one giant database, and retrieving information about spool files and other system components via SQL is a natural.
We wrote recently about some of these features—in particular some of those introduced alongside TR3 and also TR11 (ibmsystemsmag.com/ibmi/administrator/db2/DB2-for-i-Services/). These introduced the notion of using SQL views and UDTFs to retrieve spool file information.
In addition to spool file processing, similar capabilities have been provided for user profiles, job logs, jobs, PTFs, system status, messages and much more.
The developerWorks website contains a full list of the current capabilities in this area (ibm.co/1OkpBfV).
DB2 Meets XML (and JSON)
DB2 technology’s XML capabilities have grown steadily and now include the capability to store XML in DB2 tables. In and of itself, that may not sound like much until you take into account that such XML can be parsed and queried by SQL statements.
In addition to storing XML, users can parse an XML document and store the contents as DB2 tables. And, of course, the converse can also be done (i.e., generating XML documents from DB2 tables), all using SQL.
RPG’s XML-INTO, with the recently added flexibility, meets our XML parsing needs and seems more straightforward. But we’re sure people out there understand the SQL syntax and work wonders with it, so we have at least two different options.
DB2 for i has also added support for storing JSON, an alternative, lighter weight information exchange format currently used for many things XML has been utilized for in the past. At present, there is only support for storing and retrieving JSON documents within DB2 tables—no support is available for parsing JSON into DB2 table data or generating JSON from DB2 technology. It is an area to keep watching, as more support is almost certain to be added in the future. Additional details on the current support are listed on developerWorks (ibm.com/developerworks/ibmi/library/i-json-store-technology/).
Other DB2 for i Enhancements
The last couple of DB2 for i releases contain many more enhancements. This article concentrates mostly on the features that overlap with RPG application requirements. More information about the performance, availability and security enhancements—particularly the new Row and Columns Access Control (RCAC)—is listed on the DB2 for i resource page (ibm.co/1SknsEY).
There is no doubt in our minds that our favorite platform continues to get better and better, and there is clearly much more to come from the DB2 and RPG teams. Watch this space.
IBM Champions Jon Paris and Susan Gantner co-own Partner400, a management consulting company. Together, they have more than 50 years of experience in IBM midrange systems and regularly blog on ibmsystemsmag.com.