Application Development and Automation 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: 
Read only

constructor

Former Member
0 Likes
547

Dear Experts ,

plz explain me this coe with some suitable example , im unable to understand this . I m new in oo abap .plz help me.

if you have anyb documents regaeding oo abap , plz send me .

METHODS:

constructor

IMPORTING im_no TYPE i

im_name TYPE string

im_hours TYPE i

im_hourly_payment TYPE i,

Thanks .

4 REPLIES 4
Read only

Former Member
0 Likes
525

Hello,

Please, see these: [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3e59b790-0201-0010-88aa-bc8a7f95f6fb], [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3412d190-0201-0010-aaaa-ff5a315ae5fe] and [http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf].

Regards.

Read only

Former Member
0 Likes
525

Hi Ranjna,

That is the implementation part of the class, in which a constructor will be useful for initializing the class attributes (both public as well as private).

for example

METHODS:

constructor

IMPORTING im_no TYPE i

im_name TYPE string

im_hours TYPE i

im_hourly_payment TYPE i,

this particular constructor is useful for initializing the class attributes number, name, hours, hourly_payment when ever an object is created.

in the above example the constructor is importing number , name , hours, payment ....while an object is created and assign these values to the object created from that class.

but we need to see that a constructor cant have exporting or returning parametres. only importing parametres.

we cant call the constructor explicitly, it is called automatically when ever an object is created.

this is just a small part of constructors , again

constructors are two types one is instanc and other is class.

instance constructor is called when ever an object is accessed and an class constructor is called when ever an class is accessed for the first time.

instance constructors will be called as many times as objects created.

class constructor is called only once. i.e when class is first accessed.

this is just basic idea of constructors.....

go through the above links given by others.....it will help u a lot.

best of luck......

cheers

kiran

Read only

former_member188594
Active Participant
0 Likes
525

Hi,

You need to have some object oriented programming knowledge first, which you can acquire through various links provided by others. Coming to present context,

CONSTRUCTOR is a special method that is called by runtime system as soon as the object has been generated in the memory. This can have only IMPORTING parameters and exceptions.

There are two types of CONSTRUCTORS:

1) Instance constructor:

The CONSTRUCTOR is a special instance method in a class and is always named CONSTRUCTOR. The constructor is automatically called at runtime with the CREATE OBJECT.

2) Static or class constructor:

The static constructor is a special static method in a class and is always named CLASS_CONSTRUCTOR. It is executed no more than once per program or class. The static constructor is called automatically before the class is first accessed. This constructor's signature cannot have IMPORTING parameters or EXCEPTIONS and cannot be called explicitly.

CONSTRUCTOR and CLASS_CONSTRUCTOR are automatically called when you create an object or when you first access the components of the class.

Reward points if you find this useful.

Regards,

Sekhar