Converting Legacy Code to Named Indicators

Q. While maintaining a large RPG IV program, I added an indicator data structure, using the INDDS keyword for the workstation file. I also added the INDARA keyword to the DDS, as required, and recompiled the file. But now the program doesn’t work. What did I do wrong? (The program is over 3,000 lines, and I do not want to change everything to use the new indicator data structure.)

A. When you add the INDDS keyword to a file specification, you “break the connection” between the DDS file’s numbered indicators and the RPG program’s number indicators. To test or set the indicators in the file, you must use the names of the indicators defined in your indicator data structure. When you test or set the numbered indicators, you’re not processing the same ones that the file uses.

Named indicators, indicator data structures, and built-in functions largely eliminate the need to use the familiar 99 numbered indicators in a new RPG IV program. But you may find it impractical and error-prone to upgrade legacy RPG code to replace numbered indicators with newer constructs. Fortunately, it’s not an either/or issue; you can assign both numbered and named indicators for the same condition, allowing the program to use either a numbered indicator or its corresponding named indicator interchangeably. All it takes is a data structure and a pointer:

D PtrIndicators   S               *   Inz(%Addr(*In)) 
D Indicators      DS                  Based(PtrIndicators) 
D   Exit                     3   3N 
D   Cancel                  12  12N 
D   Overflow                90  90N 
D   Sfldspctl               91  91N 
D   Sfldsp                  92  92N 
D   Sflend                  93  93N 
D   Sflclr                  94  94N 

Because the Indicators data structure points to the same address as the internal array *In, it shares the same memory as the numbered indicators. In this example, the program can refer to indicator 03 either by its number or by its name: Exit (in byte 3 of the Indicators data structure). The same is true of the other indicators in the data structure.