RPG II programmers have traditionally used indicators to control program logic:
Read a record, turn on an indicator.
Compare two values, turn on an indicator.
Search an array, turn on an indicator.
Terminate the program, turn on an indicator.
Indicators were the most consistent way to control program logic. An indicator takes up only two positions on a coding specification and, because the fixed-format column design of RPG severely limited the amount of space per line of code, indicators were a logical solution.
Today, however, RPG has been enhanced to support structure operations similar to those found in PL/I. New operations, such as IF-THEN-ELSE-END, DO, DOW, DOU, and SELECT-WHEN-OTHERWISE, provide RPG with full structured-programming support.
When an indicator is used, RPG generates a compare-and-branch instruction. If multiple indicators control an operation code, multiple compare-and-branch instructions are generated. This effect was minimized in RPG II by reversing the indicators and using them to control a GOTO operation that jumps around the program code. Figures 7.1 and 7.2 illustrate this "RPG II-style" of coding in the RPG IV language.
.....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq C FIELDA COMP '01' 22 C N22 GOTO NOTOT1 C ADD QTY TQTY C ADD QTY GQTY C MOVE '**' FLAG2 C MOVE '***' FLAG3 C NOTOT1 TAG
.....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq C FIELDA COMP '01' 22 C 22 ADD QTY TQTY C 22 ADD QTY GQTY C 22 MOVE '**' FLAG2 C 22 MOVE '***' FLAG3
Figure 7.1 shows the preferred method of controlling the program logic before modern operation codes became available. Figure 7.2 illustrates the original method of controlling program logic. Neither technique, however, represents a viable coding practice in today's world of advanced application programming.
When multiple indicators are needed to condition the same section of a program, the OR condition (columns 7 and 8) can be used. See Figures 7.3 and 7.4.
.....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq C FLDA COMP 'A' 21 C FLDB COMP 'B' 22 C N21 CORN22 GOTO NOTOT2 C ADD QTY TQTY C ADD QTY GQTY C MOVE '**' FLAG2 C MOVE '***' FLAG3 C NOTOT2 TAG
.....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq C FLDA COMP 'A' 21 C FLDB COMP 'B' 22 C 21 CAN 22 ADD QTY TQTY C 21 CAN 22 ADD QTY GQTY C 21 CAN 22 MOVE '**' FLAG2 C 21 CAN 22 MOVE '***' FLAG3
Figure 7.3 illustrates the preferred method of controlling program logic with multiple indicators before modern operation codes became available. The technique shown in Figure 7.4, unfortunately, is used more often. This code is actually converted from a previous version of RPG. Once again, neither of these techniques is useful for today's advanced application-programming needs.