CASxx (Conditionally Invoke Subroutine)

Free-Form Syntax (not allowed - use the IF and EXSR operation codes)
Code Factor 1 Factor 2 Result Field Indicators
CASxx Comparand Comparand Subroutine name HI LO EQ

The CASxx operation allows you to conditionally select a subroutine for processing. The selection is based on the relationship between factor 1 and factor 2, as specified by xx. If the relationship denoted by xx exists between factor 1 and factor 2, the subroutine specified in the result field is processed.

You can specify conditioning indicators. Factor 1 and factor 2 can contain a literal, a named constant, a figurative constant, a field name, a table name, an array element, a data structure name, or blanks (blanks are valid only if xx is blank and no resulting indicators are specified in positions 71 through 76). If factor 1 and factor 2 are not blanks, both must be of the same data type. In a CAS   operation, factor 1 and factor 2 are required only if resulting indicators are specified in positions 71 through 76.

The result field must contain the name of a valid RPG IV subroutine, including *PSSR, the program exception/error subroutine, and *INZSR, the program initialization subroutine. If the relationship denoted by xx exists between factor 1 and factor 2, the subroutine specified in the result field is processed. If the relationship denoted by xx does not exist, the program continues with the next CASxx operation in the CAS group. A CAS group can contain only CASxx operations. An ENDCS operation must follow the last CASxx operation to denote the end of the CAS group. After the subroutine is processed, the program continues with the next operation to be processed following the ENDCS operation, unless the subroutine passes control to a different operation.

The CAS   operation with no resulting indicators specified in positions 71 through 76 is functionally identical to an EXSR operation, because it causes the unconditional running of the subroutine named in the result field of the CAS   operation. Any CASxx operations that follow an unconditional CAS   operation in the same CAS group are never tested. Therefore, the normal placement of the unconditional CAS   operation is after all other CASxx operations in the CAS group.

You cannot use conditioning indicators on the ENDCS operation for a CAS group.

See Compare Operations or Subroutine Operations for further rules for the CASxx operation.

Figure 284. CASxx Operation
*...1....+....2....+....3....+....4....+....5....+....6....+....7...+....
CL0N01Factor1+++++++Opcode(E)+Factor2+++++++Result++++++++Len++D+HiLoEq....
 *
 *  The CASGE operation compares FieldA with FieldB.  If FieldA is
 *  greater than or equal to FieldB, Subr01 is processed and the
 *  program continues with the operation after the ENDCS operation.
 *
C     FieldA        CASGE     FieldB        Subr01
 *
 *  If FieldA is not greater than or equal to FieldB, the program
 *  next compares FieldA with FieldC.  If FieldA is equal to FieldC,
 *  SUBR02 is processed and the program continues with the operation
 *  after the ENDCS operation.
 *
C     FieldA        CASEQ     FieldC        Subr02
 *
 *  If FieldA is not equal to FieldC, the CAS operation causes Subr03
 *  to be processed before the program continues with the operation
 *  after the ENDCS operation.
 *  The CAS statement is used to provide a subroutine if none of
 *  the previous CASxx operations have been met.
 *
C                   CAS                     Subr03
 *
 *  The ENDCS operation denotes the end of the CAS group.
 *
C                   ENDCS


[ Top of Page | Previous Page | Next Page | Contents | Index ]