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

SAVE an Instance to Database?

swen_hettstedt2
Explorer
0 Likes
1,526

Hy Guru's,

is there a way to save an instance to database?

Thanks for reply!

1 ACCEPTED SOLUTION
Read only

ThomasZloch
Active Contributor
0 Likes
1,067

Please explain a bit more about what you're trying to do and why.

Thomas

7 REPLIES 7
Read only

ThomasZloch
Active Contributor
0 Likes
1,068

Please explain a bit more about what you're trying to do and why.

Thomas

Read only

0 Likes
1,067

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

Read only

0 Likes
1,067

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

Read only

Clemenss
Active Contributor
0 Likes
1,067

Hi Swen,

Answer from radio Eriwan: Basically, yes.Search for persistent objects

Regards

Clemens

Read only

0 Likes
1,067

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

Read only

swen_hettstedt2
Explorer
0 Likes
1,067

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

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,067

Hello Swen,

Really appreciate your feedback. Wish other OPs will take a hint from it

Cheers,

Suhas