METHOD statement
- Last Updated: February 11, 2026
- 14 minute read
- OpenEdge
- Version 13.0
- Documentation
Defines a method of a class, declares a method prototype in an ABL interface, or overrides a method inherited from an ABL or .NET super class. A method is a class member that, when invoked by name, can execute code and return a value similar to a user-defined function. The description that follows begins with the general syntax for defining a method.
.cls) file.Syntax
|
Use the following syntax to declare an interface method prototype:
|
Use the following syntax to declare an abstract method prototype:
|
- [ PRIVATE | PACKAGE-PRIVATE | PROTECTED | PACKAGE-PROTECTED | PUBLIC ]
-
Specifies the access mode for this method.
A
PRIVATEmethod can be called by the defining class. An instance can call the private method of another instance if they are both from the same class. APACKAGE-PRIVATEmethod can be called from within the class and any class within its package. APROTECTEDmethod can be called by the defining class and any of its derived classes. APACKAGE-PROTECTEDmethod can be called from within the class, any class within its package, and from within any subclass that inherits the class. APUBLICmethod can be called from any code (in a class or a procedure) that has access to a class instance.The default access mode is
PUBLIC.When declaring an interface method prototype, the access mode for this method must be
PUBLIC(the default).When defining an abstract method, the access mode for the method cannot be
PRIVATE.If this method is defined with theOVERRIDEoption, the access mode must not be more restrictive than the access mode defined for the overridden ABL or .NET super class method. The following table shows what access mode you can use on anOVERRIDEmethod in an ABL class when the method being overridden is .NET:.NET ABL protectedPROTECTED, PACKAGE-PROTECTED, PUBLICprotected internalPROTECTED, PACKAGE-PROTECTED, PUBLICpublicPUBLIC - [ STATIC ]
- Defines a method that is a static member of the class type for which
it is defined and that is scoped to the ABL session where it is referenced. You can call
an accessible static method in any piece of code.
Without this option, ABL defines an instance method that is scoped to a single instance of the class where it is defined. You can call any public instance method (abstract or non-abstract) in any procedure, or in any instance or static method defined inside or outside of the class where the instance property is defined. Any static method can call the public instance method only using an object reference to a class instance that defines the instance method as a member. If the referencing static method is defined in the same class as the public instance method, the class must instantiate itself in order to have access to an instance reference.
For more information on the mechanism for calling methods of different access modes and scopes, see the reference entry for Class-based property access.
The
STATICoption is not valid when you:- Define or implement an abstract method
- Declare an interface method prototype
- Implement an interface method
Note: The access mode modifier and theSTATIC/ABSTRACTmodifier can appear in either order, e.g.,METHOD STATIC PUBLIC VOID myMethod():...is valid syntax. - [ ABSTRACT ]
- Defines the method as an abstract member of the class type for which
it is defined. The defining class type must also be abstract. If you define an abstract
method, it has the following requirements:
- You must specify the
OVERRIDEoption if an inherited method (abstract or otherwise) has the same name and signature. - You can specify any access mode other than
PRIVATE. - The abstract method must be overridden and implemented in a derived class.
Any class definition for an instance method that includes the
OVERRIDEoption and does not include theABSTRACToption defines a method implementation. If it also includes theABSTRACToption, the inherited method remains or is redefined as abstract.This option is not valid either when you define a static method or you declare an interface method prototype.
- You must specify the
- [ OVERRIDE ]
- Specifies one of the following:
- This instance method overrides the behavior of another instance method inherited from an ABL or .NET class.
- This instance method implements, or overrides the behavior of, an abstract method inherited from an ABL or .NET abstract class.
- This instance method redefines as abstract an implemented method
inherited from an ABL or .NET class.Note: A .NET abstract class is defined in C# with the
abstractkeyword. - This static method redefines the behavior of another static method implemented in a super class.
When you specify
OVERRIDE, the method signature must match the overridden method with respect to the name, return type, and the number, types, and modes of its parameters. In addition, the access mode cannot be more restrictive than the access mode of the super class method it overrides. When overriding a .NET method, the return type and parameters must also map appropriately to the inherited .NET method return type and parameters. For more information, see the description of the return-type and parameter options.If you are overriding an inherited abstract method and you specify the
ABSTRACToption, your overriding method is also defined as abstract, and it must be implemented in a class derived from the defining class. Note that you do not have to override an inherited abstract method that you want to remain abstract as long as the inheriting class is also abstract. However, doing so allows you to specify a less restrictive access mode for the abstract method.If you do not specify the
ABSTRACToption when overriding an inherited abstract method, your method definition implements the abstract method.If you are overriding an inherited method that already has an implementation and you specify the
ABSTRACToption, your overriding method redefines the inherited method as abstract, and it must, again, be implemented in a class derived from the defining class. Note that to redefine an inherited method as abstract that already has an implementation, the defining class must also be abstract.Note that instance methods do not override static methods and static methods do not redefine instance methods. For more information about overriding and redefining methods, see Develop Object-oriented ABL Applications.
You can only override methods of a .NET super class that, in C# terms, are:
- Declared as
virtualorabstract - Declared as
public,protectedorprotected internal - Not declared as
staticorsealed(FINAL)
For an interface, the
OVERRIDEoption can only be specified for methods that are defined inProgress.Lang.Object, however this is not required. - [ FINAL ]
- Indicates this method cannot be overridden or redefined by a method
defined in an inheriting subclass.
This option is not valid either when you define an abstract method or when you declare an interface method prototype.
- VOID
- Indicates this method does not return a value.
- return-type
- Indicates the data type of the method return value. You can specify
return-type as one of the following data types.
For more information on each data type, see the Data types reference entry:
{ CHARACTER | COM-HANDLE | DATE | DATETIME | DATETIME-TZ | DECIMAL | HANDLE | INT64 | INTEGER | LOGICAL | LONGCHAR | MEMPTR | RAW | RECID | ROWID |AS-data-type |[ CLASS ]object-type-name }[ EXTENT [constant]]- AS-data-type
- If you are defining the return type for a method that overrides
a .NET super class method (abstract or otherwise) or implements a method defined
in a .NET interface, return-type must specify
the exact return type of the overridden or implemented .NET method. For a .NET
mapped data type that is a default match for an ABL primitive type, you must use
the default matching ABL data type, as shown in Table 4. (For example, INTEGER indicates a .NET System.Int32.) For a
.NET mapped data type that is not a default match for one
of the ABL primitive types, ABL provides a data type keyword (the AS-data-type) that you must use to explicitly
indicate the required .NET data type, as shown in Table 5. (For example, UNSIGNED-BYTE indicates a .NET System.Byte.)
Note: At run time, a method return type defined using an AS-data-type keyword behaves in ABL like the corresponding ABL primitive type shown in Table 5. (For example, an UNSIGNED-BYTE behaves like an INTEGER.)
Also note that when overriding or implementing a .NET array return value, you must specify the .NET array object type (for example,
"System.Int32[]"or"System.Byte[]"); you cannot use an ABL array equivalent (for example, INTEGER EXTENT or UNSIGNED-BYTE EXTENT). - object-type-name
- Specifies the type name of an ABL or .NET class or interface.
Specify an object type name using the syntax described in the Type-name syntax reference entry. With an
appropriate USING statement,
you can also specify a class or interface name alone, without the qualifying
package or namespace.
If you are defining the return type for a method that overrides a .NET super class method (abstract or otherwise), or that implements a method defined in a .NET interface, object-type-name must specify the exact return type of the overridden or implemented .NET method. However, for .NET inner (nested) type, note the difference in the ABL syntax, which replaces the corresponding period (.) in the .NET object type with a plus (+) (see the Type-name syntax reference entry).
Also note that when overriding or implementing a .NET array return value, you must specify the .NET array object type (for example,
"System.Drawing.Point[]"); you cannot use an ABL array equivalent (such as System.Drawing.Point EXTENT). - [ CLASS ]
- If the specified class or interface type name conflicts with an
abbreviation of a built-in primitive type name, such as INT for INTEGER, you must
specify the
CLASSkeyword.For a class or interface return value, ABL returns an object reference associated with the class or interface, not a class instance itself. For more information on object references, see the Class-based object reference reference entry.
- [ EXTENT [constant ]]
- Defines the return value as an array of data elements with a
primitive or object data type. This option can specify an array return value as
either determinate (has a defined number of elements) or indeterminate (has an
undefined number of elements). To define a determinate array return value, specify
the
EXTENToption with the constant argument. This optional argument is an integer value that represents the number of elements in the array. To define an indeterminate array return value, specify theEXTENToption without the constant argument. For more information about determinate and indeterminate arrays, see Work with one-dimensional arrays in Basic ABL.If you do not use the
EXTENToption (or you specify constant as0), the return value is not an array return value.
- method-name
- The method name. This name must be unique among all methods defined
in the class hierarchy of the defining class, unless the method:
- Includes the
OVERRIDEoption to override an inherited method. - Overloads a method in the defining class or in any super class within its inherited class hierarchy. In this case, the parameter list must differ from that of every other method with the same name in the defining class, and it must differ from that of every other method with the same name defined in every super class of the defining class.
Note: Members of a class are grouped into six namespaces, including buffers/temp-tables, methods, variables/properties/events, ProDataSets, queries, and data-sources. Methods defined as members of a class share the same namespace. There can be only one class member in this namespace with a given name. If the method is defined in a class that is derived from a .NET class, other restrictions on method-name apply. For more information, see the Notes in this reference entry. - Includes the
- ( [ parameter [ , parameter]...] )
- Defines zero or more parameters of the method.
If this method is one of several overloaded methods, the parameter list must be unique among all methods defined in the class hierarchy of the defining class. This uniqueness can be established using a different combination of number, data types, or modes for the parameters. Note that both instance and static methods overload one another within the class hierarchy.
If this method implements an interface method prototype or overrides an inherited method (using the
OVERRIDEoption), the parameter list must match the parameter list of the interface method or the method this is overriding.If the method implements a .NET interface method prototype or overrides an inherited .NET method (abstract or otherwise), you must explicitly map any .NET mapped types specified for parameters of the .NET method (see Table 5). Note that at run time, any explicitly mapped parameter behaves like the corresponding ABL primitive type.
For more information on the syntax of parameter, establishing uniqueness for method overloading, and on mapping .NET parameter types, see the Parameter definition syntax reference entry.
- method-body
- The body for a method implementation. For an interface method
prototype or an abstract method, you cannot specify method-body. For more information about declaring method prototypes in an
interface, see the INTERFACE statement
reference entry.
Define method-body using the following syntax:
method-logic . . . [catch-block[catch-block...]] [finally-block] END [ METHOD ] .- method-logic
- The logic of the method. This logic can contain the ABL
statements that are allowed within a procedure block, including class-related
statements.
If you define the method to return a value of the data type specified by return-type, you can execute the RETURN statement to set a value of that data type to return at run time. If return-type is defined as a .NET array of mapped types (for example,
"System.Byte[]"), you must return an object reference of the specified .NET array of mapped types in the RETURN statement. You cannot return an ABL array of a type that maps to the .NET array type (for example, INTEGER EXTENT) or the AVM raises a run-time error. If you do not execute anyRETURNstatement for return-type in the method-logic, the method returns the Unknown value (?) as its return value.If you are defining an instance method with the
OVERRIDEoption, you can also call the overridden implementation of this method in the class hierarchy using theSUPERsystem reference. You can also optionally call any instance method defined in the same class using theTHIS-OBJECTsystem reference.If you are defining a static method, you cannot access any instance members of a class (including the defining class) nor can you use the
SUPERandTHIS-OBJECTsystem references. From a static method, you can access only other static members of a class and the local variables or other local data elements of the method.Each logic statement must end with a period.
- catch-block
- Specifies a
CATCHstatement that defines error handling code for one or more error types. ADOblock does not have any default error handling. Therefore, aDOblock must have error handling options specified such that it becomes an undo-able block. Otherwise, ABL generates a compiler warning. For more information on catch-block, see the CATCH statement reference entry. - finally-block
- Specifies a
FINALLYstatement that defines the processing that must occur after all other processing in the block occurs. For more information on finally-block, see the FINALLY statement reference entry. - END [ METHOD ]
- Specifies the end of the method body definition. You must end
the method body definition with the
ENDstatement.
Examples
The following example shows the definition of an instance method in a class (which might implement a method prototype declared in an interface, as depicted in the second example):
|
The following example shows the definition of a method prototype declaration in an interface (which can be implemented by an instance method definition in a class, as depicted in the first example):
|
For more examples of method definitions, including static and abstract methods, see the descriptions of r-CustObj.cls, r-CustObjStatic.cls, and r-CustObjAbstract.cls in the CLASS statement reference entry.
Notes
- You can terminate a
METHODstatement with either a period (.) or a colon (:), but typically use a colon (:) for a method definition (in a class) and a period (.) for a method prototype (in an interface). - A complete method definition must begin with the
METHODstatement and end with theENDstatement. - A method of a class can invoke another method of a class (instance or static, as appropriate), as well as an internal or external procedure or a user-defined function. Similarly, a procedure or user-defined function can invoke a method of a class. Note that if method-name is an ABL reserved keyword, you might need to use the THIS-OBJECT system reference or Type-name syntax to call the method. For more information on referencing and invoking methods, see the reference entry for a Class-based method call.
- Local variables and other data elements defined within a method are scoped to the end of the method definition. The values of local variables and data elements do not persist across method invocations; they are re-initialized each time you invoke the method. However, if you define a local variable within a method using the same name as a data member or property within the class hierarchy, the local variable takes precedence over the data member or property for the duration of the method.
- When defining local variables and other data elements for any method,
even one that overrides or implements a .NET method, you cannot define these elements
using an
ASdata type (see Table 5). You must use an ABL data type like any other method definition. The ABL data that you assign to or from a given .NET method parameter must be assignment compatible with the .NET type, as in all other contexts. - You cannot specify an access mode (for example,
PUBLIC) for variable definitions in a method. - You cannot define
SHAREDobjects, work tables, temp-tables, or ProDataSet objects within the body of a method. - ABL implements primitive and array parameters of methods as
NO-UNDOvariables. - You can handle application errors in a method as in any ABL block. By
executing a
RETURN ERRORaction at the block level or aTHROWaction at the block level with the presence of a ROUTINE-LEVEL ON ERROR UNDO, THROW statement, the AVM returns the ERROR condition to the statement that invoked the method. If aRETURN ERRORalso includes the option to return a character string value, or you set theReturnValueproperty of aProgess.Lang.AppErrorobject that youTHROW, you can get this value using the RETURN-VALUE function following the statement that invoked the method or in aCATCHblock that catches theProgress.Lang.AppErrorobject. For more information, see Develop Object-oriented ABL Applications. - You cannot override an inherited .NET generic method. However, you can create a non-generic ABL method of the same name (without a type parameter list).
- You cannot override the following .NET methods:
DestroyHandle( )Dispose( )Finalize( )GetHashCode( )
In .NET, these methods are overridable. However, OpenEdge defines these methods as
FINALfor an ABL session. Instead of overriding .NET methods (such asDispose( )) that destroy or otherwise clean-up .NET resources, always use a destructor in the ABL class to manage class clean-up using these methods, even when inheriting from a .NET class. Similarly, if you want to return an ABL-processed value generated byGetHashCode( ), create a separate ABL method that callsGetHashCode( )to return the value. - When you define a method in an ABL class that inherits a .NET class,
you cannot define method-name
as any of the following reserved method names (case insensitive) or ABL raises a
compile-time error:
Get_property-name( )— Where property-name is the name of a property (including any default indexed property) defined by the .NET super classNote: For default indexed properties, property-name is usuallyItem.Set_property-name( )— Where property-name is the name of a property (including any default indexed property) defined by the .NET super classAdd_event-name( )— Where event-name is the name of an event defined by the .NET super classRemove_event-name( )— Where event-name is the name of an event defined by the .NET super class
- When you raise error from within an ABL method that overrides a .NET
method or implements a .NET method defined in a .NET interface, if the method is called
from .NET, and ABL error options raise the error out of the method block, ABL returns a
.NET
System.Exceptionto the caller. If the error is raised by executing aRETURN ERRORwith the optional error string, theMessageproperty of theSystem.Exceptiondescribes the operation where the error occurred, but the error string is available only to the ABL session, using theRETURN-VALUEfunction. If the error is raised by executing aRETURN ERRORwith an optional ABL error object or by executing anUNDO, THROW, theSystem.Exception:Messageproperty includes both a description of the operation where the error occurred and any messages from the ABL error object. If the error is fatal, the AVM responds as for any ABL class, generating a protrace file and exiting the session.
See also
Class-based method call, CLASS statement, FUNCTION statement, INTERFACE statement, Parameter definition syntax, PROCEDURE statement, RETURN statement, Type-name syntax, USING statement