Application Development and Automation 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: 
Read only

Accessing Data References

Former Member
0 Likes
647

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

1 ACCEPTED SOLUTION
Read only

abdul_hakim
Active Contributor
0 Likes
620

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

3 REPLIES 3
Read only

abdul_hakim
Active Contributor
0 Likes
621

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

Read only

0 Likes
620

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

Read only

Former Member
0 Likes
620

Had to create another fully-typed data reference variable inside the method with

data: lr_str type ref to string

which I assigned the outside variables address via

lr_str = ch_r_data-dref

and then dereferrenced it for receiving the value with

lr_str->* = 'abc'

.