The ELSE statement specifies that alternate processing is to take place when the conditions of the matching IF statement are not satisfied.
>>-ELSE--------------------------------------------------------><
The ELSE statement has no parameters. The ELSE statement must be column-aligned with the matching IF statement. Only one ELSE statement is allowed on the same line, even though each can align with a prior IF statement. You can nest IF statements within ELSE statements. The only limitation on the number of nested IF statements is the maximum number of columns available for indented statements due to the panel record length.
The ELSE statement is indentation sensitive. If the conditional expression is true, the ELSE statement that is column-aligned with the IF plus all statements to the right of that column are skipped. Processing continues with the next statement that begins in the same column as the ELSE or in a column to the left of the ELSE.
IF (&DOW = UP)
&ACTION = SELL
ELSE
IF (&DOW = DOWN)
&ACTION = BUY
ELSE
&ACTION = HOLD
&DOW = &BEAR
In this example, if the value of &DOW is UP, variable &ACTION is set to SELL and processing continues at the statement &DOW = &BEAR. The indented processing statements following the first ELSE statement execute if variable &DOW does not have a value of UP. The assignment statement, &ACTION = HOLD, executes only if the value of &DOW is not UP or DOWN.
Figure 1 shows a sample panel definition with an IF/ELSE statement pair. The current value of variable PHA is tested for the local area code, 919. If the value of PHA is 919, variable RATE is set to the value of variable &LOCAL. If the value of PHA is not 919, variable RATE is set to the value of variable &LONGD.
)BODY
%---------------------------- EMPLOYEE RECORDS ------------------------------
%COMMAND===>_ZCMD %
+
%EMPLOYEE SERIAL: &EMPSER
+
+ TYPE OF CHANGE%===>_TYPECHG + (NEW, UPDATE, OR DELETE)
+
+ EMPLOYEE NAME:
+ LAST %===>_LNAME +
+ FIRST %===>_FNAME +
+ INITIAL%===>_I+
+
+ HOME ADDRESS:
+ LINE 1 %===>_ADDR1 +
+ LINE 2 %===>_ADDR2 +
+ LINE 3 %===>_ADDR3 +
+ LINE 4 %===>_ADDR4 +
+
+ HOME PHONE:
+ AREA CODE %===>_PHA+
+ LOCAL NUMBER%===>_PHNUM +
+
)INIT
&TYPECHG = TRANS (&TYPECHG N,NEW U,UPDATE D,DELETE)
)PROC
&TYPECHG = TRUNC (&TYPECHG,1)
IF (&PHA = ‘919’)
&RATE = &LOCAL
ELSE
&RATE = &LONGD
)END