Progress
Language Reference


RETURN Statement

Interfaces
OS
SpeedScript
All
All
Yes

Leaves the local or remote procedure block and returns to the calling procedure. If there is no calling procedure, RETURN returns to the Procedure Editor or other ADE tool that invoked the procedure.

For more information on remote procedures, see the Building Distributed Applications Using the Progress AppServer manual.

SYNTAX

RETURN
  [ ERROR | NO-APPLY ]
  [ return-value ] 

ERROR

Causes an ERROR condition in the calling block. This causes the ERROR condition to be raised for the RUN statement in the calling procedure. You can use the ERROR option only in a procedure or a database trigger block. Any values that are set for OUTPUT or INPUT-OUTPUT parameters before the RETURN ERROR executes are not returned to the calling procedure.

NO-APPLY

Suppresses the default behavior for the current user-interface event. For example, the default behavior for a character code key press in a fill-in field is to echo the character in the field. If you execute RETURN NO-APPLY in a trigger, this behavior is not performed. You can use the NO-APPLY option in a user-interface trigger block or within an internal procedure.

return-value

The value that RETURN returns to the calling procedure. RETURN appearing in a user-defined function returns an expression whose type matches the return type of the function. RETURN not appearing in a user-defined function returns a CHARACTER expression. To access return-value from the calling procedure, use the RETURN-VALUE function.

EXAMPLES

The r-fact.p procedure is called recursively because (n factorial) is n * ((n - 1) factorial). The r-fact.p procedure first checks that the input value is valid. If the value is invalid, it returns a message to the caller. Note that r-return.p checks the RETURN-VALUE immediately after running r-fact.p. If a message is returned, r-return.p displays that message.

The procedure r-return.p accepts an integer as input and then runs r-fact.p to calculate the factorial of that integer. The factorial of a number is the result of multiplying together all of the integers less than or equal to that number (for example: 3 factorial is 3 * 2 * 1 = 6). The r-fact.p procedure is called recursively because n factorial is n * (n -1) factorial.

r-return.p
DEFINE NEW SHARED VARIABLE nfact AS INTEGER LABEL "N Factorial"
                       FORMAT ">,>>>,>>>,>>9".
DEFINE VARIABLE n AS INTEGER FORMAT "->9" LABEL "N".

REPEAT:
    SET n SPACE(5).
    nfact = n.
    RUN r-fact.p.
    IF RETURN-VALUE <> ""
    THEN DO:
       BELL.
       MESSAGE RETURN-VALUE.
    END.
    ELSE DISPLAY nfact.
END. 

r-fact.p
DEFINE SHARED VARIABLE nfact AS INTEGER.
DEFINE VARIABLE i AS INTEGER.

IF nfact < 0
THEN RETURN "The value is negative.".

IF nfact > 12
THEN RETURN "The calculated value won’t fit in an integer.".

i = nfact.
nfact = nfact - 1.

IF nfact <= 1 THEN DO:
    nfact = i.
    RETURN.
END.

RUN r-fact.p.

nfact = nfact * i.

RETURN. 

Note that this is not the most efficient way to calculate factorials, but in other applications, such as bill of material explosions, recursive procedures are very effective.

NOTES

SEE ALSO

CREATE SERVER Statement, FUNCTION Statement, ON ENDKEY Phrase, ON ERROR Phrase, ON QUIT Phrase, ON STOP Phrase, RETURN-VALUE Function


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095