Define an object reference return type
- Last Updated: February 17, 2026
- 3 minute read
- OpenEdge
- Version 12.8
- Documentation
User-defined functions and class methods can define return types as object references (as class or interface types). When an object is passed locally, class instances are always returned by reference. Thus, only a reference to an object is returned, not the object itself. When an object is passed between an application server and an ABL client, the object is serialized by the sender, and the receiver uses this information to create a copy of the object. See Pass object reference parameters for more information.
This is the syntax to define an object reference return type for a method:
Syntax
|
This is the syntax to define an object reference return type for a user-defined function:
|
Descriptions of the object reference return type syntax elements (bolded) follow:
- CLASS
- The
CLASSkeyword is required if object-type-name conflicts with an abbreviation for a built in ABL data type, such asINTE(INTEGER). Otherwise, it can optionally be used to clarify the readability of the statement. - object-type-name
- The class or interface type name of the object reference to
be returned. This can be the fully qualified object type name or the
unqualified class or interface name, depending on the presence of an
appropriate
USINGstatement in the class or procedure file. For more information on object type names, see Define and reference object type names. For more information on theUSINGstatement, see Reference an object type name without its package.
For more information on the syntax of these statements, see the METHOD statement and FUNCTION statement statement reference entries in ABL Reference.
The
following code fragment, from the sample class acme.myObjs.CustObj, illustrates a method returning a class return
type, in this case, to initialize a message object (acme.myObjs.Common.MsgObj) for use by the current instance of CustObj:
|
The MessageHandler( )
method definition implements an abstract method defined in the immediate super
class. This method instantiates the MsgObj class
and returns the object to the caller.
ABL treats a return value from a class method the same as an assignment. That is, the compiler verifies that the object reference being returned by the method is consistent with the variable to which the object reference is being assigned. For more information on the compatibility rules for assigning object references, see Assign object references.
Thus, the rules for assigning an
object reference return value from within a method or user-defined function are the
same as for assigning an OUTPUT object reference
parameter from within a method. (For more information on passing object references
as OUTPUT parameters, see Pass object reference parameters.) The caller of the method must
define a data element to receive the returned object reference that is the same
class as the return object reference, a super class of the returned object
reference, or an interface of the returned object reference. As with parameters, if
the caller has as its target an object reference variable defined to reference a
super class or interface, the caller can only invoke those methods and access data
that are defined by the specified super class or interface. If the caller attempts
to call a method or access data that is not defined in the super class or attempts
to call a method not defined by the interface, the compiler generates an
error.