Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Constructor

Former Member
0 Kudos

What is constructor in Abap objects. Please explain with example.

1 REPLY 1

Former Member
0 Kudos

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