INDICATOR-CONTROLLED LOGIC


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.

start figure

 .....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 

end figure

Figure 7.1: Indicator-controlled branching.

start figure

 .....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 

end figure

Figure 7.2: Traditional RPG II-style indicator usage.

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.

start figure

 .....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 

end figure

Figure 7.3: Multi-indicator controlled branching.

start figure

 .....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 

end figure

Figure 7.4: Traditional multi-indicator control logic

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.




The Modern RPG IV Language
The Modern RPG IV Language
ISBN: 1583470646
EAN: 2147483647
Year: 2003
Pages: 156
Authors: Robert Cozzi

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net