Universal Data Mover Subroutines

Universal Data Mover Subroutines

The Universal Data Mover scripting language provides support for subroutines.

Subroutines are portions of the script code that can be called, by name, at any point. This provides a convenient way to reuse common script code.

Usage

There are two parts to a subroutine:

Definition

Names the subroutine and defines the script code that becomes associated with that subroutine name.

Invocation

Carries out the work of lines of script associated with a subroutine.

Defining a Subroutine

subroutine name
[script line 1]
...
[script line n]
endsub

Invoking a Subroutine

callsub name

Sequence of Defining / Invoking a Subroutine

A subroutine must be physically defined before the callsub to the routine is used.

For example, the following subroutine will function correctly:

subroutine test
   echo "This is subroutine test"
   echo "$(_halton)"
endsub

echo "This is main()"
callsub test


However, this subroutine will fail:

echo "This is main()"
callsub test

subroutine test
   echo "This is subroutine test"
   echo "$(_halton)"
endsub


Nesting / Recursion of Subroutines

UDM allows subroutine nesting (one subroutine calls another subroutine) and recursion (a subroutine calls itself).

For example, the following illustrates subroutine nesting:

subroutine a
    echo "Beginning subroutine A"
    callsub b
    echo "Ending subroutine A"
endsub

subroutine b
    echo "Beginning subroutine B"
    echo "Ending subroutine B"
endsub

callsub a

Example

subroutine loop_increment
        echo "inside loop_increment: $(LOOP)"
        set LOOP=<$(LOOP) + 1>
endsub

echo "Starting Loop:"
set LOOP=0
if <$(LOOP) LT 1>
        callsub loop_increment
end
if <$(LOOP) LT 2>
        callsub loop_increment
end
if <$(LOOP) EQ 2>
        callsub loop_increment
end
echo "Final Value of LOOP: $(LOOP)"

Output

Starting Loop:
inside loop_increment: 0
inside loop_increment: 1
inside loop_increment: 2
Final Value of LOOP: 3