|Home • Trainings • Quiz • Tips • Tutorials • Functional • Cert Q's • Interview Q's • Jobs • Testimonials • Advertise • Contact Us|
Flexible conversion of Internal Table values to XML format
By Sakthi Saravanan, HCL AXON
article is about flexible conversion of internal table values into XML format.
process of converting internal table values into XML format will be used more
flexibly based on the requirement of the business users. This process is very
simple yet powerful for all kinds of XML conversions from internal table fields.
key things which we need to know for this flexible conversion process are listed
1: Sample report with internal table
As like normal reporting, using the transaction code SE38, Create a new Z report with internal table values.
The processes are shown below:
*&-- TABLE DECLARATION --&* TABLES: pa0001.
*&-- SELECT OPTIONS --&* SELECT-OPTIONS: s_pernr FOR pa0001-pernr.
*&-- DATA TYPE DECLARATION --&* TYPES: BEGIN OF ty_itab, pernr TYPE pa0001-pernr, begda TYPE pa0001-begda, endda TYPE pa0001-endda, END OF ty_itab.
DATA : lt_itab TYPE STANDARD TABLE OF ty_itab, wa_itab TYPE ty_itab.
DATA : xml_out TYPE string. DATA : lv_src TYPE string, lv_trg TYPE string.
*&-- START OF SELECTION --&* START-OF-SELECTION.
SELECT pernr begda endda FROM pa0001 INTO TABLE lt_itab WHERE pernr IN s_pernr.
2: Internal table conversion to XML
In the event 'END-OF-SELECTION' the CALL TRANSFORMATION statement is used
to convert internal table values into XML format (String value).
'LT_FINAL' is internal table and XML_OUT is a string which contains XML
converted values of internal table. The declaration of XML_OUT is shown above.
3: Customized XML mapping
The customized XML mapping will be done by using a custom Z table (ZMAP_XML)
which is maintained using Table maintenance generator.
The field values which are listed in XML will always be shown in CAPS. To
get the customized field names on XML file with out CAPS and other customized
XML values, maintain the custom table with two fields Source field and target
In the source field, maintain the XML field which are exactly produced in
XML and in the target field maintain the required XML field which are to be
shown in the XML output. The sample fields which are maintained as shown below:
The first row shown above is actual source field from XML and the second row is custom field value as per the requirement to change the XML field in the output.
5. Using the below code select all the values maintained in the ZMAP_XML table into an internal table. Loop all the records of the internal table by passing the source and target values to the function module WRB_UTIL_STRING_REPLACE by giving the XML_OUT string in changing parameters.
The function module will replace the passed source field value from the
XML_OUT string into target field value which is passed from the internal table.
All the required XML Fields which are in CAPS will be
modified into customized XML fields as per the requirement.
Please send us your feedback/suggestions at webmaster@SAPTechnical.COM
©2006-2007 SAPTechnical.COM. All rights reserved.
product names are trademarks of their respective companies. SAPTechnical.COM
is in no way affiliated with SAP AG.
Graphic Design by Round the Bend Wizards