NEW statement

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 = new-function [ NO-ERROR ]
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:

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 NEW function, which creates an instance of a specified class and returns an object reference to that instance. This is the syntax for the NEW function, where object-type-name must specify a class type consistent with the object type of object-reference: The value of new-function is restricted to alphanumeric characters plus the symbols #, $, %, and _.
NEW object-type-name ( [ parameter[ , parameter ]...] )

The parameter list specifies the class constructor that is used to instantiate the class. For more information on the syntax and operation of the NEW function, see the NEW function (classes) reference entry.

NO-ERROR
The NO-ERROR option is used to prevent the statement from raising ERROR and displaying error messages.

For the NEW statement with NO-ERROR, if ERROR is 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:

DEFINE VARIABLE myCustObj AS CLASS acme.myObjs.CustObj NO-UNDO.

myCustObj = NEW acme.myObjs.CustObj ( ). 

Notes

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