CASxx (Conditionally Invoke Subroutine)
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.