2009 Nov 16 1:45 PM
Hello,
Is it possible to have a dynamic interface declaration like you can have a dynamic object declaration?
For an object:
data: lo_object type ref to object.
create object lo_object type (lv_object_name).
Is this in some way possible to do with an interface? I need to do this for an interface at runtime.
Gr,
Jaron
oops. my bad.
Yes, of course you'll get that error. Because you can't create an object reference to an interface. It has to be reference to a concrete class.
Are you wanting something like:
DATA: r_ref TYPE REF TO (my_interface).
where my_interface contains the name of the interface?
matt
2009 Nov 16 2:23 PM
As long as lv_object_name contains the name of an interface that exists, then the syntax is valid.
matt
2009 Nov 16 2:26 PM
I get an error message saying I can't do it because it's not a class.
Edited by: J. Frenk on Nov 16, 2009 3:26 PM
2009 Nov 16 3:10 PM
oops. my bad.
Yes, of course you'll get that error. Because you can't create an object reference to an interface. It has to be reference to a concrete class.
Are you wanting something like:
DATA: r_ref TYPE REF TO (my_interface).
where my_interface contains the name of the interface?
matt
2009 Nov 18 8:28 AM
You can create data of a dynamically given reference type (which may be an interface) and move the object reference to it.
Something like so:
DATA:
my_obj TYPE REF TO object,
lr_data TYPE REF TO data.
FIELD-SYMBOLS: <fs> TYPE ANY.
CREATE OBJECT my_obj TYPE my_object_type.
TRY.
CREATE DATA lr_data TYPE REF TO (some_interface_type_name).
ASSIGN lr_data->* TO <fs>.
<fs> ?= my_obj.
CATCH cx_sy_move_cast_error.
CATCH cx_sy_create_data_error.
ENDTRY.Basically, the assignment tests if my_obj is an instance of the type named some_interface_type_name.
Hope this helps,
Sebastian
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |