Skip to Content
1
Feb 17, 2016 at 09:53 AM

How to send an instant object to another system?

32 Views

Hi All,

Currently I need to send an instant object from one SAP system to another SAP system using RFC.

I have read that one of the approach is by using serializable interface in corresponding class.

One of the simple example has been mentioned by Uwe in this post. I have tested that example, and it is working fine. 😊

However, in my case is a little bit different. The object that I need to send is object of (interface IF_SA_DOC) does not have interface IF_SERIALIZABLE_OBJECT. Therefore, i re-declare a new class (by adjusting the Uwe code) and put instant of IF_SA_DOC into constructor.

Following is the complete code.

---

*----------------------------------------------------------------------*

* CLASS lcl_mysample DEFINITION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

CLASS lcl_mysample DEFINITION.

PUBLIC SECTION.

INTERFACES:

if_serializable_object.

DATA: go_obj TYPE REF TO cl_sa_doc.

METHODS:

constructor

IMPORTING

io_obj TYPE REF TO cl_sa_doc

.

ENDCLASS. "lcl_mysample DEFINITION

*----------------------------------------------------------------------*

* CLASS lcl_mysample IMPLEMENTATION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

CLASS lcl_mysample IMPLEMENTATION.

METHOD constructor.

me->go_obj = io_obj.

ENDMETHOD. "constructor

ENDCLASS. "lcl_mysample IMPLEMENTATION

DATA: go_sample TYPE REF TO lcl_mysample.

CONSTANTS: line_length TYPE i VALUE 4096.

TYPES: line_t(line_length) TYPE x,

table_t TYPE STANDARD TABLE OF line_t.

DATA: restab TYPE table_t.

DATA: lv_xstring TYPE xstring.

DATA: lo_interface TYPE REF TO if_sa_doc.

DATA: gt_xml TYPE STANDARD TABLE OF string,

go_serializable TYPE REF TO if_serializable_object,

go_new TYPE REF TO lcl_mysample.

DATA: lt_context TYPE sdokproptys,

lo_sadoc TYPE REF TO cl_sa_doc,

ls_info_object TYPE sdokobject

.

PARAMETERS:

p_class TYPE sdok_class DEFAULT 'SOLARGEN',

p_objid TYPE sdok_docid DEFAULT 'E41F1367460C1ED496EBB72EB5B6C1C2'

.

START-OF-SELECTION.

ls_info_object-class = p_class.

ls_info_object-objid = p_objid.

CALL FUNCTION 'ZGET_ST_CONTEXT_DATA'

EXPORTING

iv_projectid = 'PROJECT_NAME'

CHANGING

it_context = lt_context.

CALL METHOD cl_sa_doc_factory=>get_doc_from_kw

EXPORTING

i_class = ls_info_object-class

i_objid = ls_info_object-objid

* I_STRUCTID =

* IS_PHYSICAL_OBJECT =

i_with_dialog = space

* I_QUERY_FUNCTION =

i_read_only = 'X'

i_as_copy = space

* I_NEW_FOLDER_WHEN_COPY =

* I_SHOW_TOOLBARS = SPACE

* I_CALLING_OBJECT =

* I_FOLDER_TECHNAME =

* IT_TOOLBAR_BUTTONS =

i_use_external_editor = 'X'

i_bypass_check = 'X'

* IT_TOOLBAR_MENUES =

* IT_IO_ATTR =

it_context = lt_context

* I_PARENT_CONTAINER =

i_with_header = 'X'

* IT_TOOLBAR_BUTTONS_EDIT =

i_open_editor = 'X'

RECEIVING

e_iobject = lo_interface

EXCEPTIONS

cancelled = 1

not_found = 2

error = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

lo_sadoc ?= lo_interface.

* <Object initiate>

CREATE OBJECT go_sample

EXPORTING

io_obj = lo_sadoc.

* go_sample->display_counter( ).

go_serializable ?= go_sample.

* <Transformation...>

CALL TRANSFORMATION id_indent

SOURCE obj = go_sample

RESULT XML restab.

* <Reverting...>

" Perhaps download XML itab to file or store in DB table

" Afterwards read file or record in DB entry again and

" revert TRANSFORMATION

CALL TRANSFORMATION id_indent

SOURCE XML restab

RESULT obj = go_new.

---

The problem is that attribute GO_OBJ of object (GO_NEW) after the reversion <Reverting...> statement will remains empty (initial). Only the GO_NEW is replicated.

Attribute GO_OBJ of object GO_SAMPLE is initiated properly.GO_SAMPLE->GO_OBJ = LO_SADOC. No issue here.

But why the reference of attribute value cannot be copied in the target object?

Do I missed somewhere? 🤪

Thanks,

Dinivian.