‎2008 Aug 03 2:51 PM
hi all,
where should we use static Constructors and where should we use instance Constructors .
can any one help me with the proper scenarios.
<removed by moderator>
thanks and best regards,
sravan.
Edited by: Mike Pokraka on Aug 3, 2008 6:04 PM
‎2008 Aug 07 11:02 AM
Hii!
Instance constructor is a special instance method in a class and is always named CONSTRUCTOR.
These constructors are necessary after the instanctiation of class:
If you need to allocate the resources
You need to initialize attributes that cannot be covered by the VALUE addition to the DATA statement.
You need to send messages containing the information that a new object was created.
Static constructor is called automatically before the class is first accessed. This means that you can use this constructor if you want some values just before the class is first accessed.
If anyone has better answer. Please come forward.
Even I want to know more about static constructors
Regards
Abhijeet
‎2008 Aug 03 3:03 PM
In this Forum it is Discussed many times, use Search Option.
and Before posting a Question, Read the rules .
Check this:-
http://help.sap.com/saphelp_nw04/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm
Regards
Vijay Babu Dudla
‎2008 Aug 04 3:15 PM
hi vijay,
i need functinal scenarios . means... example requirement at which we define these two constuctors.
thanks & Regards,
sravan.
‎2008 Aug 03 8:52 PM
Hello Sravan
The same questions were discussed recently:
Regards
Uwe
‎2008 Aug 07 10:47 AM
‎2008 Aug 07 11:01 AM
Hi Sravan,
Please got through the links ,
http://www.thaiabap.com/index.php?option=com_content&view=article&id=2043
http://help.sap.com/saphelp_nw04/helpdata/en/08/d27c03b81011d194f60000e8353423/content.htm
http://www.slideshare.net/srinatha/oo-abap-sap/
http://www.geocities.com/rmtiwari/Resources/Utilities/ABAPReference/ABENCONSTRUCTOR.htm
http://www.sap-press.de/katalog/buecher/htmlleseproben/gp/htmlprobID-28
Regards,
Sreekar.Kadiri
‎2008 Aug 07 11:02 AM
Hii!
Instance constructor is a special instance method in a class and is always named CONSTRUCTOR.
These constructors are necessary after the instanctiation of class:
If you need to allocate the resources
You need to initialize attributes that cannot be covered by the VALUE addition to the DATA statement.
You need to send messages containing the information that a new object was created.
Static constructor is called automatically before the class is first accessed. This means that you can use this constructor if you want some values just before the class is first accessed.
If anyone has better answer. Please come forward.
Even I want to know more about static constructors
Regards
Abhijeet
‎2008 Aug 07 12:13 PM
Static constructors in ABAP are called Class Constructors. I use them when I want to initialise some static attributes for later use.
For example, if I was writing a class to handle materials, I might define an internal table as a static attribute to hold of MAKT. Then when I wanted to get a material description, I'd go to the static attribute and read that, but first, I'd have to check whether it was populated.
IF sth_makt IS INITIAL.
SELECT * FROM makt INTO TABLE sth_makt WHERE spras = sy-langu.
ENDIF.
READ TABLE sth_makt ASSIGNING <ls_makt> WITH TABLE KEY matnr = i_matnr.
...And I'd have to do this everywhere I want to read sth_makt, and their could be a risk if someone is extending my class, or I'm enhancing it later, that I forget to check whether the table is filled.
If I put the select in the Class constructor, I don't have to worry about any check, safe in the knowledge that whenever I want to READ makt, it will already be populated.
matt
‎2008 Aug 07 1:07 PM