‎2010 Jan 29 10:45 AM
Hi All,
I want to know the same class name which I am executing in the constructor of the class. Is there any system variable which stores this information. Like for example sy-repid for reports.
Then after getting the calss name in string how I am going instantiate the same.
Regards,
Guru Dutt
‎2010 Jan 29 2:14 PM
You can use the RTTS classes to get to know to the class name but this would only possible once you have the object.
CRATE OBJECT ... statement creates the object before calling the CONSTRUCTOR. So, when system calls the CONSTRUCTOR, the attributes and methods can be accessible by the reference of ME. So, you can pass the reference ME to the method DESCRIBE_BY_OBJECT_REF of the class CL_ABAP_TYPEDESCR in the parameter P_OBJECT_REF and get back the Description object. Attribute ABSOLUTE_NAME of the description object would be the name of the class.
Like:
data: type_ref TYPE REF TO cl_abap_typedescr,
type_ref = cl_abap_typedescr=>describe_by_object_ref( me ).
type_ref->absolute_name " Name of the class
Regards,
Naimesh Patel
‎2010 Jan 29 2:12 PM
Hi,
You could use the class cl_abap_typedesc to achive this
check out this coding http://help.sap.com/abapdocu_70/de/ABENRTTI_OBJECT_TYPE_ABEXA.htm
the informations you need will be in the attributes of the object of cl_abap_typedesc.
Greetings,
dsp
‎2010 Jan 29 2:14 PM
You can use the RTTS classes to get to know to the class name but this would only possible once you have the object.
CRATE OBJECT ... statement creates the object before calling the CONSTRUCTOR. So, when system calls the CONSTRUCTOR, the attributes and methods can be accessible by the reference of ME. So, you can pass the reference ME to the method DESCRIBE_BY_OBJECT_REF of the class CL_ABAP_TYPEDESCR in the parameter P_OBJECT_REF and get back the Description object. Attribute ABSOLUTE_NAME of the description object would be the name of the class.
Like:
data: type_ref TYPE REF TO cl_abap_typedescr,
type_ref = cl_abap_typedescr=>describe_by_object_ref( me ).
type_ref->absolute_name " Name of the class
Regards,
Naimesh Patel
‎2010 Feb 01 10:10 AM
Hi,
When I am using
DESCR_REF = CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( ME ).There is a compile error showing : The reference 'Me" to the current instance exists only with instance methods.
Please let me know how to overcome this.
Regards,
Guru
‎2010 Feb 01 2:12 PM
You can't access the own Object Reference with ME inside the static method because to access static method, you don't need to instantiate the object.
Mention your overall design and what you are trying to do.
Regards,
Naimesh Patel
‎2010 Feb 02 5:35 AM
Hi,
There is a standard interface A with methods A1(Instance dependent), A2(static). There is a custom class B which uses the interface A. There is a sub-class C which inherits B as super-class.
A(Interface)->B(Super Class)->C(Sub Class)Now method A2 can be modified in class B. So here I can create a object refernce of type B. But when the same method A2 is visible in class C I cannot create obejct reference for class C. in method A2.
So for the same reason I needed to know the calling class name so that I can make the object reference dynamic based on calling class.
Please let me know is there any way to handle this.
Regards,
Guru
‎2010 Feb 02 6:49 AM
hi,
for objects you also need to use the method describe_by_object_ref( )
Greetings,
dsp