RPGPGM.COM - From AS400 to IBM i › No More Number Indicators
I can remember in my first programming job being introduced to RPG III programs with a list of all the indicators used in the comments at the top of the program. While I admired the throughness of the documentation, I never did like that an indicator would only be used for one purpose. I prefered to use a few indicators for file Input/Output and check immediately afterwards if the indicator was *ON, for example:
01 * 99=End of file, 98=Error (record lock)
RPGLE/RPG IV introduced the "Operation Code Extender" which could replace the need for indicators for all of the operation codes. If I code the equivalent in RPG/free it could look like:
01 read FILE1 ;
But when RPGLE/RPG IV was first introduced you still had to use numbered indicators to communicate with display and printer files. Fortunately this is no longer the case as you can use the Indicator Data Structure, INDDS, to give the numbered indicators in these types of files meaningful names.
In this example I am going to use a display file as our example. This works in exactly the same way for printer files.
The first thing I need to do is to add the INDARA to the top of the display file's source, with the other keywords that apply to the entire file, see below:
A DSPSIZ(24 80 *DS3)
In the RPGLE/RPG IV source member I add the INDDS keyword into the File specification for the display file, see below, and the data structure with the same name as was given in the INDDS. In the data structure's subfields notice that the Data Type is 'N' for a indicator type field on lines 5-7 and 10-11.
01 F@SFL_DSPF CF E WORKSTN indds(IndDs)
Now I can just move *ON and *OFF to the named indicators like this:
// Intialize SFL
The error section of the IndDs data structure shows, on line 9, a trick I found. Rather than move *OFF all the indicators individually I can define a data structure subfield to be the same length as all of the error indicators. It must be defined as 'A', alphanumeric, as it is longer than one byte. I can then move all zeroes to it, which is the equivalent of moving *OFF to all the indicators in one step, see line 51 below:
01 Errors = *all'0' ;
In the subroutine Validation if any errors are found the appropriate indicator is turned *ON. When processing returns from the subroutine rather than test each indicator to see if it is *ON I can check if the Errors subfield is all zeroes, line 3, if it is not then an error has been found.
Now all the indicators are named there is not a need to list their function in the comments at the top of the program, or to puzzle about what an indicator is used for.
This article was written for OS i 7.1, and it should work with earlier releases too.
Read the original at RPGPGM.COM - From AS400 to IBM i.