Consultor Eletrônico



Kbase P67710: The WHEN option of the ASSIGN statement appears not evaluate correctly.
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   13/11/2006
Status: Unverified

SYMPTOM(s):

The WHEN option of the ASSIGN statement appears not evaluate correctly.

The iValue in the following code is evaluated to 0 and not to 100:

DEFINE VARIABLE lResult AS LOGICAL NO-UNDO.
DEFINE VARIABLE iValue AS INTEGER NO-UNDO.
ASSIGN
lResult = TRUE
iValue = 100 WHEN lResult.
MESSAGE iValue
VIEW-AS ALERT-BOX INFO BUTTONS OK.

CAUSE:

This is expected behavior because Progress evaluates the WHEN expressions at the beginning of the assignment, before any assignments take place. This behavior has been explicitly documented in OpenEdge 10.0B and higher.

FIX:

There are two ways to get the desired behavior:
1) Separate the ASSIGN phrases into their own ASSIGN statements:

DEFINE VARIABLE lResult AS LOGICAL NO-UNDO.
DEFINE VARIABLE iValue AS INTEGER NO-UNDO.
ASSIGN
lResult = TRUE.
ASSIGN
iValue = 100 WHEN lResult.
MESSAGE iValue
VIEW-AS ALERT-BOX INFO BUTTONS OK.
2) Use the IF/THEN statement instead of the WHEN option to evaluate the expression:

DEFINE VARIABLE lResult AS LOGICAL NO-UNDO.
DEFINE VARIABLE iValue AS INTEGER NO-UNDO.
ASSIGN
lResult = TRUE.
ASSIGN
iValue = IF lResult THEN 100 ELSE iValue.
MESSAGE iValue
VIEW-AS ALERT-BOX INFO BUTTONS OK.