You are currently on IBM Systems Media’s archival website. Click here to view our new website.


Four Ways To Keep Your RPG Skills Relevant

Advice to use just before New Year’s resolution time


Normally, we’d do a list like this for the January edition of EXTRA, since it’s in keeping with the notion of New Year’s resolutions. But we thought this time we’d get ahead of the game by a month. This way you have the opportunity to add a few books to your Christmas or holiday list. (You do put technical books on your gift lists, don’t you?) And you have plenty of time to add appropriate “must learn how to” items to your New Year’s resolutions.

As is often the case with these articles, the initial inspiration arose while following several recent discussions in Internet groups. These demonstrated once again that due to pressure of work, or for whatever other reason, a great many RPGers simply haven’t managed to keep up with all of the things their favorite language has to offer. These days, pressures to do more with less are increasing and it really behooves us to ensure we’re making the most of what we have. It’s also important to realize that it’s much easier to meet your users’ needs today than it is to fight a rearguard action tomorrow to prevent a takeover by an inferior alternative “solution.” With that in mind, we drew up this brief list of four topics we think should be on your “must do” list.

1) Keep Up-to-Date With What RPG has to Offer

Since a discussion of BIFs sparked this article, let’s start there. Most of us know how to use the I/O-related ones such as %EOF, %FOUND, and the basic string BIFs such as %SCAN and %LOOKUP, but there are many others. Here’s a short list of the ones of which we find many RPGers are either blissfully unaware or simply not taking advantage.

%CHAR. We find %CHAR particularly useful when we want to take a numeric value and perform basic editing on it so we can incorporate the value in a string. %CHAR will add a decimal point and negative sign if required, as well as strip off all the leading zeros so only significant characters are left. Additionally, it can also be used to obtain an edited version of a date field. We often use %CHAR in conjunction with the DSPLY op-code to display numeric fields when testing new code. For example:

DSPLY ( 'Field X is : ' + %char(X) + ' and Y is: ' + %Char(Y) );

%EDITC/W. If %CHAR doesn’t go far enough (for example, if you wish to retain leading zeros), then you need to dive into the world of %EDITC and %EDITW. %EDITC applies an edit code to a numeric value and returns the edited character string just as applying an edit code to a field in an 0-Spec would do. %EDITW performs a similar task by applying an edit word.

%REPLACE. This BIF does exactly what you’d think it should: It replaces one string with another and is not used as often as it should be. If you’re not yet familiar with it though, you needn’t spend too much time on it because in V7 IBM introduced the new BIF, %SCANRPL, which will loop through a string locating all instances of one string and replacing them with another. If you’d like to know more about it, read the article we wrote on V7’s new features.

Before we conclude this quick run-through of some of the lesser-known BIFs, we should probably mention the substring function (%SUBST) that got us started on this topic in the first place. Most people are familiar with the use of %SUBST as a means of extracting a portion of a string, but many seem to have missed out on the fact that %SUBST can also be used on the left-hand side of an Eval operation. That is to say, it can be used to constrain the portion of the target field that will be changed. For example, the code below will overwrite the first three characters of field Z with the characters “ABC”. In other words, it operates in this instance as a MOVEL would.

%Subst( Z: 1: 3) = 'ABC';

Another feature of RPG that’s significantly underutilized is variable length fields. You should always use these to avoid repetitive trim operations when building a string. They also provide a lot of flexibility when passing character strings as parameters. We covered the basics of variable length fields back in 2002 (doesn’t time fly when you’re having fun!).


Jon Paris is a technical editor with IBM Systems Magazine and co-owner of Partner400.

Susan Gantner is a technical editor with IBM Systems Magazine and co-owner of Partner400.



2019 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

New and Improved XML-INTO

Namespace support makes the opcode a viable option

Authenticating on the Web

The finer points of OpenRPGUI, Part 1

The Microphone is Open

Add your voice: Should IBM i include open-source RPG tools?

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
IBMi News Sign Up Today! Past News Letters