EasyManuals Logo

IBM TSO/E REXX User Manual

IBM TSO/E REXX
242 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #101 background imageLoading...
Page #101 background image
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 z/OS TSO/E REXX Reference.
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 */
DOn=1TOWORDS(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

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM TSO/E REXX and is the answer not in the manual?

IBM TSO/E REXX Specifications

General IconGeneral
BrandIBM
ModelTSO/E REXX
CategoryComputer Hardware
LanguageEnglish

Related product manuals