Receiving Information From A Function; Summary Of Subroutines And Functions; Exercise - Writing A Function - IBM TSO/E REXX User Manual

Table of Contents

Advertisement

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
v One or more variables whose values are substituted or when no values were
v Literal string
v Arithmetic, comparison, or logical expression whose value is substituted.

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 z/OS TSO/E REXX Reference.
ANSWER

Summary of Subroutines and Functions

SUBROUTINES
Invoked by using the CALL instruction followed by the
subroutine name and optionally up to 20 arguments.
RETURN 55
assigned, return their names
RETURN value1 value2 value3
RETURN 'Work complete.'
RETURN 5 * number
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)
number = WORD(numlist,n) /* Word #n goes to number
sum = sum + number
END
average = sum / WORDS(numlist)
RETURN average
/* Repeat for as many times as there */
/* are numbers
/* Sum increases by number
/* Compute the average
FUNCTIONS
Invoked by specifying the function's name immediately
followed by parentheses that optionally contain up to 20
arguments.
Chapter 6. Writing Subroutines and Functions
Writing a Function
*/
*/
*/
*/
*/
*/
*/
83

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents