Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Determine class name used for calling a static method

pokrakam
Active Contributor
0 Likes
15,218

Hi all,

I know static methods cannot be redefined, but they can be called using a subclass as the 'calling class name'. Is it possible to determine the object type used for calling a static method?

For example, I have ZCL_SUPER with a static method HELLO and a subclass ZCL_SUB.

I can use ZCL_SUPER=>HELLO( ) or I can use ZCL_SUB=>HELLO( ).

Both will execute the same code (correct), but is it possible to tell the difference inside the HELLO method? SY-REPID will always show the superclass (also correct).

I've found some similar threads but none with a clear answer.

Any input appreciated,

Mike

1 ACCEPTED SOLUTION
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
10,321

I guess there is no simple solution. I expect that the compiler interprets the symbolic names ZCL_SUPER=> and ZCL_SUB=> in order to point to the method and forgets about it. Why should it keep the information? In fact I have a similar problem: Is there a simple way to find out the name of an actual parameter passed to a formal parameter inside a method? It isn't! I ended up in interpreting the call stack and parsing the calling code!

I guess there is no simple solution. I expect that the compiler interprets the symbolic names ZCL_SUPER=> and ZCL_SUB=> in order to point to the method and forgets about it. Why should it keep the information? In fact I have a similar problem: Is there a simple way to find out the name of an actual parameter passed to a formal parameter inside a method? It isn't! I ended up in interpreting the call stack and parsing the calling code!

41 REPLIES 41
Read only

0 Likes
2,656

Thanks Horst,

I was looking on CL_DEMO_OUTPUT before, but I thought that maybe there is other way Now I need some time to adapt this to my need.

Cheers

Łukasz

Read only

matt
Active Contributor
0 Likes
2,656

Moderator message: in future, please don't add your question to a question that's more than a few months old. Rather create a new question and link to the old.