2

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?

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Adam Harkus
  • 2,050
  • 2
  • 36
  • 64
  • There are already some very interesting answers to the same question [here in SAP Community](https://answers.sap.com/questions/13132061/abap-how-do-you-check-where-a-method-is-called-fro.html). – Sandra Rossi Sep 09 '20 at 15:21
  • 2
    Does this answer your question? [How to find ABAP program/FM which invokes this method](https://stackoverflow.com/questions/45327306/how-to-find-abap-program-fm-which-invokes-this-method) – Sandra Rossi Sep 09 '20 at 15:23

2 Answers2

1

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.

Philipp
  • 67,764
  • 9
  • 118
  • 153
0

Sorted using the code_scanner transaction.

Adam Harkus
  • 2,050
  • 2
  • 36
  • 64
  • `RS_ABAP_SOURCE_SCAN` is better to use, since it has more search options and is more standard. `code_scanner` uses `AFX_CODE_SCANNER` prog under the hood, which lays in `AFX_FRAMEWORK` package, which seems to be Finance-specific and may not be available on all systems. – Suncatcher Sep 22 '20 at 10:53