‎2012 Mar 19 9:45 AM
Hi,
is there a disadvantage if i create a class with only static methodes. I don't need to create object, just use static methodes.
I want this class because we are using same select statements several times in different methodes.
tnx. Adibo
‎2012 Mar 19 3:13 PM
Adibo A wrote:
is there a disadvantage if i create a class with only static methodes. I don't need to create object, just use static methodes.
There is not disadvantage. If you are storing something in STATIC attributes, than you need to pay extra attention while clearing them. Otherwise, this method would be simply an Utility method which accepts the input and gives back the output.
I want this class because we are using same select statements several times in different methodes.
Are these methods being called in the same LUW or Session with Same input parameter with same expected Output? If yes, than you should consider Singleton DP.
Regards,
Naimesh Patel
‎2012 Mar 19 12:42 PM
Hi Adibo,
is there a disadvantage if i create a class with only static methodes. I don't need to create object, just use static methodes.If you really don't need to store results for further calls, IMO there are no disadvantages.
I want this class because we are using same select statements several times in different methodes.
I don't really understand your needs, but I thinks this is not important for my 1st answer
‎2012 Mar 19 1:27 PM
Hi,
I want this class because we are using same select statements several times indifferent methodes.
For this, you can create a class using singleton design pattern, and create static attributes( table types) to store date from DB and you can access those attributes.
Hope this helps u.,
Thanks & Regards,
Kiran.
‎2012 Mar 19 2:47 PM
kiran kumar Reddy wrote:
For this, you can create a class using singleton design pattern, and create static attributes( table types) to store date from DB and you can access those attributes.
Why?
Singleton DP is implemented if you want to use the same instance of a class through out your application. If i understand correctly the OP doesn't need to work with an instance of the class, so why Singleton, please enlighten us?
‎2012 Mar 20 10:40 AM
Hi Suhas,
Sorry for my late reply. As the OP asked,
I want this class because we are using same select statements several times in different methodes.
What I feel was, he could have create a class using singleton DP, and for the first time, fetch the data from DB and store in the attributes of that instance. Now when he wants the data again, he can check whether the instance is bound or not. if it is bound, he can avoid hitting DB!
Correct me if you feel it is wrong.
Regards,
Kiran.
‎2012 Mar 19 3:13 PM
Adibo A wrote:
is there a disadvantage if i create a class with only static methodes. I don't need to create object, just use static methodes.
There is not disadvantage. If you are storing something in STATIC attributes, than you need to pay extra attention while clearing them. Otherwise, this method would be simply an Utility method which accepts the input and gives back the output.
I want this class because we are using same select statements several times in different methodes.
Are these methods being called in the same LUW or Session with Same input parameter with same expected Output? If yes, than you should consider Singleton DP.
Regards,
Naimesh Patel
‎2012 Mar 20 10:40 AM
Hi,
Tnx all, for the answers!!
@Patel, method could be called in the same LUW but I don expect the same output.
I'am just using static methods to reduce some code and to prevent writing same select statement over and over again..
See my code:
zCL_STATIC_METHODS
| GET_ZAKENPARTNER_SOORT | Static Method | Public | Get Zakenpartner Soort' |
| I_PARTNER | Importing | Type | BU_PARTNER | Nummer zakenpartner | |
| E_TEXT | Exporting | Type | BU_TEXT40 | Omschrijving |
METHOD get_zakenpartner_soort.
SELECT SINGLE tb004t~text40 INTO e_text
FROM but000
INNER JOIN tb004t ON but000~bpkind EQ tb004t~bpkind "#EC CI_BUFFJOIN
WHERE but000~partner EQ i_partner.
ENDMETHOD.
And i call it like this:
REPORT z_static_call.
DATA: lv_text TYPE bu_text40.
zcl_static_methods=>get_zakenpartner_soort(
EXPORTING i_partner = '0010000278'
IMPORTING e_text = lv_text ).
BREAK-POINT.
As simple as that.