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

Copy object content

Former Member
0 Likes
4,174

Hallo

Does anyone know an easy way to copy the content of an complex object?

The simple opperator "=" would copy only the reference.

I search for a methode to backup an object and write it back later.

Thank you

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,671

Hello Tobias

One possibility would be to serialize your object to XML using CALL TRANSFORMATION. In order to use this option the object must implement the interface IF_SERIALIZABLE_OBJECT (which is just a "marker", like in Java).

The other way is to have a look at class CL_OS_STATE. This class has a method CLONE (apparently that's what you are looking for). If look at the coding of this method you see how to clone object instance in SAP. Unfortunately, I do not yet understand how to use this class (and the corresponding interface; another interesting interface is IF_OS_CLONE) because I do not recommend to use the system-call directly.

I hope I could give you some hints how to solve your problem. And if you fully understand cloning I would appreciate your feedback.

Regards

Uwe

4 REPLIES 4
Read only

athavanraja
Active Contributor
0 Likes
1,671

can you eloborate your question further? what do you mean by complex object?

Regards

Raja

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,672

Hello Tobias

One possibility would be to serialize your object to XML using CALL TRANSFORMATION. In order to use this option the object must implement the interface IF_SERIALIZABLE_OBJECT (which is just a "marker", like in Java).

The other way is to have a look at class CL_OS_STATE. This class has a method CLONE (apparently that's what you are looking for). If look at the coding of this method you see how to clone object instance in SAP. Unfortunately, I do not yet understand how to use this class (and the corresponding interface; another interesting interface is IF_OS_CLONE) because I do not recommend to use the system-call directly.

I hope I could give you some hints how to solve your problem. And if you fully understand cloning I would appreciate your feedback.

Regards

Uwe

Read only

Former Member
1,670

Hey great

that is the solution

Thank you Uwe.

The system call SYSTEM-CALL OBJMGR CLONE xxx TO xxx

does exactly what I'm searching for.

When you want to backup all attributes of an object, you can implement the interface IF_OS_CLONE within your class (no functionality just as marker) with following content:

SYSTEM-CALL OBJMGR CLONE ME TO RESULT.

Then you are able to clone your class:

DATA: go_backup TYPE REF TO z_cl_class.

go_backup ?= go_object->if_os_clone~clone( ).

In this example go_backup contains after cloning the same attribute values as go_object does, but represents an own instance.

Grüsse in das Nachbarland Schweiz.

Tobias

Read only

0 Likes
1,670

Hello Tobias

Thanks for the feedback.

Regards

Uwe

PS: I am a German expatriate...