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: 

Problem with Constructors in ABAP - OOP

Former Member
0 Kudos

Hello,

I am not able to create multiple constructors inside a Global Class in SE24.

Once i create 1st constructor, the button as well as menu item is automatically disabled.

I have identified that this problem also occurs when i make the 1st constructor passing parameters. In that case, the ABAP program refuses creation of an object without passing values to that object attributes.

I have also tried creating multiple constructors identical to C++ method. i.e. Giving the same name to constructors as that of class name and changing the number/type of parameters that are passed. But ABAP refuses to identify that method as constructor and furthermore multiple methods with the same class name can not be created.

Can anyone have solution to this??

Thanks for your valuable time...

1 ACCEPTED SOLUTION

marcelo_ramos
Active Contributor
0 Kudos

Hi Amar,

In ABAP Objects we can use two types of constructor methods: INSTANCE CONSTRUCTOR and STATIC CONSTRUCTOR.

The constructors are Identified by reserved name "CONSTRUCTOR" to INSTANCE CONSTRUCTOR and "CLASS_CONSTRUCTOR" to STATIC CONSTRUCTOR.

Only two constructors is allowed per class one is "CONSTRUCTOR" and other is "CLASS_CONSTRUCTOR", and doesn't allowed to modify or overwrite its signature.

<b>I Noted that is your first Post, so don't forget to read all <a href="https://www.sdn.sap.com/irj/sdn/wiki?path=/display/HOME/RulesofEngagement&">RULES</a> and close this thread when your question be answer !</b>

Regards.

Marcelo Ramos

3 REPLIES 3

Former Member
0 Kudos

Hi Amar,

OOABAP does not support polymorphism unlike C++. i.e you cannot have more than one mehtod with same name but different signature..

regards,

Piyush

marcelo_ramos
Active Contributor
0 Kudos

Hi Amar,

In ABAP Objects we can use two types of constructor methods: INSTANCE CONSTRUCTOR and STATIC CONSTRUCTOR.

The constructors are Identified by reserved name "CONSTRUCTOR" to INSTANCE CONSTRUCTOR and "CLASS_CONSTRUCTOR" to STATIC CONSTRUCTOR.

Only two constructors is allowed per class one is "CONSTRUCTOR" and other is "CLASS_CONSTRUCTOR", and doesn't allowed to modify or overwrite its signature.

<b>I Noted that is your first Post, so don't forget to read all <a href="https://www.sdn.sap.com/irj/sdn/wiki?path=/display/HOME/RulesofEngagement&">RULES</a> and close this thread when your question be answer !</b>

Regards.

Marcelo Ramos

0 Kudos

Hi Marcelo,

I have some confusion about constructor's............. i know that constructor's are automatically called when ever we create an object for a respective class............may i know what is the exact use of these constructor's ? and why they are automatically called?please resolve my doubt.

Regards,

Venkatt

Moderator Message: Please read the documentation on instance CONSTRUCTORs. Also post a separate thread for your query.

Edited by: Suhas Saha on Nov 8, 2011 10:36 AM