Skip to Content
0

Any advantage in creating a referrence to a standard class to access a method within that class ?

Apr 28, 2017 at 05:37 AM

94

avatar image

Hi,

Is there any advantage in creating a referrence to a standard class and then using that reference to call the method within that standard class ?

CL_ABAP_DATFM=>CONV_DATE_EXT_TO_INT.

Create a reference of Standard class and then accessing a method using that referrence.

data:ref_class  type ref to CL_ABAP_DATFM.
ref_class->CONV_DATE_EXT_TO_INT.

Thanks,

K.Kiran.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Matthew Billingham
Apr 28, 2017 at 09:27 AM
4

ref_class->CONV_DATE_EXT_TO_INT. is semantically misleading, since it is calling a static method as though it is an instance method. Bad programming in my view.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Matt,

Most of the Custom Code based on OOPS which I get to see in my system,often uses this way.That is the reason which made me raise this question.Thanks,

K.Kiran.

0

If it really is just

data:ref_class  typerefto CL_ABAP_DATFM.
ref_class->CONV_DATE_EXT_TO_INT.

Then it's entirely wrong and will dump, since ref_class hasn't been instantiated.

1

Matthew already answered but I suspect someone thought they had to create a reference in order to use the method and then the code got copy-pasted from there. I'm not at all surprised since I've seen some questionable code over and over either written by the same person or the same consulting company. Also made me wonder WTF many times and question my own sanity.

1