April 15

4 comments

Set off all RPG Indicators in a program

By NickLitten

April 15, 2018

RPG, Indicators

RPG INDICATORS are switches

Just like car indicators (or ‘blinkers’ as my American cousins call them) they can be switched *ON or *OFF in a program to indicate the state of a certain piece of logic. In the IBM RPG language, it used to logically flick the switch of a numeric indicator 01-99 to “indicate” that something was happening.

Rpg indicatorsFor example, we might switch on indicator 44 to say “invalid customer code” and then in every other place int he code we would say “if *IN44 is *ON then show this message, or print this warning or something”. Thats the end of this stating-the-obvious broadcast.

Using numeric indicators has been frowned upon for years, RPG has evolved and although it still fully supports using the old numeric style indicators, the introduction of alphanumeric ‘indicators’ in programming code makes much more sense. After all, what makes more sense checking a value of *IN66 or checking a value of a field called ItemCodeValid?

We can turn off everything in one simple Clear (or Reset if you set specific indicators *on/*off in *INZSR):

Clear *IN;

Now saying that, older programs some times use numeric indicators extensively and this is just a neat way of turning off blocks of indicators. SO, lets says we wanted to turn off all indicators higher than 20:

// *IN is a standard RPGLE array for *IN(01) thru *in(99) - and it says turn off all from 21 to 99
%SubArr(*IN : 21 : 99) = *Off;

In older column based RPG (or RPG400) you could use the MOVEA (move array command) turn them all off

C MOVEA *ALL:‘0’ *in01

Or specify a smaller block of indicators:

C MOVEA ‘0000’ *in80

​would move *zeros to *in80, *in81, *in82, *in83

Lots of other techniques to set off blocks of indicators but (if I am forced to use numeric indicators) I like the %subarr solution.

But… Wait… Indicators SUCK!

Using numeric indicators in any program is a really simple way to mess up your code.

Numeric indicators are not intuitive as to their functions, not clear and simple to understand, programmers are constantly referring to comments to figure out what indicators do. Ask yourself the question “Have I ever debugged a program and found the wrong indicators number is being used to turn *ON or *OFF?’ The answer for 100% of programmers is a resounding YES 🙁

The modern clean answer is to scrap those indicators and switch them to named variables.

Let’s look at named variables as an alternative to indicators here

  • Minor note — this might not clear all (nor even most) indicators. Ever since the indicator data type was introduced, we’ve been able to create any number of indicators outside of the *IN data space. A new DS might be used to hold a block of program-specific indicators while the *IN indicators are reserved for “standard usage” in all programs.

  • Thanks for the tip. Was thinking that I didn’t want to type *IN70 =*OFF for each different indicator and knew there must be something better out there. I couldn’t bring myself to use MOVEA. 🙁

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips

    >