Syntax error (14422) when accessing database in static metho

Posted by thomass@proventus.no on 23-Nov-2009 14:38

When trying to access the database from a static method in a class the compiler gives error 14422 (Static methods, property accessors, and constructors may only reference static members of the class. 'Customer' is an instance member).

METHOD PUBLIC STATIC INTEGER DoSomething():

 

  DEF VAR result AS INT NO-UNDO INIT 0.

  FOR EACH Customer NO-LOCK:

     result = result + 1.     

  END.

RETURN result.

END METHOD.

When accessing the database dynamicly (using buffers and queries) everything works fine, so it's perfectly possible for the language to access a db from a static method context.

The message indicates that the database-tables in OOABL is considered non-static members. I find this strange because the dataaccess in ABL is a very static construct, it's always available and no initialization is required (other that having a connection available in the session of course).

So the question is: Am I missing something here? Is this by-design or a bug?

All Replies

Posted by Admin on 23-Nov-2009 14:43

I believe that all the default buffers are instance level. Don't know if it's a bug or a desired feature. Dosn't disturb me too much.

DEFINE PRIVATE STATIC BUFFER Customer FOR Customer .

or

DEFINE PRIVATE STATIC BUFFER bCustomer FOR Customer .

fixes the issue. This defines a class level buffer.

Posted by Thomas Mercer-Hursh on 23-Nov-2009 17:45

And, I would say that best practice indicates that you should always define such a buffer in order to limit the scope.

This thread is closed