::ROUTINE

The ::ROUTINE directive creates named routines within a program.

                           +-PRIVATE-+
>>-::ROUTINE--routinename--+---------+--;-----------------------><
                           +-PUBLIC--+

The routinename is a literal string or a symbol that is taken as a constant. Only one ::ROUTINE directive can appear for any routinename in a program.

A ::ROUTINE directive starts a routine, which is ended by another directive or the end of the program.

If you specify the PUBLIC option, the routine is visible beyond its containing Rexx program to any other program that references this program with a ::REQUIRES directive. If you do not specify the PUBLIC option, the routine is visible only within its containing Rexx program.

Routines you define with the ::ROUTINE directive behave like external routines. In the search order for routines, they follow internal routines and built-in functions but precede all other external routines.

Example:


::class c
::method a
call r "A"  /* displays "In method A" */

::method b
call r "B"  /* displays "In method B" */

::routine r
use arg name
say "In method" name

Notes:

  1. It is an error to specify ::ROUTINE with the same routine name more than once in the same program. It is not an error to have a local ::ROUTINE with the same name as another ::ROUTINE in another program that the ::REQUIRES directive accesses. The language processor uses the local ::ROUTINE definition in this case.

  2. Calling an external Rexx program as a function is similar to calling an internal routine. For an external routine, however, the caller's variables are hidden and the internal values (NUMERIC settings, for example) start with their defaults.

Note: If you specify the same ::ROUTINE routinename more than once in different programs, the last one is used. Using more than one ::ROUTINE routinename in the same program produces an error.