Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Make export parameter point to an existing memory reference

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!

3 REPLIES 3

michael_piesche
Active Contributor

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?

michael_piesche
Active Contributor

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.

michael_piesche
Active Contributor
0 Kudos

adaceroge, please follow up on your open question.

  • comment answers or your question if there are still open issues.
  • otherwise mark an answer as accepted if it helped you solve your problem
  • or post an answer of yourself and accept it if you found another useful solution yourself
  • or redirect your question to another question that is related and was useful to solve your problem
  • in the end, close your question