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: 

Transfering Data from one object to the other

Former Member
0 Kudos

Hallo all,

i have to move detaildata from one instance to an other instance.

Both are instances of IF_REBD_MEAS_MNGR but they have different partents.

i tried with an simple go_object_trg = go_object_src but that doesn't work because the parent of go_object_trg changes to the original one and so the Data can't be stored because the target object diddn't change.

Can anyone help?

Thanks a lot

Best regards, Stefan

5 REPLIES 5

Former Member
0 Kudos

Hello,

If they have the same parent/interface you can use the following:


TRY.
    go_object_trg ?= go_object_src.
  CATCH CX_SY_MOVE_CAST_ERROR.
    WRITE: 'Error during cast'.
ENDTRY.

Regards,

0 Kudos

Hallo,

no they don't have the same parent.

is it possible to cast the objects and replace the parent after that cast?

I think this could help.

Best regards

Stefan

matt
Active Contributor
0 Kudos

First, obj1 = obj2 assigns the REFERENCES to the objects. Not the attributes. Essentially you end up with two references to the obj2. As you've found.

If I understand you correctly, you have two instances of different classes, say CL_A and CL_B, that implement the same interface, say IF_I?

Do something like:

DATA: obj1 TYPE REF TO cl_a,
      obj2 TYPE REF TO cl_b.

...some code that builds obj1 and obj2.

obj1->if_i~attrib1 = obj2->if_i~attrib1.
obj1->if_i~attrib2 = obj2->if_i~attrib2.

Or you could write a method something like:

obj1->get_attributes_of( obj2 ).

where get_attributes_of is implemented like:

me->if_i~attrib1 = i_obj->if_i~attrib1.
me->if_i~attrib2 = i_obj->if_i~attrib2.

matt

0 Kudos

Hi,

thanks for the Info.

It looks like this:

DATA:.....
 go_rental_object_vw TYPE REF TO if_rebd_rental_object,
          go_rental_object_mdt TYPE REF TO if_rebd_rental_object,
          go_meas_mngr_vw        TYPE REF TO   if_rebd_meas_mngr,
          go_meas_mngr_mdt        TYPE REF TO   if_rebd_meas_mngr.

And my problem ist, that the go_rental_object_vw with its attributes from go_meas_mngr_vw has to be overwritten with the attributes of go_meas_mngr_mdt

Did you understand me now?

Thanks a lot

Stefan

matt
Active Contributor
0 Kudos

You have to do it attribute by attribute. There's no other way.

matt