TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

Rexx User Functions


After completing this chapter, you will be able to define and apply user defined function.


Function:

A function can be termed as a common routine which when invoked performs a pre-defined set of instructions and returns a value to the place from where it is invoked.

Normally a function call is performed by issuing the function name followed by parentheses within which the arguments passed to the function can be specified.

For example,

SUM(A,B)

Where SUM is the function and A & B are the arguments passed to the function.

Note:

There should be no space between the function name and the left parenthesis.

Following are the general characteristics of a function:

  1. A function may or may not receive input arguments.

  2. Any function must return a value.

  3. After executing the function, the function call is replaced by the value returned by the function.

For example,

SAY 7 + SUM(7,9)

Let us say, the function SUM(7,9) returns a value of 16. After executing the function, the above statement will be treated as

SAY 7 + 16

And 23 will be displayed.

A function call can contain up to 20 arguments separated by commas. Each argument can be one or more of the following:

Type of ArgumentSample
Blank Function( )
Constant Function(55)
Symbol Function(symbol_name)
Literal String Function(“Literal String”)
Another Function Function(Function(Arguments))
Combination of argument types Function('Literal String', 55)

A function call generally appears in an expression. Therefore a function call, like an expression, does not usually appear in an instruction by itself.


User Defined Functions:

The arguments passed to the subroutine can be received by ARG or PARSE ARG command. A maximum of 20 arguments can be received. After performing the user-designated task, the function returns a value to the calling module through RETURN command. As soon as RETURN command is encountered, the control will transfer back to the place where function call is made.

Set of instructions which might have to be performed often in a REXX module can be grouped together to form a function, which can be executed whenever it is needed.

For example, it may be needed to find maximum of three numbers multiple times in a REXX module. The logic to find the maximum of three numbers can be formulated as a common routine MAX which can be invoked as a function as follows:

HIGH(number1,number2,number3)

To find the maximum of 45, -2, number, 199, and assign the maximum value into a variable by name 'MAXVAL', the following instruction could be used:

MAXVAL = HIGH(45,-2,199)

Example:

/* REXX */
PARSE ARG NUMBER1, NUMBER2, NUMBER3
IF NUMBER1 > NUMBER2 THEN
    IF NUMBER1 > NUMBER3 THEN
        GREATEST = NUMBER1
    ELSE
        GREATEST = NUMBER3
ELSE
    IF NUMBER2 > NUMBER3 THEN
        GREATEST = NUMBER2
    ELSE
        GREATEST = NUMBER3
RETURN GREATEST

Summary:

  • A function can be termed as a common routine which when invoked performs a pre-defined set of instructions and returns a value to the place from where it is invoked.

  • Functions are similar to subroutines except for the way in which they are called and the way the values are returned.

  • Functions are classified as user-defined functions and built-in functions.


If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal