NEW statement
- Last Updated: April 13, 2026
- 3 minute read
- OpenEdge
- Version 13.0
- Documentation
Creates an instance of a class (object) using the NEW function and assigns its object reference to an appropriately defined ABL
data element. Once assigned, you can use the object reference to access this class instance
and its PUBLIC data members, properties, and methods. For more information
on object references, see the reference entry for a Class-based object reference:
Syntax
|
- object-reference
- The name of an ABL data element to which you want to assign
the object reference of a new instance of the class specified by new-function.
This data element must be defined as a compatible class or interface
type and can be one of the following:
- A temp-table field defined as a Progress.Lang.Object class type using the DEFINE TEMP-TABLE statement
- A variable scoped to the current procedure, user-defined function, or method of a class or an accessible class-based variable data member defined as a class or interface type using the VAR statement or DEFINE VARIABLE statement
- A parameter defined as a class or interface type for the current procedure, user-defined function, or method of a class using an appropriate DEFINE PARAMETER statement or Parameter definition syntax
- An accessible and writable class-based property defined as a class or interface type using the DEFINE PROPERTY statement
To be compatible, the object type of object-reference must be:
- The same class type as the class instantiated by new-function
- A super class of the class instantiated by new-function
- An interface that is implemented by the class instantiated by new-function
- new-function
- An invocation of the
NEWfunction, which creates an instance of a specified class and returns an object reference to that instance. This is the syntax for theNEWfunction, where object-type-name must specify a class type consistent with the object type of object-reference:NEW object-type-name ( [ parameter[ , parameter ]...] )object-type-name is restricted to alphanumeric characters plus the symbols
#,$,%,-, and_.The parameter list specifies the class constructor that is used to instantiate the class. For more information on the syntax and operation of the
NEWfunction, see the NEW function (classes) reference entry. - NO-ERROR
- The NO-ERROR option is used to prevent the statement from raising
ERRORand displaying error messages.For the
NEWstatement withNO-ERROR, ifERRORis raised, then the object-reference remains unchanged.
Example
The following code fragment shows the definition of a variable that is assigned to the object reference for a new class instance:
|
Notes
- After the assignment, object-reference contains a copy of the object reference value returned by new-function, which points to the same object instance, not a copy of the object created by new-function.
- Although you can assign an object reference to a temp-table field defined as a Progress.Lang.Object class type, you cannot assign an object reference to a field in a database table. For more information, see Develop Object-oriented ABL Applications.
- This statement can raise errors during the execution of constructors for
the class being instantiated by new-function, or for
any class in its inherited class hierarchy. For example:
- A constructor in the class hierarchy executes the RETURN statement with
the
ERRORoption or the UNDO statement with theTHROWorRETURN ERRORoptions. - The class definition file for the class, a super class, or an interface could not be found.
- The run-time parameters of the constructor for the class, or a constructor for a class in the inherited class hierarchy, are not compatible.
When the AVM encounters one of these errors, and the constructor cannot create the class instance or its inherited class hierarchy, the AVM automatically invokes the destructor for any class that has already been constructed while building the class hierarchy for the object.
For more information on errors raised by instantiating classes, see Develop Object-oriented ABL Applications.
- A constructor in the class hierarchy executes the RETURN statement with
the
- The ABL Virtual Machine (AVM) automatically deletes (garbage collects)
any class instance that you create with the
NEWstatement some time after no reference to that object exists in the ABL session. However, you can force any class instance to be deleted immediately by using theDELETE OBJECTstatement. For more information on garbage collection for class instances, see the DELETE OBJECT statement reference entry.
See also
Assignment (=) statement, CAST function, Class-based object reference, CLASS statement, DYNAMIC-NEW statement, NEW function (classes), New( ) method, NO-ERROR option, Parameter passing syntax , VAR statement