Application Development 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: 

Determine all classes of class pool by RTTI

dschiener
Participant
0 Kudos
695

Hi there,

I would like to know if there is a possibility to determine all classes of a class pool using RTTI in ABAP.

It should be possible to determine all containing class in both directions:

Starting from global class -> local class(es) -> local test class(es).

Starting from local test class(es) -> local class(es) -> global class.


I would also prefer a solution without using the namens of the classes as identifying parameters, e.g. I could extract the name of the global class by using the field ABSOLUTE_NAME. That's not the solution I am looking for.

Nice would be something like this, starting from a local test class:

 

 

METHOD my_test.
  DATA(class_descriptor) = CAST cl_abap_classdescr( cl_abap_classdescr=>describe_by_oref( me ) ).
  DATA(global_class) = class_descriptor->global_class.
ENDMETHOD.

 

 

BR

6 REPLIES 6

Sandra_Rossi
Active Contributor
564

Probably RTTS is not relevant for doing such a thing. RTTS is to help working with ABAP types, not to scan the internal parts of a type. Of course, you have other solutions which don't imply RTTS.

dschiener
Participant
0 Kudos
564

sandra.rossi

Of course, you have other solutions which don't imply RTTS.

For example?

Sandra_Rossi
Active Contributor
0 Kudos
564

You have limited the question to RTTS, it's why I didn't elaborate.

Quickly, by "of course", I meant all you could think of primarily like what is done by where-used list in ABAP editor, ABAP Unit framework, Code Inspector (used by ATC), etc., all implying reading and parsing ABAP source code. I'll elaborate later but I guess other people will reply to this second question.

raymond_giuseppi
Active Contributor
564

Did you try to use a class such as CL_ABAP_COMPILER which allows some xref usage identificaion.

holm
Participant
0 Kudos
564

the question is, why do you need to find those classes by reflection? Or could the problem (that we do not know so far) be solved by a smart design of the related classes itself?

dschiener
Participant
0 Kudos
564

raymond.giuseppi

Did you try to use a class such as CL_ABAP_COMPILER which allows some xref usage identificaion.

Not yet. I did not know this SAP class before! Thanks for the hint.

holm.kettner

the question is, why do you need to find those classes by reflection?

I want to write smart and reusable unit tests for several enumeration classes. In general the unit tests should do checks on the containing attribute of the public class and other use cases. Therefore I need to know the name of the public class and also the ones of their local classes at run time.

BR