2006 Sep 15 10:22 AM
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
2006 Sep 16 4:02 PM
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
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
2006 Sep 16 8:22 AM
can you eloborate your question further? what do you mean by complex object?
Regards
Raja
2006 Sep 16 4:02 PM
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
2006 Sep 18 3:05 PM
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
2006 Sep 18 3:08 PM
Hello Tobias
Thanks for the feedback.
Regards
Uwe
PS: I am a German expatriate...
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |