Coding without indicators

If you have spent any time changing the way your RPG programs process indicators, for example changing If *in99 = *on or If *in99 = '1' to simply If *in99 (all three statements evaluate the same to either 'true' or 'false') you may want to consider completely removing the indicators as a better use of your time. The reason is that indicators are inherently inefficient and are fast becoming obsolete in the grand scheme of things (read: IBM and the future).

One might ask if a program is working fine why is there any need to change. Well, if free format RPG is in your future this might force a reevaluation as indicators are rarely needed and most often they are not even allowed. Also, the indicators cut down on the readability of your code for any other person who might have to read it. The real question is why use the indicator in the first place? Was the indicator the result of an I/O operation? With RPG IV there is no need for I/O indicators since we can use built-in functions %found and %eof, or with an extender, %status)

Instead of using *in99 after a read or chain, use %found, or 'not %found'.

// use of bifs to eliminate indicators
Chain mykey myfile
if %found

Or if you need to check for locking
// use of bif and extender to check record lock status
Chain(E) mykey myfile
if %status = 01218

Another example is a READ loop that exits when end-of-file is reached;
READ myfile DOW not %eof(myfile)
READ myfile

Display files have always been a place where programmers tend to use a lot of indicators. This can be somewhat circumvented by naming indicators in the D specs by using field names defined as type 'N' fields which correspond with function keys pressed. Here are a couple of methods to accomplish naming display file indicators; Mapping Indicators to Names

If your legacy code contains indicators U1-U8 you might need to leave them or treat them as a special case. Similarly *INLR will still be valid in your code.

By spending a little time removing indicators, and learning to code without them, RPG IV code can become more efficient and less cluttered. You will be making yourself ready for using more free format RPG. Future generations will exalt your efforts and put your name up in lights. Well, that last statement might have been a slight exaggeration.