RANGES, LISTS, AND SELECTOMIT


RANGES, LISTS, AND SELECT/OMIT

Testing for a range, a list, or specific select/omit values is a tradition in programming. The modern RPG language provides limited support for these operations with the IF operation.

For a simple range, traditional RPG programs have used various techniques (as shown in Figure 7.17 and 7.18). Whenever possible, the modern RPG language programmer avoids using indicators and uses the technique illustrated in Figure 7.17. The COMP operation, as shown in Figure 7.18, is less desirable.

start figure

 .....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq      C                   Do        35            X                 3 0      C                   Move      Name(x)       CHAR              1      C                   If        Char >= 'a' and Char <= 'z'      C                   BitOn     '1'           NAME(x)      C                   Endif      C                   EndDo 

end figure

Figure 7.17: Using IF to test a range of values.

start figure

 .....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq...      C     LOOP          tag      C                   Add       1             X                 3 0      C                   Move      NAME(X)       char              1      C     char          comp      'a'                                21  21      C   21char          comp      'z'                                  2323      C   21      CAN 23              BitOn         '1'       Name(x)      C     X             comp      35                                   56      C  n56              GOTO      LOOP 

end figure

Figure 7.18: Traditional RPG code used to test a range of values.

The code in Figure 7.17 states that:

    If CHAR is Greater than or Equal to 'a'       AND it is Less than or Equal to 'z', then... 

Figure 7.17 is the preferred technique because it says exactly what it does. The technique shown in Figure 7.18 performs exactly the same function, but it is convoluted and inflexible. At best, maintenance is complicated. Testing a list of values requires the use of the IF operation along with the OR operator. For example, to test for the occurrence of the letters R, P, G, or the number 4 in the NAME array, the IF operation is used in conjunction with the OR operation. See Figure 7.19 and 7.20.

start figure

 .....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq...      C                   DO        35            X                 3 0      C                   Move      NAME(x)       char              1      C                   If        Char='R' OR char='P' OR char='G' or Char='4'      C                   EXSR      RPG4      C                   EndIf      C                   EndDo 

end figure

Figure 7.19: IF with OR to test for a list of values.

start figure

 .....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq      C     LOOP          tag      C                   ADD       1             X                 3 0      C                   Move      NAME(x)       char              1      C     CHAR          COMP      'R'                                    75      C  N75CHAR          COMP      'P'                                    75      C  N75CHAR          COMP      'G'                                    75      C  N75CHAR          COMP      '4'                                    75      C   75              EXSR      RPG4      C     X             COMP      35                                   75      C   75              GOTO      LOOP 

end figure

Figure 7.20: Traditional RPG COMP operation to test a list of values.

Figure 7.19 shows the preferred technique. Its straightforward approach is concise and can be modified easily. On the other hand, the technique shown in Figure 7.20 is complex and cumbersome. Care should be taken when modifications are made.




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