TIP: Invoking a business object method from another system


Sometimes you want to call a business object method on another system. How do you do that? Here is how…

Use BD97 to link Logical system and RFC

OPTION 1: Instance independent call to specified method.

In the receiving system (my example is SCM) perform the following steps:

  1. SWO1
  2. Enter your Z object type. e.g. ZEH_DISP
  3. Add method. e.g. EHList (Attributes: Dialog, Synchronous, Instance-Independent)
  4. Code: e.g. call transaction ‘/SAPTRX/EH_LIST’.

In the sending system (my example is ECC) perform the following code:

data: w_handle     type swo_objhnd,
it_container type table of swcont.

call function ‘SWO_CREATE’
exporting
objtype           = ‘ZEH_DISP’
logical_system    = ‘SCM’
importing
object            = w_handle
exceptions
no_remote_objects = 1
others            = 2.

if sy-subrc <> 0.
message i001(z1) with ‘No object created!’.
endif.

call function ‘SWO_INVOKE’
exporting
object    = w_handle
verb      = ‘EHList’
tables
container = it_container.

OPTION 2: Instance dependent call to specified method.

In the receiving system (my example is SCM) perform the following steps:

  1. SWO1
  2. Enter your Z object type. e.g. ZEH_DISP
  3. Add method. e.g. DisplayEH (Attributes: Dialog, Synchronous)
  4. Code: e.g.

DATA : w_guid TYPE /saptrx/eh_hdr-eh_guid.

SELECT SINGLE eh_guid
FROM /saptrx/eh_hdr
INTO w_guid
WHERE ao_id = object-key.

CALL FUNCTION ‘/SAPTRX/EH_DETAILS’
EXPORTING
i_guid = w_guid.

In the sending system (my example is ECC) perform the following code:

data: w_handle     type swo_objhnd,
it_container type table of swcont.

call function ‘SWO_CREATE’
exporting
objtype           = ‘ZEH_DISP’
objkey            = lv_key  “Contains BO Key value
logical_system    = ‘SCM’
importing
object            = w_handle
exceptions
no_remote_objects = 1
others            = 2.

if sy-subrc <> 0.
message i001(z1) with ‘No object created!’.
endif.

call function ‘SWO_INVOKE’
exporting
object    = w_handle
verb      = ‘DisplayEH’
tables
container = it_container.

OPTION 3: Instance dependent call to default method.

  1. SWO1
  2. Enter your Z object type. e.g. ZEH_DISP
  3. Add method. e.g. DisplayEH (Attributes: Dialog, Synchronous)
  4. Code: e.g.

DATA : w_guid TYPE /saptrx/eh_hdr-eh_guid.

SELECT SINGLE eh_guid
FROM /saptrx/eh_hdr
INTO w_guid
WHERE ao_id = object-key.

CALL FUNCTION ‘/SAPTRX/EH_DETAILS’
EXPORTING
i_guid = w_guid.

In the sending system (my example is ECC) perform the following code:

data: w_handle     type swo_objhnd,
it_container type table of swcont.

call function ‘SWO_CREATE’
exporting
objtype           = ‘ZEH_DISP’
objkey            = lv_key   “Contains BO Key value
logical_system    = ‘SCM’
importing
object            = w_handle
exceptions
no_remote_objects = 1
others            = 2.

if sy-subrc <> 0.
message i001(z1) with ‘No object created!’.
endif.

call function ‘SWO_INVOKE’
exporting
object    = w_handle
*          verb      = ‘DisplayEH’
tables
container = it_container.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s