2007 Mar 06 2:47 PM
Hi!
Strange question at first, but let me explain.
I want to write a method that gets an empty interface reference, determines the interface type and creates an instance of a predefined class that implements the given interface. Perhaps a bit of source code makes this a little bit clearer:
DATA: lr_instance type ref to <Name of Interface, e.g. "IF_WORKFLOW">.
lr_instance ?= /eas/cl_plugin_factory=>get_instance_for_interface( lr_instance ).
The returning parameter is type as REF TO OBJECT and the importing parameter as ANY. The passed reference is not bound before the call. The method's task is it to get the static type of the passed reference, lookup an implementing class (left out for simplification), create an instance of this class and bind it to the interface reference.
I tried to use the RTTI classes (CL_ABAP_TYPEDESCR), but the returned type instance is not of type CL_ABAP_INTFDESRC as expected, but CL_ABAP_REFDESRC.
Anyone an idea how to solve this puzzle ?
Hi!
Strange question at first, but let me explain.
I want to write a method that gets an empty interface reference, determines the interface type and creates an instance of a predefined class that implements the given interface. Perhaps a bit of source code makes this a little bit clearer:
DATA: lr_instance type ref to <Name of Interface, e.g. "IF_WORKFLOW">.
lr_instance ?= /eas/cl_plugin_factory=>get_instance_for_interface( lr_instance ).
The returning parameter is type as REF TO OBJECT and the importing parameter as ANY. The passed reference is not bound before the call. The method's task is it to get the static type of the passed reference, lookup an implementing class (left out for simplification), create an instance of this class and bind it to the interface reference.
I tried to use the RTTI classes (CL_ABAP_TYPEDESCR), but the returned type instance is not of type CL_ABAP_INTFDESRC as expected, but CL_ABAP_REFDESRC.
Anyone an idea how to solve this puzzle ?
2007 Mar 06 3:00 PM
Hi!
Ok, how stupid can one be.. Next time, I will debug a little bit further before posting questions here in the forums. For anyone wanting to do something similiar, the answer to the question follows.
The solution is that simple: CL_ABAP_REFDESRC owns a method to return the referenced type: GET_REFERENCED_TYPE. This method returns nicely an instance of CL_ABAP_INTFDESRC if passed an interface reference. With this interface type, one can get the name of the interface easily with GET_RELATIVE_NAME.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |