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

Regarding constructors in oops

spandana_babu
Participant
0 Likes
2,063

hi

sap gurus

hw to view the constructors in class builder..& also tell hw to use construcotrs in oops abap

with example..

hw can i find out the parameters for the constructor in stanadard class.

Regards

Spanadna

4 REPLIES 4
Read only

amit_khare
Active Contributor
0 Likes
1,377

check class in SE24.

Read only

Former Member
0 Likes
1,377

Hi Spandana,

You instantiate a class using the ABAP statement CREATE OBJECT. This calls the constructor for the instance. The constructor can contain parameters that you may have to supply with values.

there are two special methods which you call using CALL METHOD. These are called CONSTRUCTOR and CLASS _CONSTRUCTOR. They are automatically called when you create an object (Constructor) or when you first access the components of a class (CLASS _CONSTRUCTOR).

find the below links are helpful to understand the ABAP Objects.

[http://help.sap.com/erp2005_ehp_03/helpdata/EN/ce/b518b6513611d194a50000e8353423/frameset.htm|http://help.sap.com/erp2005_ehp_03/helpdata/EN/ce/b518b6513611d194a50000e8353423/frameset.htm]

Read only

matt
Active Contributor
0 Likes
1,377

>

> hi

>

> sap gurus

>

> hw to view the constructors in class builder..& also tell hw to use construcotrs in oops abap

> with example..

> hw can i find out the parameters for the constructor in stanadard class.

>

>

> Regards

>

> Spanadna

This should have been posted in the ABAP Objects section...

If you look at the class in SE24, you may see a method called "CONSTRUCTOR". If you set your cursor on the constructor, and click on the PARAMETERS button, you'll see the parameters. These are always input parameters. A constructor can have zero, one or many parameters. Some may be optional.

You can also tell the parameters of a constructor by using the Create object pattern (Pattern button in the ABAP editor, ABAP Objects Patterns, Create object ).

If you don't see a CONSTRUCTOR method in SE24, it means that the class does not have an explicit constructor. In this case, CREATE OBJECT still returns an object reference, but there's no code run in the class at creation, and there are no parameters.

matt

Read only

Former Member
0 Likes
1,377

hii..

first constructors are the 1st events tht are triggered in a class..there r 2 type of constructors..static and instance.

for eg in oops.

class cl1 definition.

public section.

methods: add,sub, constructor importing v1 type i v2 type i.

class-methods:class_constructor. -


> ths is static constructor.its only triggered once at the beginning of the object.

private section.

data:var1 type i,var 2 type i,result type i.

class-data: counter type i.----> static data to count the number of the static constructor occurrence.

methods:display.

endclass.

class 1 implementation.

method add. reasult = var1 + var2.

display().

endmethod.

method display.

write: 'reasult', result.

endmethod.

method constructor.

var1 = v1.

var2 = v2.

endmethod.

method class_constructor.

write: 'ths is static'.

endmethod.

_

*now the main prg...*_

data:ref1 type ref to cl1.

parameters: p1 type i,p2 type i.

data:result type i.

star-of-selection.

create object ref1 exporting v1=p1 v2=p2.

ref1->add().

hopefully i am able to expalin you with ths example....

plzz reward points if helpful...