Copyright 2022 - BV TallVision IT

The constructor is a rather special method, that any class can have. There are 2 types of constructor, the (regular) CONSTRUCTOR and the CLASS-CONSTRUCTOR. When an object for a class is instantiated, typically with CREATE OBJECT the constructor method on the class is called. The parameters on the constructor need to be passed in the CREATE OBJECT statement (unless they are optional of course).

Having an actual constructor is optional. Thus a class instance can also be created without. The constructor typically gathers information for the object attributes and check whether it is valid to create the object. Your report needs an object with it's own attributes and methods to process a purchase order. The constructor would typically need the purchase order number, as the purchase order is an already existing document. If the constructor checks the existance of the actual number, it could return an exception "Purchase order does not exist".

So what makes a constructor a constructor ? The method name CONSTRUCTOR is a reserved word. That's all ? Method CLASS-CONSTRUCTOR is also a reserved word. This method is executed when the class is first used, and (like with reglar constructors) it is executed only once. Less common, but can be very important for the information held on class level rather than class-instance level.