Thursday, July 9, 2009

(Tips) Renaming Program Indicators AS/400 RPG

Naming your numeric indicators used in screen displays or printer files is an effective way to make your programs more readable and understandable, but did you know there are two ways it can be done? The first method is associating a data structure using the INDDS keyword, and the second method is by address association using the BASED keyword.

The first method uses the INDDS keyword which references a data structure. Within the data structure you give each indicator you use a unique name. So instead of saying IF *IN99 = *ON, you can say IF ERROR = *ON. This provides someone who has never been in the program before a better understanding of what the test is, instead of having to hunt down every occurrence of the indicator and figure it out from there.












The keyword INDDS references a data structure named Indicators. The data structure is a length of 99, but you don't need to specify every indicator, only the ones you're using. Additionally, the keyword INDARA needs to be present in the display or printer file you're referencing. The data structure can be referenced by more than one display and/or printer file within the program. You can also create separate ones for each. The second method uses the BASED keyword. It is similar to the first method except it does not require changes to the file specifications or either the display or printer files; all the changes are in the data structure, like so:







Here, the built-in function %ADDR references the Indicator array, and BASED references the data structure you provide. A difference between the two methods is that the first method can refer to a different data structure for each display and/or printer file you use, whereas the second one would apply to all. Here's an added tip, regardless of which method you use. You are not restricted to one name for each indicator. It is possible to supply multiple names for each. For example if indicator 50 is used to condition a field on two different screens, each with a different meaning, you can specify something like this within the data structure:



This way you're not stuck using a name in another part of the program that isn't the intended meaning. A word of caution however, as when you condition one of the named indicators above, it affects both when they're sharing the same indicator within a data structure. As long as this is kept in mind when designing the program, you'll be OK.

No comments:

Post a Comment