How to check where a who calls this method?

Viewed 2083

I have a custom method in an ABAP class.

I used the 'Where used' tool to show where the class is called from but, as it turns out, it's called from somewhere else I didn't expect.

So what's the best way of showing a complete list of everything that calls the method?

2 Answers

Due to the wonders of object-oriented programming, an instance of a class can hide behind a reference to one of its base classes or interfaces it implements. For example:

DATA foo TYPE REF TO z_my_interface.    
CREATE OBJECT foo TYPE z_my_class.  
" lots of more code
foo->bar( ).

You can not find this reference to z_my_class->foo with its "Where Used" list, because at that code location foo could also be a reference to an instance of any other class which implements z_my_interface. But you might be able to find this if you don't just look at the where-used list of the method but at the where-used list of the whole class or the interface / base class which declares the method.


And then there are evil dynamic programming tricks like this which determine methods and classes at runtime:

DATA foo TYPE REF TO object.
CONSTANTS: classname TYPE string VALUE 'Z_MY_CLASS',
           methodname TYPE string VALUE 'BAR'.

CREATE OBJECT foo TYPE (classname).
CALL METHOD foo->(methodname).

There is no chance to find this with the where-used tool. But if the class- and/or method name does actually appear in the code (it might not, for example if they are read from a customizing table) then you can use the report RS_ABAP_SOURCE_SCAN. This handy little tool allows you to select a set of ABAP programs and search for strings (and even regular expressions) within their sourcecodes.


However, if you know the method gets called when you do something specific as a user and just want to know where, then it can be easier to just set a debugger breakpoint in the method, run into it and check the call stack.

Sorted using the code_scanner transaction.

Related