RETURN

Top  Previous  Next

Returns a single value in a function subroutine and immediately returns execution to the caller.

 

Syntax

  RETURN <expression>;

 

The value returned is calculated by evaluating the expression in the statement. Functions library calls are supported as well.

 

A function subroutine can have multiple RETURN statements, but the function execution will terminate as soon as one of them is reached and executed.

 

Examples

A subroutine function is declared and called in the scripting code block. The value returned is calculated by multiplying the values for parameters i1 and i2.

 

execute udsblock(pin integer)

returns(pout integer, pout2 integer)

as

 

 declare function mult(i1 integer, i2 integer) returns integer

 as 

 begin

   return i1 * i2;

 end

begin

  pout = mult(pin, 5);

end

 

In this example, a function returns 'even' or 'uneven' based on the incoming number. The declare function has two RETURN statements, only one is executed depending on the calculation.

 

execute udsblock(your_number integer)

returns(evenness varchar(10))

as

 

 declare function even_uneven(i integer) returns varchar(10)

 as 

 begin

   if Math.Mod(i, 1) = 0

   then return 'even';

   else return 'uneven';

 end

begin

  evenness = even_uneven(your_number);

end