RPG/400 Help

SELEC (Begin a Select Group)

*---------*---------------*-----------------*----------------*---------------*
|   CODE  |    FACTOR 1   |     FACTOR 2    |     RESULT     |  INDICATORS   |
|         |               |                 |      FIELD     |               |
*---------*---------------*-----------------*----------------*---------------*
| SELEC   |               |                 |                |               |
*---------*---------------*-----------------*----------------*---------------*

The select group conditionally processes one of several alternative sequences of operations. It consists of:

After the SELEC operation, control passes to the statement following the first WHxx condition that is satisfied. All statements are then executed until the next WHxx operation. Control passes to the ENDSL statement (only one WHxx is executed). If no WHxx condition is satisfied and an OTHER operation is specified, control passes to the statement following the OTHER operation. If no WHxx condition is satisfied and no OTHER operation is specified, control transfers to the statement following the ENDSL operation of the select group.

Conditioning indicators can be used on the SELEC operation. If they are not satisfied, control passes immediately to the statement following the ENDSL operation of the select group.

The select group can be specified anywhere in calculations. It can be nested within IF, DO, or other select groups. The IF and DO groups can be nested within select groups.

If a SELEC operation is specified inside a select group, the WHxx and OTHER operations apply to the new select group until an ENDSL is specified.

Figure "SELEC Operation" shows an example of the SELEC operation.

SELEC Example

Figure 51. SELEC Operation

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C* In the following example, if X equals 1, do the operations in
C* sequence 1 (note that no END operation is needed before the
C* next WHxx); if X does NOT equal 1, and if Y=2 and X<10, do the
C* operations in sequence 2.  If neither condition is true, do
C* the operations in sequence 3.
C*
C                     SELEC
C           X         WHEQ 1
C                     Z-ADDA         B
C                     MOVE C         D
C                      :                               seq 1
C           Y         WHEQ 2
C           X         ANDLT10
C                      :                               seq 2
C                     OTHER
C                      :                               seq 3
C                     ENDSL
C*
C* The following example shows a select group with conditioning
C* indicators.  After the CHAIN operation, if indicator 10 is on,
C* then control passes to the ADD operation.  If indicator 10 is
C* off, then the select group is processed.
C*
C           KEY       CHAINFILE                     10
C  N10                SELEC
C           X         WHEQ 1
C                      :                              seq 1
C           Y         WHEQ 2
C                      :                              seq 2
C                     ENDSL
C                     ADD  1         N


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