The Good (Indicators Part 2)

Back around 1980 or so, I read an article or two by Dick Eagleson in an IBM minicomputer trade publication about the (then) relatively new concepts of structured programming. I believe it was before the System/38 came out, so he explained how to perform sequence, selection (IF-THEN-ELSE-END; CASE;and so on), and iteration (DO-ENDDO-DO WHILE, etc.) in the context of pre-System/36 RPGII, where all you had to work with was COMP and GOTO and TAG. (In this article, he also declared his Law of Software Strangeness: Any code you write and don’t look at for six months may as well have been written by someone else when you look at it again.)

In this article, he also declared that just because IBM provided 99 numbered indicators to use, it didn’t mean that you had to see how many you could stuff into any given program! It was not a revelation, because it was so obvious; but the implications were grand. You did not have to use all the indicators that come to mind in your programs. The need for indicator complexity was nonexistent; do it the structured way.

To give an example, suppose you wanted to convey this RPGIV concept:


     C                   IF        (X>5 and Y<3 and Z=9)
     C                   DOU       X<5 or Y>3
     C**  Some code that changes the values of X or Y
     C                   ENDDO
     C                   ENDIF

This is how you could render it in RPGII:


     C           X         COMP 5                    25
     C   25      Y         COMP 3                      25
     C   25      Z         COMP 9                        25
     C  N25                GOTO EIF001
     C           LUP001    TAG
     C* SOME CODE CHANGING X OR Y
     C           X         COMP 5                      25
     C  N25      Y         COMP 3                    25
     C  N25                GOTO LUP001
     C           EIF001    TAG            

This new way of thinking changed the way I programmed from then on. While I did not swear off indicators as I learned RPG400 and RPGIV, I made sure that my code would be as succinct as possible, using as few indicators as possible. At the same time, I was not afraid of using them or overly concerned about getting rid of them.

Much of the dislike for indicators seems to be based on the fact that they are not self-defining like a field name is (CUSTBAL, for instance meaning Customer Balance). If you set on indicator 89 for an unsuccessful CHAIN(random file access) operation, and you continue on into your calculations without referring to indicator 89 in your calculations, you tend to lose track of the significance of indicator 89. That is true. But immediately after the CHAIN, you DO know the significance of indicator 89. Do whatever you need to do with it-change the course of your processing, put out an error message, or whatever- then FORGET about indicator 89. If you really need to save the result of the CHAIN, set a field to Y or N based on the results (or in RPGIV, save it in a named indicator variable). Go ahead and use 89 somewhere else, if the spirit moves you.

Other examples could be given. Record identification indicators can be defined by the program to identify when a particular file is read. Especially if you are dealing with Input Primary and Input Secondary files (where entire files are read from beginning to end with no need for a READ calculation), these indicators are self-documenting (unless, if you’re foolish, you change their settings in calculations).

Now, do I use an indicator when doing a CHAIN operation? No, I don’t; I use the %FOUND BIF (built-in function) to test whether a chain was successful. But I have no problem with others using CHAIN with an indicator. At a previous employer, they were considering coding standards, and they wanted to mandate the use of BIFs like %FOUND. Another programmer pointed out that when you use %FOUND, when running a program in debug mode, the BIF does not give immediate feedback on the success of the CHAIN; using CHAIN with an indicator gives you immediate feedback. I had never thought of that; and I can see that as a reason why a programmer should indeed be permitted to use an indicator in this situation, if he deems it appropriate.

So I have no problem with indicators as such; only when they are used badly, as I showed in my previous post. And I think that RPG gurus and others who have a hissy fit when indicators are used (in a proper way) should just calm down, relax, get another cup of coffee and find something worth worrying about.

Leave a Reply