03-04-2020 9:27 PM
Hi All,
I have an internal table with a list of generic memory references and would like to be able to retrieve them using a method. What I would like is assign the memory reference to the export parameter of my method so I would be able to change the referenced data using the parameter. How can I accomplish this behaviour? My method looks like this at the moment but the result is that the export parameter is a copy of the referenced object so changing it wont update the referenced data.
* SIGNATURE
METHODS get_param
IMPORTING
iv_id_param TYPE clike
EXPORTING
ev_val TYPE any.
* IMPL
METHOD get_param.
DATA: lr_ref TYPE REF TO data.
FIELD-SYMBOLS: <fs_val> TYPE any.
zif_cx_enh_param_map~get_param_ref(
EXPORTING
iv_id_param = iv_id_param
IMPORTING
er_ref = lr_ref
).
ASSIGN lr_ref->* TO <fs_val>.
ev_val = <fs_val>.
ENDMETHOD.
Thanks for any help!
03-05-2020 12:29 AM
Not sure where the problem is. If you want to pass a reference to a data type, then you also need to pass it as a reference "TYPE REF TO data". In your case, you had to define a data type with separate memory assigned to it, before you even called get_param in order to receive the value for ev_val, so thats why those are two different objects in memory and only the value is copied.
If you therefore define your ev_val as "TYPE REF TO" and simply pass the references from method to another. However, then your method will be 'useless' since you could already call zif_cx_enh_param_map~get_param_ref directly.
But maybe you want to do some changes in your method, well in this case, you dereference it with the operator ->* like you did, do your changes to the field-symbol and it all happens for the same data in the memory.
* SIGNATURE
METHODS get_param
IMPORTING
iv_id_param TYPE clike
EXPORTING
ev_val TYPE REF TO data.
* IMPL
METHOD get_param.
zif_cx_enh_param_map~get_param_ref(
EXPORTING
iv_id_param = iv_id_param
IMPORTING
er_ref = ev_val
).
ENDMETHOD.
Does this solve your problem, or am I missing something?
03-06-2020 1:55 AM
Please use comments for comments and not answers!
Regarding your problem, that can’t be done, simply because your ev_value is generic and linked to a data variable that has its own memory when it was declared. So that (outside) data variable is already assigned to your export parameter ev_value. You cannot reassign a variables memory to another variable.
you can only dereference a ref to data with ->* to a field-symbol.
05-13-2020 3:11 PM
adaceroge, please follow up on your open question.