IBM SC34-5764-01 Server User Manual


 
Each SELECT must end with an END. Indenting each WHEN makes a program easier to read.
Exercises - Using SELECT WHEN...OTHERWISE...END
"Thirty days hath September, April, June, and November; all the rest have thirty-one, save February alone
..."
Write a program that uses the input of a number from 1 to 12, representing the month, and produces the
number of days in that month. Assume the user specifies the month number as an argument when calling
the program. (Include in the program an ARG instruction to assign the month number into the variable
month). Then have the program produce the number of days. For month 2, this can be 28 or 29.
ANSWER
/******************************** REXX *******************************/
/* This program receives input with a person's age and sex. In */
/* reply, it produces a person's status as follows: */
/* BABIES - under 5 */
/* GIRLS - female 5 to 12 */
/* BOYS - male 5 to 12 */
/* TEENAGERS - 13 through 19 */
/* WOMEN - female 20 and up */
/* MEN - male 20 and up */
/*********************************************************************/
PARSE ARG age sex .
SELECT
WHEN age < 5 THEN /* person younger than 5 */
status = 'BABY'
WHEN age < 13 THEN /* person between 5 and 12 */
DO
IF sex = 'M' THEN /* boy between 5 and 12 */
status = 'BOY'
ELSE /* girl between 5 and 12 */
status = 'GIRL'
END
WHEN age < 20 THEN /* person between 13 and 19 */
status = 'TEENAGER'
OTHERWISE
IF sex = 'M' THEN /* man 20 or older */
status = 'MAN'
ELSE /* woman 20 or older */
status = 'WOMAN'
END
SAY 'This person should be counted as a' status'.'
Figure 18. Example Using SELECT WHEN...OTHERWISE...END
Control Flow within a Program
38
CICS TS for VSE/ESA: REXX Guide