Kbase P178043: 4GL/ABL: FOR EACH fails to iterate if its WHERE clause invokes a class method
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  01/12/2010 |
|
Status: Unverified
SYMPTOM(s):
4GL/ABL: FOR EACH fails to iterate if its WHERE clause invokes a class method
FOR EACH silently fails without errors if the WHERE clause contains a class method call
The following code erroneously return the unknown value for the smapleCount variable:
define variable sampleCount as integer no-undo init 0.
for each ttSample
where ttSample.Value1 = testClass:GetIntAttributeValueByName('UserID')
no-lock:
sampleCount = sampleCount + 1.
end.
MESSAGE sampleCount
VIEW-AS ALERT-BOX INFO BUTTONS OK.
FACT(s) (Environment):
All Supported Operating Systems
OpenEdge 10.2B
CAUSE:
Bug# OE00202448
CAUSE:
UDF?s and class methods are executed once and the returned value is used for all iterations. As a best practice, UDF?s and class methods should be moved outside the FOR EACH block, or inside the FOR EACH block, depending on the objective, and they should never be in the WHERE clause. The only way to execute code during a WHERE clause should be to make a FIND trigger for the table of the FOR EACH.
FIX:
None at this time. A workaround is to store the value returned by the class method call in a temporary variable and use that variable in the WHERE clause instead of the method invocation itself. For example
define variable sampleCount as integer no-undo init 0.
define variable myValue as integer no-undo init ?.
myValue = testClass:GetIntAttributeValueByName('UserID').
for each ttSample
where ttSample.Value1 = myValue
no-lock:
sampleCount = sampleCount + 1.
end.
MESSAGE sampleCount
VIEW-AS ALERT-BOX INFO BUTTONS OK.