You are on page 1of 4

8/19/2014 Exchange Infrastructure - Understanding and working with ABAP Mapping

http://saptechnical.com/Tutorials/XI/ABAPMapping/page3.htm 1/4
Search
Home Trai ni ngs Qui z Ti ps Tutori al s Functi onal Cert Q's I ntervi ew Q's Jobs Testi moni al s Adverti se Contact Us
Corporate Trainings
Document Categories:
ABAP
TM
Adobe Forms
ABAP-HR
ALE & IDocs
ALV
BAPI
BASIS
BSP
Business Objects
Business Workflow
CRM NEW
LSMW
SAP Script/Smart Forms
BI/BW
eXchange Infrastructure (XI)
Enterprise Portals (EP)
eCATT
Object Oriented Programming
SAP Query
Userexits/BADIs
WebDynpro for Java/ABAP
TM
Others
What's New?
Inserting data from Internal
Table into the step Send Mail
Display GL Account long text
using enhancement
framework
Differences between
polymorphism in JAVA and
ABAP
Passing multiline parameters
from an ABAP Class event to a
Workflow container
Concept of Re-evaluate agents
for active work items in SAP
Workflow
Dynamic creation of
component usage in ABAP
WebDynpro
Adobe Forms: Display symbols
like copyright and others
Deactivate Hold functionality in
Purchase order (ME21N)
Quiz on OOABAP
Add fields in FBL5N using
BADIs
Tutorial on Wide casting
Defining a Range in Module
Pool Program
Copy fields from one
structure/table into another
structure/table
Side Panel Usage in NWBC
Introduction to SAP Event
Management
Display Statistical Report using
Function Module
Adding Explicit Enhancement
to custom program
Display data dynamically using
Field Symbols
SAP BODS - Beginners guide
Display text vertically (Rotate
text) in Adobe Form
Sending email with multiple
tabs of excel as a single
attachment
Copying Sales Order
attachments to the invoice
Contribute?
Sample Specs
What's Hot?
Web Dynpro for ABAP Tutorials
Understanding and working with ABAP Mapping
...Previous
ABAP Class Code
Here is the ABAP Mapping Class Code i.e. developed for reference:
**********************************************************************
method IF_MAPPING~EXECUTE.
data:
emp_node_collection type ref to if_ixml_node_collection,
emp_node_length type i,
emp_node_iterator type ref to if_ixml_node_iterator,
emp_node type ref to if_ixml_node,
emp_node_list type ref to if_ixml_node_list,
emp_node_list_length type i,
emp_node_list_iterator type ref to if_ixml_node_iterator,
emp_subnode type ref to if_ixml_node,
emp_subnode_list type ref to if_ixml_node_list,
emp_subnode_list_length type i,
emp_subnode_name type string,
w_node_name type string,
w_node_value type string,
w_fieldname type string,
w_tablename type string,
w_index type i,
w_node type ref to if_ixml_node.
data:
odocument type ref to if_ixml_document,
fs_output type string,
employee_node type ref to if_ixml_node,
personal_node type ref to if_ixml_node,
job_node type ref to if_ixml_node,
rnode type ref to if_ixml_node.
data:
begin of fs_job,
empid type string,
company type string,
department type string,
designation type string,
begindate type string,
enddate type string,
salary type string,
end of fs_job,
begin of fs_personal,
empid type string,
firstname type string,
middlename type string,
lastname type string,
age type i,
gender type string,
end of fs_personal,
t_personal like standard table of fs_personal,
t_job like standard table of fs_job.
field-symbols:
<fs> type any,
<fs_table> type table.
* Initialize iXML
type-pools ixml.
class cl_ixml definition load.
* create main factory
data: ixml_factory type ref to if_ixml.

Satellite street maps
onlinemapfinder.com
Search Maps, Get Driving Directions Instantly with
Free App!
Simplify your Backup
Small Businesses Can Win
Performance Management
Training
Materials
corporatetrainingma
Customizable training
materials to teach soft
skills workshops.
Cover
Funeral
Costs
WPF
WebBrowser
Control
Promote
Your Website
Dividend
Stocks To
Buy
Free
Workflow
Software
bonitasoft.com/work
Open Source Forms
Driven Workflow
Download and Improve
Processes Now
Careers In
Management
Best Cash
ISAS
9 Best
Stocks to
Own Now
Easy .NET
Reporting
Tool
8/19/2014 Exchange Infrastructure - Understanding and working with ABAP Mapping
http://saptechnical.com/Tutorials/XI/ABAPMapping/page3.htm 2/4
Join the Mailing List
Enter name and email address below:
Name:
Email:
Subscribe Unsubscribe
GO
ixml_factory = cl_ixml=>create( ).
* create stream factory
data: stream_factory type ref to if_ixml_stream_factory.
stream_factory = ixml_factory->create_stream_factory( ).
* create input stream
data: istream type ref to if_ixml_istream.
istream = stream_factory->create_istream_xstring( source ).
* create input document
data : idocument type ref to if_ixml_document.
* initialize parser
idocument = ixml_factory->create_document( ).
* Parse the input document
data iparser type ref to if_ixml_parser.
iparser = ixml_factory->create_parser( stream_factory = stream_factory
istream = istream
document = idocument ).
* Implements the DOM generating interface to the parser
iparser->parse( ).
emp_node_collection = idocument->get_elements_by_tag_name_ns( name = 'EMPLOYEE' ).
emp_node_length = emp_node_collection->get_length( ).
emp_node_iterator = emp_node_collection->create_iterator( ).
DO emp_node_length times.
emp_node = emp_node_iterator->get_next( ).
emp_node_list = emp_node->get_children( ).
emp_node_list_length = emp_node_list->get_length( ).
emp_node_list_iterator = emp_node_list->create_iterator( ).
DO emp_node_list_length TIMES.
emp_subnode = emp_node_list_iterator->get_next( ).
emp_subnode_name = emp_subnode->get_name( ).
emp_subnode_list = emp_subnode->get_children( ).
emp_subnode_list_length = emp_subnode_list->get_length( ).
DO emp_subnode_list_length TIMES.
w_index = sy-index - 1.
w_node = emp_subnode_list->get_item( w_index ).
w_node_name = w_node->get_name( ).
w_node_value = w_node->get_value( ).
concatenate 'fs_' emp_subnode_name '-' w_node_name
into w_fieldname.
assign (w_fieldname) to <fs>.
if sy-subrc eq 0.
move w_node_value to <fs>.
endif.
ENDDO.
concatenate 'fs_' emp_subnode_name into w_fieldname.
assign (w_fieldname) to <fs>.
check sy-subrc eq 0.
concatenate 't_' emp_subnode_name into w_tablename.
assign (w_tablename) to <fs_table>.
if sy-subrc eq 0.
move fs_personal-empid to fs_job-empid.
append <fs> to <fs_table>.
endif.
ENDDO.
ENDDO.
odocument = ixml_factory->create_document( ).
CALL METHOD ODOCUMENT->CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'EMPLOYEES'
PARENT = ODOCUMENT
* PREFIX = ''
* URI = ''
* VALUE = ''
RECEIVING
RVAL = EMPLOYEE_NODE
.
loop at t_personal into fs_personal.
clear fs_output.
CALL METHOD ODOCUMENT->CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'PERSONAL'
PARENT = EMPLOYEE_NODE
* PREFIX = ''
* URI = ''
VALUE = fs_output
RECEIVING
RVAL = PERSONAL_NODE
.
concatenate fs_personal-firstname
fs_personal-middlename
fs_personal-lastname
into fs_output.
CALL METHOD ODOCUMENT->CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'FULLNAME'
PARENT = personal_node
8/19/2014 Exchange Infrastructure - Understanding and working with ABAP Mapping
http://saptechnical.com/Tutorials/XI/ABAPMapping/page3.htm 3/4
* PREFIX = ''
* URI = ''
VALUE = fs_output
RECEIVING
RVAL = RNODE
.
move fs_personal-age to fs_output.
CALL METHOD ODOCUMENT->CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'AGE'
PARENT = personal_node
* PREFIX = ''
* URI = ''
VALUE = fs_output
RECEIVING
RVAL = RNODE
.
CALL METHOD ODOCUMENT->CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'GENDER'
PARENT = personal_node
* PREFIX = ''
* URI = ''
VALUE = fs_personal-gender
RECEIVING
RVAL = RNODE.
loop at t_job into fs_job where empid = fs_personal-empid.
AT NEW EMPID.
CALL METHOD ODOCUMENT->CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'JOB'
PARENT = EMPLOYEE_NODE
* PREFIX = ''
* URI = ''
* VALUE = ''
RECEIVING
RVAL = JOB_NODE.
ENDAT.
concatenate fs_job-company
fs_job-department
fs_job-designation
fs_job-begindate
fs_job-enddate
fs_job-salary
into fs_output
separated by '*'.
CALL METHOD ODOCUMENT->CREATE_SIMPLE_ELEMENT_NS
EXPORTING
NAME = 'COMPANYDATA'
PARENT = JOB_NODE
* PREFIX = ''
* URI = ''
VALUE = fs_output
RECEIVING
RVAL = RNODE.
endloop.
endloop.
* create output stream
data ostream type ref to if_ixml_ostream.
ostream = stream_factory->create_ostream_xstring( result ).
* create renderer
data renderer type ref to if_ixml_renderer.
renderer = ixml_factory->create_renderer( ostream = ostream
document = odocument ).
* implements DOM based interface to the renderer.
renderer->render( ).
endmethod.
Testing of ABAP Mapping Class
The above-created Mapping program could be tested by using the transaction XI_MAPPING_TEST.
This transaction requires the Sender details i.e. Sender Service/Party Name, Sender Interface
Namespace, Sender Interface; the Receiver details i.e. Receiver Service/Party Name, Receiver
Interface Namespace, Receiver Interface And Input XML source file.
Source Input XML File:
Source Input XML File:
<?xml version="1.0" encoding="UTF-8" ?>
- <ns0:MT_Emp_Det xmlns:ns0="http://yash.com/YH203/file2file_abapmapping">
- <EMPLOYEE>
- <PERSONAL>
<EMPID>001</EMPID>
<FIRSTNAME>Santosh</FIRSTNAME>
<MIDDLENAME>Kumar</MIDDLENAME>
<LASTNAME>K</LASTNAME>
<AGE>25</AGE>
<GENDER>M</GENDER>
</PERSONAL>
- <JOB>
<COMPANY>XYZ</COMPANY>
<DEPARTMENT>SAP</DEPARTMENT>
<DESIGNATION>Consultant</DESIGNATION>
<BEGINDATE>20050606</BEGINDATE>
<ENDDATE />
<SALARY>600000</SALARY>
</JOB>
- <PERSONAL>
<EMPID>002</EMPID>
8/19/2014 Exchange Infrastructure - Understanding and working with ABAP Mapping
http://saptechnical.com/Tutorials/XI/ABAPMapping/page3.htm 4/4
<FIRSTNAME>Bala</FIRSTNAME>
<MIDDLENAME>Krishna</MIDDLENAME>
<LASTNAME>Reddy</LASTNAME>
<AGE>25</AGE>
<GENDER>M</GENDER>
</PERSONAL>
- <JOB>
<COMPANY>XYZ</COMPANY>
<DEPARTMENT>SAP</DEPARTMENT>
<DESIGNATION>Consultant</DESIGNATION>
<BEGINDATE>20050606</BEGINDATE>
<ENDDATE>20061206</ENDDATE>
<SALARY>600000</SALARY>
</JOB>
- <JOB>
<COMPANY>XYZ</COMPANY>
<DEPARTMENT>SAP</DEPARTMENT>
<DESIGNATION>Consultant</DESIGNATION>
<BEGINDATE>20070106</BEGINDATE>
<ENDDATE />
<SALARY>800000</SALARY>
</JOB>
</EMPLOYEE>
</ns0:MT_Emp_Det>
Target output XML File generated:
<?xml version="1.0" ?>
- <EMPLOYEES>
- <PERSONAL>
<FULLNAME>SantoshKumarK</FULLNAME>
<AGE>25</AGE>
<GENDER>M</GENDER>
</PERSONAL>
- <JOB>
<COMPANYDATA>XYZ*SAP*Consultant*20050606**600000</COMPANYDATA>
</JOB>
- <PERSONAL>
<FULLNAME>BalaKrishnaReddy</FULLNAME>
<AGE>25</AGE>
<GENDER>M</GENDER>
</PERSONAL>
- <JOB>
<COMPANYDATA>XYZ*SAP*Consultant*20050606*20061206*600000</COMPANYDATA>
<COMPANYDATA>XYZ*SAP*Consultant*20070106**800000</COMPANYDATA>
</JOB>
</EMPLOYEES>

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM
Home Contribute About Us Privacy Terms Of Use Disclaimer Safe Companies: Advertise on SAPTechnical.COM | Post Job Contact Us
2006-2007 SAPTechni cal .COM. Al l ri ghts reserved.
Al l product names are trademarks of thei r respecti ve compani es. SAPTechni cal .COM i s i n no way affi l i ated wi th SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver, and and any other SAP trademarks are regi stered trademarks of SAP AG i n Germany and i n several other countri es.
Every effort i s made to ensure content i ntegri ty. Use i nformati on on thi s si te at your own ri sk.
Graphic Design by Round the Bend Wizards
Simple CRM Software
podio.com/Simple_CRM_Software
Successfully manage leads & deals
Unlimited projects. 5 Users Free!

You might also like