Consultor Eletrônico



Kbase P87475: Internal Procedure return-value function returns the previous value.
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   7/8/2004
Status: Unverified

SYMPTOM(s):

Internal Procedure return value returns the previous value.

The following procedure displays different values for the first and second calls to the internal procedure. But the third call returns the same value as the previous second call.

run pAbc in this-procedure (1).
message return-value view-as alert-box.

run pAbc in this-procedure (2).
message return-value view-as alert-box.

run pAbc in this-procedure (3).
message return-value view-as alert-box.

procedure pAbc:
def input parameter p-par as int no-undo.

if p-par = 1 then
return "number one".
else if p-par = 2 then
return "number two".
end procedure.

CAUSE:

The 'RETURN-VALUE' function simply returns the value returned by the last RETURN statement. In this piece of code, for the last call there hasn't been a RETURN statement since the second call, and this is why it returns a duplicate value.

FIX:

To resolve this problem do not use the RETURN-VALUE function at all, if the expectation is to get three different values for three different calls to the procedure. For example:


DEFINE VARIABLE cRESULT AS CHARACTER NO-UNDO.

run pAbc in this-procedure (1, OUTPUT cResult).
message RETURN-VALUE " : " cResult view-as alert-box.

run pAbc in this-procedure (2, OUTPUT cResult).
message return-value " : " cResult view-as alert-box.

run pAbc in this-procedure (3, OUTPUT cResult).
message return-value " : " cResult view-as alert-box.

procedure pAbc:
DEFINE INPUT PARAMETER p-par AS INT NO-UNDO.
DEFINE OUTPUT PARAMETER o-par AS CHAR NO-UNDO.

IF if p-par = 1 then
o-par = "number one".
else if p-par = 2 then
o-par = "number two".
end procedure.