h2. Introduction
The aim of this weblog is to show how to call an Abap
mapping in SAP XI through a RFC Call using the functionalities of JCO.
Why should one ever need this? I don't know, but the the need was born
during the development and testing phase of the unit test tool for XI
mapping called Detroubulator: Call for beta testers.
With the collaboration of http://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/u/10354 [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] we've implemented this new feature (which was "On
The Horizon" in Detroubulator readme file). For depth info go to
the detroubulator home
page.
You can find here an interesting Detroubulator A Complete Walkthrough
h2. Requirements
- SAP JCo libraries installed on your system. Can be dowloaded
here.
FUNCTION zxi_dtrb_abap_mapping_execute.
*"----
""Local Interface:
*" IMPORTING
*" VALUE(MAPPING) TYPE SEOCLSNAME
*" VALUE(PARAMS) TYPE MPP_PARAM_TAB OPTIONAL
*" VALUE(SOURCE) TYPE XSTRING OPTIONAL
*" VALUE(SOURCE_STR) TYPE STRING OPTIONAL
*" EXPORTING
*" VALUE(RESULT) TYPE XSTRING
*" VALUE(RESULT_STR) TYPE STRING
*" VALUE(RETURN) TYPE BAPIRET2
*"----
DATA: li_mapping TYPE REF TO if_mapping,
li_param TYPE REF TO cl_mapping_param,
li_trace TYPE REF TO cl_mapping_trace,
lv_src TYPE xstring,
lx_root TYPE REF TO cx_root,
lv_pname TYPE syrepid,
lv_iname TYPE syrepid,
lv_srcli TYPE i,
ls_param TYPE LINE OF mpp_param_tab.
CREATE OBJECT li_param
EXPORTING
params = params.
IF source_str IS SUPPLIED.
CALL FUNCTION 'ECATT_CONV_STRING_TO_XSTRING'
EXPORTING
im_string = source_str
im_encoding = 'UTF-8'
IMPORTING
ex_xstring = lv_src.
ELSE.
lv_src = source.
ENDIF.
CREATE OBJECT li_mapping TYPE (mapping).
TRY.
CALL METHOD li_mapping->execute
EXPORTING
SOURCE = lv_src
param = li_param
trace = li_trace
IMPORTING
RESULT = RESULT.
CATCH cx_root INTO lx_root.
return-type = 'E'.
return-message = lx_root->if_message~get_text( ).
return-message_v1 = lx_root->cx_root.
CALL METHOD lx_root->get_source_position
IMPORTING
program_name = lv_pname
include_name = lv_iname
source_line = lv_srcli.
return-message_v2 = lv_pname.
return-message_v3 = lv_iname.
return-message_v4 = lv_srcli.
EXIT.
ENDTRY.
IF source_str IS SUPPLIED.
CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
EXPORTING
im_xstring = result
im_encoding = 'UTF-8'
IMPORTING
ex_string = result_str.
ENDIF.
ENDFUNCTION.
</textarea>