I would like to know if two RTTI objects describe the same type.
Is it safe to assume that two objects describing the same type would reference the same instance ?
IF lo_typedescr1 = lo_typedescr2.
" Described types are identical
ELSE.
" Described types are not identical
ENDIF.
The answer depends on the exact context in which you are comparing two ABAP types, and on which criteria you use to consider that the types are identical.
Here is an example which demonstrates that there are two different RTTI Objects (which means that the condition
IF type_1 = type_2is evaluated as false) for the "same" type, one is declared usingTYPE c LENGTH 1and another one usingTYPE flagwhich is an ABAP Dictionary data element of type C and length 1:By debug we see that the RTTI Objects are different:
Here is another example which also demonstrates that there are two different RTTI Objects for the "same" structured type:
get_type_1:get_type_2:In the blog post Improve the Memory Consumption of ABAP Runtime Type Creation (RTTC), we can see that the dynamic creation of types with the method
createmay create several RTTI Objects corresponding to the exact same type.create:get_type_1:get_type_2:get:get_type_1:get_type_2:The official ABAP documentation - Runtime Type Services (RTTS) is helpless because it describes RTTS in only a few sentences.
Of course, people will often find that the test
IF type_1 = type_2will work, but that won't be always the case as I explained above.To be complete, with this example below,
IF type_1 = type_2is evaluated as true:get_type_1:get_type_2: