The compare operation evaluates the relationship between two items. The branch operation performs a transfer to another part of the program. The COMP and GOTO operations in conjunction with conditioning indicators have a significant number of alternatives in the modern RPG language. Table 7.1 lists these alternatives with a brief description.
Op Code | Description |
---|---|
ANDxx | Extend IFxx, DOWxx, and DOUxx conditioning. |
CABxx | Compare two values then branch to a label. |
CASxx | Compare two values then call a subroutine. |
COMP | Compare two values and set resulting indicators on/off. |
DO | Begin DO loop with an optional counter. |
DOUxx | Begin DO UNTIL loop. |
DOWxx | Begin DO WHILE loop. |
ELSE | Else clause, used in conjunction with the IFxx operation. |
ELSEIF | Combines the functionality of the ELSE and IF opcodes |
ENDxx | Ends a DO, DO WHILE, DO UNTIL, CASE, SELECT, and IF/THEN/ELSE group. |
GOTO | Performs an unconditional branch to a label. |
IFxx | Compares values and performs a block of code. |
ITER | Branch to the top of the DO loop. |
LEAVE | Exit a DO loop. |
ORxx | Extend IFxx, DOWxx, and DOUxx conditioning. |
OTHER | Otherwise clause of the SELECT/WHEN group. |
WHENxx | Within a SELECT group, compares two values and performs a block of code. |
Figures 7.12, 7.13, and 7.14 are examples of the various compare and branch operations.
.....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq C FLDA CABEQ 'A' LABEL 21
.....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq C FieldA COMP 'A' 21 C 21 GOTO label
.....CSRn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq C IF Field = 'A' C SETON 21 C GOTO Label C EndIf
All three of these examples perform the same task. Figure 7.12 is the preferred technique for several reasons:
It is a single RPG operation code.
It generates the least number of instructions.
The CABxx operation (illustrated in Figure 7.12) replaces the technique featured in Figure 7.13.
When the technique featured in Figure 7.12 is used, resulting indicators are not normally used unless the program is communicating with an externally described file. For example, the indicator may control the attributes of a field in a workstation device file.