IBM SC34-5764-01 User Manual

Page 87

Advertising
background image

In a function call, you can pass up to 20 arguments separated by commas.

function(argument1,argument2,argument3,...)

Using the ARG Instruction: A subroutine or function can receive the arguments with the ARG
instruction. In the ARG instruction, commas also separate arguments.

ARG

arg1, arg2, arg3, ...

The names of the arguments that are passed do not have to be the same as those on the ARG instruction
because information is passed by position rather than by argument name. The first argument sent is the
first argument received and so forth. You can also set up a template in the CALL instruction or function
call. The language processor then uses this template in the corresponding ARG instruction. For information
about parsing with templates, see section “Parsing Data” on page 73.

In the following example, the main routine sends information to a subroutine that computes the perimeter
of a rectangle. The subroutine returns a value in the variable perim by specifying the value in the RETURN
instruction. The main program receives the value in the special variable RESULT.

The next example is the same except it uses ARG in a function instead of a subroutine.

This program receives as arguments the length and width of a
rectangle and passes that information to an internal subroutine.
The subroutine then calculates the perimeter of the rectangle.

PARSE ARG long wide
CALL perimeter long, wide
SAY ‘The perimeter is’ RESULT ‘inches.’

EXIT

perimeter:
ARG length, width

perim = 2 * length + 2 * width

RETURN perim

/***********************************REXX***********************************/
/* */
/* */
/* */
/*****************************************************************************/

Figure 39. Example of Passing Arguments on the CALL Instruction

Writing Subroutines and Functions

Chapter 6. Writing Subroutines and Functions

65

Advertising