01-27-2008 9:21 AM
What is constructor in Abap objects. Please explain with example.
01-27-2008 9:39 AM
Hi,
Constructor method
Implicitly, each class has an instance constructor method with the reserved name constructor and a static constructor method with the reserved name class_constructor.
The instance constructor is executed each time you create an object (instance) with the CREATE OBJECT statement, while the class constructor is executed exactly once before you first access a class.
The constructors are always present. However, to implement a constructor you must declare it explicitly with the METHODS or CLASS-METHODS statements. An instance constructor can have IMPORTING parameters and exceptions. You must pass all non-optional parameters when creating an object. Static constructors have no parameters.
Static constructor
The static constructor is always called CLASS_CONSTRUCTER, and is called autmatically before the clas is first accessed, that is before any of the following actions are executed:
1) Creating an instance using CREATE_OBJECT
2) Adressing a static attribute using <classname>-><attrbute>
3) Calling a ststic attribute using CALL METHOD
4) Registering a static event handler
5) Registering an evetm handler method for a static event
The static constructor cannot be called explicitly.
check out this link for example program using constructor...
http://www.erpgenie.com/abap/OO/eg.htm#Use constructor to create an object with parameters
Reward points if useful **
Regards,
Shanthi.P