RETURN

The RETURN instruction returns flow control to the function caller.

Syntax

RETURN [ value [,...]  ]
  1. value can be any valid expression, an object reference or dynamic array reference.

Usage

The RETURN instruction transfers the control back from a function with optional return values.

Record members can be returned with the .* or THRU notation. Each member is returned as an independent variable.

A function may have several RETURN points (not recommended in structured programming) but they must all return the same number of values.

The number of returned values must correspond to the number of variables listed in the RETURNING clause of the CALL statement invoking this function.

A function cannot return a static array, but can return the reference of a dynamic array.

Example

MAIN
  DEFINE fname, lname VARCHAR(30)
  CALL foo(NULL) RETURNING fname, lname 
  DISPLAY fname CLIPPED, " ", upshift(lname) CLIPPED
  CALL foo(1) RETURNING forname, surname 
  DISPLAY fname CLIPPED, " ", upshift(lname) CLIPPED
END MAIN

FUNCTION foo(code)
  DEFINE code INTEGER
  DEFINE person RECORD
                 fname VARCHAR(30),
                 lname VARCHAR(30)
               END RECORD
  IF code IS NULL THEN
     RETURN NULL, NULL
  ELSE
     LET person.fname = "John"
     LET person.lname = "Smith"
     RETURN person.*
  END IF
END FUNCTION