Skip to Content
-1

How to get the CLASSNAME from an UNINSTANCIATED object.

Dec 08, 2017 at 01:36 PM

81

avatar image
Former Member

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.

ybq7a.png (18.4 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Horst Keller
Dec 08, 2017 at 01:46 PM
3

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.
Show 3 Share
10 |10000 characters needed characters left characters exceeded

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=

1

But absolute names are better suited for dynamic type specifications.

1

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.

0