Receiving Information from a Function
Although a function can receive up to 20 arguments in a function call, it can specify
only one expression on the RETURN instruction. That expression can be a:
v
Number
RETURN 55
v
One or more variables whose values are substituted or when no values were
assigned, return their names
RETURN value1 value2 value3
v
Literal string
RETURN 'Work complete.'
v
Arithmetic, comparison, or logical expression whose value is substituted.
RETURN 5 * number
Exercise - Writing a Function
Write a function named "AVG" that receives a list of numbers separated by blanks,
and computes their average as a decimal number. The function is called as follows:
AVG(number1 number2 number3 ...)
Use the WORDS and WORD built-in functions. For more information about these
built-in functions, see
ANSWER
Possible Solution
/****************************** REXX *******************************/
/* This function receives a list of numbers, adds them, computes
*/
/* their average and returns the average to the calling exec.
*/
/*******************************************************************/
ARG numlist
/* receive the numbers in a single variable */
sum = 0
/* initialize sum to zero
*/
DO n = 1 TO WORDS(numlist)
/* Repeat for as many times as there */
/* are numbers
*/
number = WORD(numlist,n) /* Word #n goes to number
*/
sum = sum + number
/* Sum increases by number
*/
END
average = sum / WORDS(numlist)
/* Compute the average
*/
RETURN average
Summary of Subroutines and Functions
SUBROUTINES
FUNCTIONS
Invoked
by using the CALL instruction followed by the
subroutine name and optionally up to 20 arguments.
Invoked
by specifying the function’s name immediately
followed by parentheses that optionally contain up to 20
arguments.
Writing a Function
Chapter 6. Writing Subroutines and Functions
83
Содержание TSO/E REXX
Страница 1: ...z OS TSO E REXX User s Guide SA22 7791 00 ...
Страница 2: ......
Страница 3: ...z OS TSO E REXX User s Guide SA22 7791 00 ...
Страница 10: ...viii z OS V1R1 0 TSO E REXX User s Guide ...
Страница 12: ...x z OS V1R1 0 TSO E REXX User s Guide ...
Страница 14: ...xii z OS V1R1 0 TSO E REXX User s Guide ...
Страница 18: ...xvi z OS V1R1 0 TSO E REXX User s Guide ...
Страница 20: ...2 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 58: ...Tracing Expressions with the TRACE Instruction 40 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 78: ...60 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 86: ...Built In Functions 68 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 128: ...Issuing Other Types of Commands from an Exec 110 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 136: ...Debugging Execs 118 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 170: ...Protecting Elements in the Data Stack 152 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 201: ...Part 3 Appendixes Copyright IBM Corp 1988 2001 183 ...
Страница 202: ...184 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 222: ...Using Variables 204 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 226: ...208 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 238: ...220 z OS V1R1 0 TSO E REXX User s Guide ...
Страница 241: ......