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: 

How to get the CLASSNAME from an UNINSTANCIATED object.

Former Member
0 Kudos

Hi,

I would like to get the Classname from an UNinstanciated object.

 METHOD constructor.
    DATA obj        TYPE REF TO zcl_c1h_zamiz_fil_dao.
    DATA classname  TYPE string.
    classname  = CLASS=>Method( obj ) .
ENDMETHOD.

The DEBUGGER mode provides this information:

Thank you very much.

Rachid.

1 ACCEPTED SOLUTION

horst_keller
Product and Topic Expert
Product and Topic Expert

To say it correctly, you want the static type of an initial reference variable (there is not such a thing as an uninstantiated object).

Use RTTI.

 DATA(class_name) = 
  CAST cl_abap_refdescr( 
    cl_abap_typedescr=>describe_by_data( oref ) 
      )->get_referenced_type( 
        )->absolute_name.
4 REPLIES 4

horst_keller
Product and Topic Expert
Product and Topic Expert

To say it correctly, you want the static type of an initial reference variable (there is not such a thing as an uninstantiated object).

Use RTTI.

 DATA(class_name) = 
  CAST cl_abap_refdescr( 
    cl_abap_typedescr=>describe_by_data( oref ) 
      )->get_referenced_type( 
        )->absolute_name.

absolute_name returns for instance \CLASS=<the global class> (+ possibly some more complex "paths" for local classes)

You may use get_relative_name( ) to get the name of the class without the prefix \CLASS=

horst_keller
Product and Topic Expert
Product and Topic Expert

But absolute names are better suited for dynamic type specifications.

0 Kudos

You're right (always 🙂 ). Sometimes the name of the class only is needed for some logics. As we don't know the final goal of the OP.