5 pts.
 Re-using Indicators in RPG400
If we have used all the indicators from 01 - 99 in a RPG Program, How can we re-use the indicators in the same program. Can anyone provide me a solution please

Software/Hardware used:
ASKED: January 22, 2010  2:15 PM
UPDATED: January 25, 2010  4:10 PM

Answer Wiki:
You can always reuse indicators, as often or as many times as you want. The problem is, if you're dealing with an old, ancient, archaeic program that originated from RPG II or RPG III which should be retired or rewritten, you'll need to carefully analyze how it uses whichever indicators you're thinking of reusing in order to avoid messing up its current logic. You may have to save the values of an indicator to a work variable and then re-use that indicator, and then copy the value from the saved variable back into it once your new logic is done with it. A better solution is to convert the program to RPG IV, if it hasn't already been done. Then, the only reason to even use the numbered 1-99 indicators is if it's an interactive program that uses a display file and needs those indicators to condition various behaviors on the screen. Any other numbered indicator can be replaced with a named indicator, where you can define and use as many as you want. And depending on what those indicators are being used for, you may be able to completely eliminate them by relying on the built in functions (BIFs) for file and record status (functions like %EoF, %Found, %Equal, etc.). So instead of using a resulting indicator after a file operation, and then testing the value of that indicator to know whether or not a record was retrieved ,you would leave the resulting indicator off, and just use the approprate BIF to condition your logic. Instead of: <pre> KEYFIELD CHAIN MYFILE 98 IF *IN98 = *Off (proceed) ENDIF </pre> you would do this: <pre> KEYFIELD CHAIN MYFILE IF %Found(MYFILE) (proceed) ENDIF </pre> or this: <pre> /Free CHAIN (KEYFIELD) MYFILE; IF %Found(MYFILE); (proceed....) ENDIF; /End-Free </pre> CWC ***************************** Re-write your program without indicators and publicly flog the person who wrote the program to set an example. Steve
Last Wiki Answer Submitted:  January 25, 2010  4:48 am  by  Cwc   4,275 pts.
All Answer Wiki Contributors:  Cwc   4,275 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

It can’t be said much better than Cwc said it. First, stop using RPG/400 and convert to RPG IV. Second, start replacing numbered indicators with functions wherever possible. Where functions don’t make sense, use indicator variables. And if the indicators are controlling DSPF attributes, replace them with the DSPATR(&program-to-system-field) form.

Tom

 108,055 pts.

 

Short of their rewrite
Just prior to your new code move the indicators to a hold area
You could create an array with 99 1 character long fields named HIN
MOVEA *IN HIN
then use the indicators as you need to in the new code
at the end of the new code repopulate the indicators
MOVEA HIN *IN and they are all back where they were.
Phil

 44,180 pts.

 

What Phil wrote is a good solution, but if you need to re-use only a few and say within a subroutine, the you can create a work-field called in a similar “name” as the indicator, like #IN99 and move the *IN99 into it. After you made your new stuff move back the #IN99 into *IN99.
MOVE *IN99 #IN99
do something
MOVE #IN99 *in99

But, again the best way is to convert to RPGIV.

Good luck,
YuVa47

 1,285 pts.