Posted on May. 13, 2010 at 07.09 PM - Kuala Lumpur, Malaysia
Prerequisite
To be able to reference an ABAP mapping program in the ABAP Workbench from an operation mapping, we need to make the appropriate settings in the Integration Server exchange profile. The parameter com.sap.aii.repository.mapping.additionaltypes must be assigned the following value: “com.sap.aii.repository.mapping.additionaltypes=R3_ABAP|ABAP-Class;R3_XSLT|XSL (ABAP Engine)”.
Implementation
We need to create one ABAP class to implement method EXECUTE from interface IF_MAPPING. Below are parameters of the Method EXECUTE:
Example coding for method EXECUTE:
METHOD if_mapping~execute.
* initialize iXML
TYPE-POOLS: ixml.
CLASS cl_ixml DEFINITION LOAD.
* create main factory
DATA: ixmlfactory TYPE REF TO if_ixml.
ixmlfactory = cl_ixml=>create( ).
* create stream factory
DATA: streamfactory TYPE REF TO if_ixml_stream_factory.
streamfactory = ixmlfactory->create_stream_factory( ).
* create input stream
DATA: istream TYPE REF TO if_ixml_istream.
istream = streamfactory->create_istream_xstring( source ).
***************************************************************************
* parse input document
* initialize input document
DATA: idocument TYPE REF TO if_ixml_document.
idocument = ixmlfactory->create_document( ).
* parse input document
DATA: iparser TYPE REF TO if_ixml_parser.
iparser = ixmlfactory->create_parser( stream_factory = streamfactory
istream = istream
document = idocument ).
DATA: rc LIKE sy-subrc.
rc = iparser->parse( ).
* select subnode surname
DATA: pnode TYPE REF TO if_ixml_node,
pnode2 TYPE REF TO if_ixml_node.
pnode = idocument.
pnode2 = pnode->get_first_child( ).
pnode2 = pnode2->get_first_child( ).
* get message content of tag <Surname>
DATA: insurnamestr TYPE c LENGTH 30.
insurnamestr = pnode2->get_value( ).
* get message content of tag <Name>
DATA: innamestr TYPE c LENGTH 30.
pnode2 = pnode->get_first_child( ).
pnode2 = pnode2->get_last_child( ).
innamestr = pnode2->get_value( ).
* create target field
DATA: l_name TYPE string.
CONCATENATE innamestr insurnamestr INTO l_name SEPARATED BY space.
* define trace message
trace->trace( level = '3'
message = 'This is a trace message' ).
***************************************************************************
* build up output document
* create output document
DATA: odocument TYPE REF TO if_ixml_document.
odocument = ixmlfactory->create_document( ).
* add node to the output document
DATA: msgtype TYPE REF TO if_ixml_element.
msgtype = odocument->create_simple_element( name = 'MtName'
namespace = 'ns'
value = l_name
parent = odocument ).
rc = msgtype->set_attribute( name = 'xmlns:ns'
value = 'urn:education.com:BIT460:mapping' ).
* create output stream
DATA: ostream TYPE REF TO if_ixml_ostream.
ostream = streamfactory->create_ostream_xstring( result ).
* create renderer
DATA: renderer TYPE REF TO if_ixml_renderer.
renderer = ixmlfactory->create_renderer( ostream = ostream
document = odocument ).
rc = renderer->render( ).
ENDMETHOD.
Example ABAP to get the runtime constant
* Accessing runtime constant
data: l_sender_service type string.
l_sender_service = param->get( if_mapping_param=>sender_service ).
Don't forget to make use of the ABAP mapping in the operation mapping and refer to this operation mapping in the interface determination
Life is beautiful! Let's make it meaningful and colorful!