2009 Nov 15 5:27 PM
Hello,
Pls. let me know, What is the use of constructor, while creating the custom clasess (or) in the context of ABAP objects? actually, I have gone through the first 2 tutorials of this this link, [http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3414800)ID1160600550DB10016261778120999663End?blog=/pub/wlg/15408] but, sorry to say that, i did not understand the content!! also, pls. let me know that, When we have to use "me"? wht are the pre-requisites for it?
Thank you
2009 Nov 15 6:08 PM
The CONSTRUCTOR of a class is a method which is called automatically when you create an instance of object of that class. So ABAP code, when you use the statement CREATE OBJECT <instance>. Then the CONSTRUCTOR method is called. This constructor method is used to "iniitialize" the instance(or object) but you can put ABAP code in there to do whatever you want really. This is not specific to ABAP, but to OO concepts. You should read a paper on Object Oriented concepts, and then try to apply them to ABAP, it will make more sense, I think.
As for as using "me". In ABAP, "Me" is basically a reference to the instance of an object. You use "me" when referring to the instance of the object in which you are working in. For example, lets say that you have an attribute in your class called foo. And you have a method in your class called, set_foo. In your SET_FOO method of the class, you would have access to this foo attribute. You could set it using the following syntax.
me->foo = 'This is foo'.Likewise, lets say that you call the SET_FOO method in your CONSTRUCTOR method. You can use this syntax.
me->set_foo( ).So again, "me" is simply referencing the instance of the class.
Regards,
Rich Heilman
2009 Nov 15 6:08 PM
The CONSTRUCTOR of a class is a method which is called automatically when you create an instance of object of that class. So ABAP code, when you use the statement CREATE OBJECT <instance>. Then the CONSTRUCTOR method is called. This constructor method is used to "iniitialize" the instance(or object) but you can put ABAP code in there to do whatever you want really. This is not specific to ABAP, but to OO concepts. You should read a paper on Object Oriented concepts, and then try to apply them to ABAP, it will make more sense, I think.
As for as using "me". In ABAP, "Me" is basically a reference to the instance of an object. You use "me" when referring to the instance of the object in which you are working in. For example, lets say that you have an attribute in your class called foo. And you have a method in your class called, set_foo. In your SET_FOO method of the class, you would have access to this foo attribute. You could set it using the following syntax.
me->foo = 'This is foo'.Likewise, lets say that you call the SET_FOO method in your CONSTRUCTOR method. You can use this syntax.
me->set_foo( ).So again, "me" is simply referencing the instance of the class.
Regards,
Rich Heilman