‎2007 Jul 26 9:48 PM
Any reason to do this in a program:
DATA: o_zcl_icg_calculations TYPE REF TO zcl_icg_calculations.
CREATE OBJECT o_zcl_icg_calculations.
CALL METHOD o_zcl_icg_calculations->calc_wettons_unit_price
EXPORTING
zunit_price_reg = unit_price
IMPORTING
z_wettons_unit_price = g_wettons_unit_price.
********************************************************************
Why not just do this....any reason?:
CALL METHOD zcl_icg_calculations->calc_wettons_unit_price
EXPORTING
zunit_price_reg = unit_price
IMPORTING
z_wettons_unit_price = g_wettons_unit_price.
‎2007 Jul 27 2:42 AM
Hi Tom, if your question is related to .... why create an instance method over a static method, or vice-versa, it all depends on the application. In a case, where you have a simple utility method, where you pass something, it does something, and gives you a result, then there is no reason why it couldn't just be a static method. But if you are manipulating instance attributes of the class, then it should be an instance method.
So in your case, if the method implementation is just doing something with that value that you are passing and giving a result, then sure the method could be defined as a static method, the you can simply call it directly instead of creating an instance first. But again, the method must be defined as "Static"
CALL METHOD zcl_icg_calculations=>calc_wettons_unit_price
EXPORTING
zunit_price_reg = unit_price
IMPORTING
z_wettons_unit_price = g_wettons_unit_price.
Regards,
Rich Heilman
‎2007 Jul 26 9:52 PM
Tom,
Please check the code in method "zcl_icg_calculations"
aRs
‎2007 Jul 26 9:54 PM
HI,
It all depends on what you are looking for.
in the first instace you are creating a object of that class..
let us say you are doing some calculations which are stored in the class attributes.. in this case these values are specific to the object that you are accessing.
let us say you have two methods..
save_data.. to save data into a attribute of the class.
after some time you say call display_data.. if you dont have a object reference then now way you can get the attributes value
and if you feel that you just want to use the methods of a class and got nothing to do with the conent of the attributes of the class then you can do call a method by taking class reference.
normally static methods are called with class reference
Thanks
Mahesh
‎2007 Jul 27 2:14 AM
To do what you suggest, method should be a class one (not an instance one), thus you should use => operator instead of ->.
‎2007 Jul 27 2:42 AM
Hi Tom, if your question is related to .... why create an instance method over a static method, or vice-versa, it all depends on the application. In a case, where you have a simple utility method, where you pass something, it does something, and gives you a result, then there is no reason why it couldn't just be a static method. But if you are manipulating instance attributes of the class, then it should be an instance method.
So in your case, if the method implementation is just doing something with that value that you are passing and giving a result, then sure the method could be defined as a static method, the you can simply call it directly instead of creating an instance first. But again, the method must be defined as "Static"
CALL METHOD zcl_icg_calculations=>calc_wettons_unit_price
EXPORTING
zunit_price_reg = unit_price
IMPORTING
z_wettons_unit_price = g_wettons_unit_price.
Regards,
Rich Heilman
‎2007 Jul 27 2:20 PM
Thanks Rich...I wasn't able to reward any points. Your explanation and others was very good. I never has a reason yet to use attributes. I guess the system won't let you allow points after a certain amount of time of the posting, if I could I would?
Thanks Again.
‎2007 Jul 27 2:26 PM
‎2007 Jul 27 2:40 PM