02-16-2022 12:15 PM
Hey there!
I use the interface IF_OS_CLONE and this system call to clone object references:
"Returning VALUE(result) TYPE REF TO object
SYSTEM-CALL OBJMGR CLONE me TO result.
Code inspector tells me to use a kernel method instead:
If this is true, what could the kernel method be?
thanks
Enno
02-16-2022 1:07 PM
What is it for? What is the exact use case? The only official way to clone I know is IF_SERIALIZABLE_OBJECT, i.e. the class must allow it, you shouldn't be allowed otherwise.
02-16-2022 2:28 PM
Hey sandra.rossi The use case is that I have a data object and I clone it to compare data after editing the original object.
What do you mean by IF_SERIALIZABLE_OBJECT? what is the procedure? serialize original object, create a new object and deserialize? like this:
CLASS test DEFINITION.
PUBLIC SECTION.
INTERFACES if_serializable_object.
DATA one TYPE string.
DATA two TYPE string.
ENDCLASS.
START-OF-SELECTION.
data(obj) = new test( ).
obj->one = 'AAAA'.
obj->two = 'BBBBB'.
CALL TRANSFORMATION id
SOURCE model = obj
RESULT XML data(ser).
data(new) = new test( ).
CALL TRANSFORMATION id
SOURCE XML ser
RESULT model = new.
how do you know this is the "official" way?
02-16-2022 6:22 PM
IF_SERIALIZABLE_OBJECT is in the ABAP documentation, so it's official.
Of course, it's stupid to use it just to know if the object has been changed.
If you have a Z class, you may handle the changes the hard way.
If I'm not wrong, persistence classes have an event CHANGED, but you need to rewrite your Z class.
I don't know anything else...
02-17-2022 9:04 AM
sandra.rossi of course the serializable interface is officially documented. but not for the official purpose of cloning objects.
I didn't say I use the copied reference to see _if_ something has changed, but rather to identify the real changes (-> change documents). So I wouldn't call this stupid.
Nevertheless your hint using serialization is a good one. I'll keep in mind for next use of cloning objects.
Thanks!