Consultor Eletrônico



Kbase P3867: FIND, FOR EACH or OPEN QUERY statement calling a user-defined function or method generates error 725
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   6/10/2010
Status: Verified

SYMPTOM(s):

FIND, FOR EACH or OPEN QUERY statement calling a user-defined function or method generates error 7254

FIND statement fails with a function that also has a FIND

Illegal FIND, FOR EACH or OPEN QUERY in User-defined function <function name>. (7254)

User-defined function or method also executes a FIND, FOR EACH or OPEN QUERY statement

/* Sample code to reproduce */

FUNCTION foo RETURNS INTEGER:
FIND FIRST customer NO-LOCK.
IF AVAILABLE customer THEN
RETURN customer.custnum.
END FUNCTION.
FIND FIRST customer WHERE CustNum = foo().

FACT(s) (Environment):

Progress 9.x
OpenEdge 10.x
All Supported Operating Systems

CAUSE:

It is illegal to invoke a user defined function (UDF) in a FIND, CAN-FIND, FOR EACH or OPEN QUERY statement if the invoked function itself contains one or more a FIND, CAN-FIND, FOR EACH or OPEN QUERY statements.

FIX:

Invoke the user-defined function prior to the FIND, CAN-FIND, FOR EACH or OPEN QUERY statement, store its return value in a variable and use that variable in the FIND, CAN-FIND, FOR EACH or OPEN QUERY statement instead of the UDF itself. For example,


FUNCTION foo RETURNS INTEGER:
FIND FIRST customer NO-LOCK.
IF AVAILABLE customer THEN
RETURN customer.custnum.
END FUNCTION.

DEFINE VARIABLE i AS INTEGER NO-UNDO.
i = foo().

FIND FIRST customer WHERE CustNum = i.