The class builder is a beautiful thing. It hides all the messy code from developers that is necessary to define and implement a class in ABAP. All we coders get to see is a pretty, abstracted interface. We can graphically define most properties of class or interface methods and parameters and only very rarely need to look at the actual coding. All we need to do is write the source code that makes the class work within.
However, what if there’s a problem? If you’ve ever run the extended code check for a class method, you know there’s an issue. All you get displayed are the internal, auto-generated include names that your class method came from. You don’t really know what’s what, and that’s not very nice.
The extended code check result is useless without knowing the include names.
Also, sometimes there’s a valid reason for having to look at the actual, un-abstracted program code – for example when you want to implement a custom code inspector check. The class builder makes it hard (or rather, impossible) to do this, and its pretty graphical interface is laughing at us mockingly.
But there must be something we can do! Well, of course there is. Funnily enough, the solution to this issue with classes is – a class. Specifically, it’s the ABAP class CL_OO_INCLUDE_NAMING, which provides methods that allow you to find out the internal names of the class building blocks.
Of course, you could write a program to call the methods of this class, but it’s much easier to just open the class in the class builder (transaction SE24). Start the test environment by clicking the wrench icon or pressing F8. A popup will appear, asking you to enter a type or field length for a generically typed parameter. Enter the value “30” for the length.
Enter “30” here to proceed.
In the list of class methods that is displayed now, find the method GET_INSTANCE_BY_NAME and click the little Execute button next to it. Provide the class name you’re working with as a parameter, execute, and… wait, what?
Well, it’s not that easy. This method returns an object of type CL_OO_INCLUDE_NAMING – yes, that’s the same class we’re already in. To proceed, click the little grey circle () next to the return value. You’re taken to the object details. This object has three interfaces as values. Click on the little detail button next to the interface IF_OO_CLASS_INCL_NAMING.
Still with me? From this interface, you can already see a bit of information, such as the internal name of the includes for different sections of the class. To see a list of names for all class methods, execute the object method GET_ALL_METHOD_INCLUDES. You are now – finally – presented with a list that contains a mapping of method names to their respective includes.
The other methods might be interesting as well. Using the method GET_INCLUDE_BY_SECTION, you can get the include names for the public, protected and private sections of the class. To do that, execute the method and use the following constants.
So, what if we want to do it the other way round – find out which method is in a specific class include? Luckily, that’s a much easier task. There are several possibilities to do that:
That’s it for this topic! Hope it helps you to make your development better.