*---------*---------------*-----------------*----------------*---------------* | CODE | FACTOR 1 | FACTOR 2 | RESULT | INDICATORS | | | | | FIELD | | *---------*---------------*-----------------*----------------*---------------* | CASXX | Comparand | Comparand | Subroutine | HI LO EQ | | | | | name | | *---------*---------------*-----------------*----------------*---------------*
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 54 through 59). If factor 1 and factor 2 are not blanks, both must be character data, or both must be numeric. In a CASbb operation, factor 1 and factor 2 are required only if resulting indicators are specified in positions 54 through 59.
The result field must contain the name of a valid RPG/400 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 CASbb operation with no resulting indicators specified in positions 54 through 59 is functionally identical to an EXSR operation, because it causes the unconditional running of the subroutine named in the result field of the CASbb operation. Any CASxx operations that follow an unconditional CASbb operation in the same CAS group are never tested. Therefore, the normal placement of the unconditional CASbb 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 for further rules for the CASxx operation. Figure "CASxx Operation" shows the coding for a group of CASxx operations.
*...1....+....2....+....3....+....4....+....5....+....6....+....7... CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++ C* C* The CASGE operation compares FIELDA with FIELDB. If FIELDA is C* greater than or equal to FIELDB, SUBR01 is processed and the C* program continues with the operation after the ENDCS operation. C* C FIELDA CASGEFIELDB SUBR01 C* C* If FIELDA is not greater than or equal to FIELDB, the program C* next compares FIELDA with FIELDC. If FIELDA is equal to FIELDC, C* SUBR02 is processed and the program continues with the operation C* after the ENDCS operation. C* C FIELDA CASEQFIELDC SUBR02 C* C* If FIELDA is not equal to FIELDC, the CAS operation causes SUBR03 C* to be processed before the program continues with the operation C* after the ENDCS operation. C* The CAS statement is used to provide a subroutine if none of C* the previous CASxx operations have been met. C* C CAS SUBR03 C* C* The ENDCS operation denotes the end of the CAS group. C* C ENDCS
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.