PreviousNextIndex

RETURN statement

Leaves the local or remote procedure or user-defined function block, trigger block, database trigger block, the method block of a class, the class constructor block, or the property accessor block, and returns to the calling procedure, user-defined function, method, constructor, or property accessor. If there is no caller, RETURN returns to the Procedure Editor or other ADE or OpenEdge Architect tool that invoked the procedure, user-defined function, trigger block, database trigger, class-based method, constructor, or property accessor.

For more information on remote procedures, see OpenEdge Application Server: Developing AppServer Applications.

Syntax

RETURN  
    [ return-value | 
       ERROR [ return-value | error-object-expression ] | 
       NO-APPLY ]  

return-value
ERROR
error-object-expression
NO-APPLY

If you do not specify any options for the RETURN statement in a procedure or trigger block, return-value is returned as the empty string (""). In a VOID method, you cannot specify any options except for the ERROR options, and RETURN without ERROR options returns without setting a return-value or error object.

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 ReturnValue property 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
/* ***************************  Definitions  ************************** */ 
DEFINE VARIABLE ix    AS INTEGER NO-UNDO. 
DEFINE VARIABLE n     AS INTEGER NO-UNDO LABEL "N" FORMAT "->9". 
DEFINE VARIABLE nfact AS INTEGER NO-UNDO LABEL "N Factorial"  
  FORMAT ">,>>>,>>>,>>9". 
/* ***************************  Main Block  *************************** */ 
REPEAT: 
  SET n SPACE(5). 
  ASSIGN nfact = n. 
  RUN r-fact.p (INPUT-OUTPUT nfact). 
  DISPLAY nfact. 
  CATCH mae AS Progress.Lang.AppError: 
    REPEAT ix = 1 TO mae:NumMessages: 
      MESSAGE "Error Number: " mae:GetMessageNum(ix) SKIP 
        "Message: " mae:GetMessage(ix) SKIP 
        "NumMessage: " ix VIEW-AS alert-box. 
    END.  
    MESSAGE "Here is the ReturnValue " mae:ReturnValue VIEW-AS ALERT-BOX.  
  END CATCH. 
END. /* REPEAT */ 

r-fact.p
/* ***************************  Definitions  ************************** */ 
DEFINE INPUT-OUTPUT PARAMETER nfact AS INTEGER NO-UNDO. 
DEFINE VARIABLE ix  AS INTEGER NO-UNDO. 
DEFINE VARIABLE mye AS Progress.Lang.AppError NO-UNDO. 
/* ***************************  Main Block  *************************** */ 
IF nfact < 0 THEN DO: 
  mye = NEW Progress.Lang.AppError("The value is negative", 200).  
  mye:ReturnValue = "User inputs out of range". 
  RETURN ERROR mye. 
END. 
IF nfact > 12 THEN DO: 
  mye = NEW Progress.Lang.AppError 
    ("Factorial value won't fit in an integer.", 201). 
  mye:ReturnValue = "Calculated value out of range". 
  RETURN ERROR mye. 
END. 
ASSIGN 
  ix    = nfact 
  nfact = nfact - 1. 
IF nfact <= 1 THEN DO: 
  ASSIGN nfact = ix. 
  RETURN. 
END. 
RUN r-fact.p (INPUT-OUTPUT nfact). 
ASSIGN 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

CONSTRUCTOR statement, CREATE SERVER statement, DEFINE PROPERTY statement, FUNCTION statement, METHOD statement, ON ENDKEY phrase, ON ERROR phrase, ON QUIT phrase, ON STOP phrase, RETURN-VALUE function, UNDO statement


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex