‎2007 Oct 03 7:00 PM
Is it possible to clone an instance of an object object like
cl_salv_tree?
‎2007 Oct 15 6:38 PM
‎2007 Oct 15 9:16 PM
Hello Gregory
The following sample report <b>ZUS_SDN_CLONE_INSTANCE</b> shows how to clone instances.
To me it seems a rather crude way (making a SYSTEM-CALL) but apparently the object you wish to clone has to implement interface IF_OS_CLONE. Perhaps there is a more elegant way available which I am not aware of yet.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_CLONE_INSTANCE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_clone_instance.
*---------------------------------------------------------------------*
* CLASS lcl_foo DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_foo DEFINITION.
PUBLIC SECTION.
INTERFACES:
if_os_clone.
DATA:
md_counter TYPE i,
md_description TYPE as4text.
METHODS:
constructor
IMPORTING
value(id_counter) TYPE i
value(id_text) TYPE as4text.
ENDCLASS. "lcl_foo DEFINITION
*---------------------------------------------------------------------*
* CLASS lcl_foo IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_foo IMPLEMENTATION.
METHOD constructor.
me->md_counter = id_counter.
me->md_description = id_text.
ENDMETHOD. "constructor
METHOD if_os_clone~clone.
************************************************************************
*
* Purpose : Creates a clone of the object.
*
************************************************************************
SYSTEM-CALL OBJMGR CLONE me TO result.
ENDMETHOD. "if_os_clone~clone
ENDCLASS. "lcl_foo IMPLEMENTATION
DATA:
go_foo TYPE REF TO lcl_foo,
go_foo_1 TYPE REF TO lcl_foo,
go_obj TYPE REF TO object,
go_state TYPE REF TO cl_os_state.
START-OF-SELECTION.
CREATE OBJECT go_foo
EXPORTING
id_counter = 1
id_text = 'Description of instance'.
WRITE: / 'GO_FOO:', go_foo->md_counter, go_foo->md_description.
go_obj = go_foo->if_os_clone~clone( ).
go_foo_1 ?= go_obj.
WRITE: / 'Clone :', go_foo_1->md_counter, go_foo_1->md_description.
END-OF-SELECTION.Regards
Uwe