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

How To Clone Objects?

TimoScharmann
Participant
0 Likes
1,386

Hi folks,

I'd like to know, if there is a way to clone any object in ABAP? Using implemented interface method if_os_clone~clone is nice, but doesn't help me, because it works only for classes that have implemented corresponding interface. For example it doesn't help me to clone objects of class 'TYPE REF TO DATA'.

3 REPLIES 3
Read only

matt
Active Contributor
0 Likes
1,027

TYPE REF TO DATA isn't a class. So I don't understand what you're trying to achieve.

matt

Read only

0 Likes
1,027

You're right, 'TYPE REF TO DATA' isn't a class. Forget this point!

DATA: 
  object1 TYPE REF TO YCLASS,
  object2 TYPE REF TO YCLASS.

CREATE OBJECT object1.
object2 = object1.

In this example object1 and object2 reference to the same instance. But I want to create a copy of object1, so that there are two separate instances of class YCLASS.

Read only

matt
Active Contributor
0 Likes
1,027

Unless the class has the clone interface implemented (or contains a method for the same purpose), there is no general way of cloning an object.

This is a common feature of object oriented languages.