CALL

The CALL instruction causes the interpreter to search your procedure until a label is found that marks the start of the subroutine. Remember, a label (word) is a symbol followed by a colon (:). Processing continues from there until the interpreter finds a RETURN or an EXIT instruction.

A subroutine can be called from more than one place in a procedure. When the subroutine is finished, the interpreter always returns to the instruction following the CALL instruction from which it came.

Often each CALL instruction supplies data (called arguments or expressions) that the subroutine is to use. In the subroutine, you can find out what data has been supplied by using the ARG instruction.

The CALL instruction is written in the following form:

CALL name  Argument1, Argument2 ...

For the name, the interpreter looks for the corresponding label (name) in your procedure. If no label is found, the interpreter looks for a built-in function or a .CMD file with that name.

The arguments are expressions. You can have up to 20 arguments in a CALL instruction. An example of a procedure that calls a subroutine follows. Note that the EXIT instruction causes a return to the operating system. The EXIT instruction stops the main procedure from continuing into the subroutine.

In the following example, REXX.CMD, the procedure calls a subroutine from a main procedure.

/* Calling a subroutine from a procedure */
DO 3
  CALL triple 'R'
  CALL triple 'E'
  CALL triple 'X'
  CALL triple 'X'
  SAY
END
SAY 'R...!'
SAY 'E...!'
SAY 'X...!'
SAY 'X...!'
SAY ' '
SAY 'REXX!'
EXIT          /* This ends the main procedure. */
/*                                                     */
/* Subroutine starts here to repeat REXX three times.  */
/* The first argument is displayed on screen three     */
/* times, with punctuation.                            */
/*                                                     */
TRIPLE:
SAY ARG(1)"    "ARG(1)"   "ARG(1)"!"
RETURN           /* This ends the subroutine.          */

When REXX.CMD is run on your system, the following is displayed:

[C:\]REXX
R   R   R!
E   E   E!
X   X   X!
X   X   X!

R   R   R!
E   E   E!
X   X   X!
X   X   X!

R   R   R!
E   E   E!
X   X   X!
X   X   X!

R...!
E...!
X...!
X...!

REXX!

[C:\]


[Back: SUBSTR( )]
[Next: REXX.CMD File Commands]