‎2008 Dec 02 10:34 AM
Hi!
I' ve got a function with a changing-parameter typed as follows:
ch_r_data type ref to data.
In my function I' m trying to assign either a string or a integer to this data reference - depending on some logic.
Unfortunatly, it' s not possilbe to directly assign a value to a generic typed data reference with
ch_r_data->* = 123.or
ch_r_data->* = 'abc'.Has anybody got an idea how to tackle that problem?
Regards,
Thomas
‎2008 Dec 02 10:41 AM
Hi,
Jus check the below logic. This will help you out..
field-symbols <fs> type any.
data dref type ref to data.
data value1 type i value 1234.
get reference of value1 into dref.
assign dref->* to <fs>.
write <fs>.
Cheers,
Hakim
Edited by: Abdul Hakim on Dec 2, 2008 5:42 AM
‎2008 Dec 02 10:41 AM
Hi,
Jus check the below logic. This will help you out..
field-symbols <fs> type any.
data dref type ref to data.
data value1 type i value 1234.
get reference of value1 into dref.
assign dref->* to <fs>.
write <fs>.
Cheers,
Hakim
Edited by: Abdul Hakim on Dec 2, 2008 5:42 AM
‎2008 Dec 02 11:39 AM
Hi, Hakim!
Thanks for answer. To be honest, that' s not exactly what I meant. Let me explain the problem with an example:
types: begin of t_dtype,
dtype type string,
dref type ref to data,
end of t_dtype.
class a definition.
public section.
methods: get_ref changing ch_r_data type t_dtype.
endclass.
class a implementation.
method get_ref.
if ch_r_data-dtype = 'string'.
get reference of 'abc' into ch_r_data-dref.
" Won' t work cause 'abc' is gone when method is finished
ch_r_data-dref->* = 'abc'.
" Compile error - can' t dereference generic type.
field-symbols: <fs_data> type string.
" what now?
elseif ch_r_data-dtype = 'int'.
" Same problem
endif.
endmethod.
class b definition.
public section.
methods: main.
endclass.
class b implementation.
method main.
data: lr_a type ref to a,
ls_dtype type t_dtype,
l_string type string.
create object lr_a.
ls_dtype-dtype = 'string'.
get reference of l_string into ls_dtype-dref.
lr_a->get_ref( changing ch_r_data = ls_dtype ).
endmethod.
endclass.I hope, the problem is now clearer.
Any ideas?
Regards,
T.
Edited by: Thomas Würcher on Dec 2, 2008 12:40 PM
Edited by: Thomas Würcher on Dec 2, 2008 12:49 PM
‎2008 Dec 02 6:40 PM
Had to create another fully-typed data reference variable inside the method with
data: lr_str type ref to stringwhich I assigned the outside variables address via
lr_str = ch_r_data-drefand then dereferrenced it for receiving the value with
lr_str->* = 'abc'
.