Consultor Eletrônico



Kbase P131908: Error 14422 occurs when trying to access a database in a static method
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   7/1/2008
Status: Unverified

SYMPTOM(s):

Attempting to access a database in a static method

METHOD PUBLIC STATIC CHARACTER getName (INPUT iCustNum AS INTEGER):

DEFINE VARIABLE cName AS CHARACTER NO-UNDO.
FOR FIRST customer WHERE custnum = iCustNum NO-LOCK:
cName = customer.name.
END.

RETURN cName.

END METHOD.

Error 14422 occurs when executing code

Static methods, property accessors, and constructors may only reference static members of the class. '<var>' is an instance member. (14422)

FACT(s) (Environment):

OpenEdge 10.1C
All Supported Operating Systems

CAUSE:

This is expected behaviour. The FOR EACH is being done directly on a database table 'customer'. This is an implicit buffer that is created for the table 'customer'. This implicit buffer is an instance buffer by design. This is not legal in the same way that it is not legal to do:

DEFINE STATIC QUERY qr FOR customer.

Because 'customer' is not static.

FIX:

Explicitly define a buffer for the database table within the static method and refer to the buffer name. For example:

METHOD PUBLIC STATIC CHARACTER getName (INPUT iCustNum AS INTEGER):

DEFINE VARIABLE cName AS CHARACTER NO-UNDO.
DEFINE BUFFER bCust FOR customer.

FOR FIRST bCust WHERE bCust.custnum = iCustNum NO-LOCK:
cName = bCust.name.
END.

RETURN cName.

END METHOD.