‎2011 Aug 19 2:37 PM
Hy Guru's,
is there a way to save an instance to database?
Thanks for reply!
‎2011 Aug 19 3:11 PM
Please explain a bit more about what you're trying to do and why.
Thomas
‎2011 Aug 19 3:11 PM
Please explain a bit more about what you're trying to do and why.
Thomas
‎2011 Aug 19 4:02 PM
Hallo Thomas,
The first step:
We move the process-data to an instance and save an ID to the process and lost the instance.
At this point i want save all process-data and all instances to database.
The second step.
This step needs the informations from the previous step.
I have an reference to the first step.
And now i want to read all information from the first step into new instance and structures.
There isn't a time-connection between the step's.
I hope the description is enough.
Thanks, Swen
‎2011 Aug 19 5:20 PM
Hi,
we still don't have the context, so we're only able to answer directly your question, but I understand that you are talking about a class instance (ABAP objects) : you may serialize your instance to XML, and save it, and reload it later to deserialize it to the instance again. For that, you need to add the interface IF_SERIALIZABLE_OBJECT to the class. And that's all.
Sandra
‎2011 Aug 19 11:47 PM
Hi Swen,
Answer from radio Eriwan: Basically, yes.Search for persistent objects
Regards
Clemens
‎2011 Aug 21 5:19 AM
Actually serializable and persistent objects are different things, but Thomas covers both in [this blog|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/1013] [original link is broken] [original link is broken] [original link is broken];.
Cheers
Graham Robbo
‎2011 Aug 22 8:54 PM
Hy together,
thanks for answers. the hints were very helpful
here is a little testreport.
*&---------------------------------------------------------------------*
*& Report ZABAP_OO_SERIALIZE_01
*&---------------------------------------------------------------------*
REPORT zabap_oo_serialize_01.
CLASS a DEFINITION DEFERRED.
DATA:
a TYPE REF TO a,
a_new TYPE REF TO a,
serializable_object TYPE REF TO if_serializable_object,
serializable_objects LIKE TABLE OF serializable_object
.
DATA: ls_serial TYPE zabap_serialize.
DATA: lt_serial TYPE TABLE OF zabap_serialize.
*----------------------------------------------------------------------*
* INTERFACE if_display_id
*----------------------------------------------------------------------*
INTERFACE if_display_id.
METHODS:
display_id.
ENDINTERFACE. "if_display_id
*----------------------------------------------------------------------*
* CLASS a DEFINITION
*----------------------------------------------------------------------*
CLASS a DEFINITION.
PUBLIC SECTION.
DATA: mt_sflight TYPE TABLE OF sflight.
INTERFACES if_serializable_object.
INTERFACES if_display_id.
METHODS: constructor
IMPORTING
i_id TYPE numc2.
PRIVATE SECTION.
DATA: m_id TYPE numc2.
ENDCLASS. "a DEFINITION
*----------------------------------------------------------------------*
* CLASS a IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS a IMPLEMENTATION.
METHOD constructor.
me->m_id = i_id.
ENDMETHOD. "constructor
METHOD if_display_id~display_id.
WRITE: 'ID:', me->m_id.
ULINE.
ENDMETHOD. "display_id
ENDCLASS. "a IMPLEMENTATION
START-OF-SELECTION.
CLEAR: lt_serial[].
CREATE OBJECT a
EXPORTING
i_id = 81.
APPEND: a TO serializable_objects.
SELECT * FROM sflight INTO TABLE a->mt_sflight.
CLEAR: ls_serial.
CALL TRANSFORMATION id_indent
SOURCE obj = a
RESULT XML ls_serial-xml.
CALL FUNCTION 'GUID_CREATE'
IMPORTING
ev_guid_22 = ls_serial-guid.
APPEND ls_serial TO lt_serial.
IF lt_serial[] IS NOT INITIAL.
TRY .
INSERT zabap_serialize FROM TABLE lt_serial.
CATCH cx_sy_open_sql_db.
WRITE: 'INSERT-Error!'.
STOP.
ENDTRY.
ENDIF.
CLEAR: lt_serial[].
SELECT * FROM zabap_serialize INTO TABLE lt_serial.
LOOP AT lt_serial INTO ls_serial.
CALL TRANSFORMATION id_indent
SOURCE XML ls_serial-xml
RESULT obj = a_new.
TRY .
CALL METHOD a_new->if_display_id~display_id.
CATCH cx_sy_ref_is_initial.
WRITE: 'A-NEW-Error!'.
STOP.
ENDTRY.
CLEAR: a_new.
ENDLOOP.<Added Code tags>
Edited by: Suhas Saha on Aug 23, 2011 2:49 PM
‎2011 Aug 23 10:20 AM
Hello Swen,
Really appreciate your feedback. Wish other OPs will take a hint from it
Cheers,
Suhas