Flexible conversion of Internal Table values to XML format

By Sakthi Saravanan, HCL AXON

Applies to:

SAP ECC 6.0  


This article is about flexible conversion of internal table values into XML format.  

Getting Started  


This 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.  

The key things which we need to know for this flexible conversion process are listed below:

  • Creation of new Z table and view for mapping
  • Maintaining 'Table Maintenance Generator' for the same Z table and view
  • Usage of SM30 Transaction code  

Step-By-Step Process  

Step 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:  

  1. Go to Transaction Code: SE38  
  1. Create a sample report with an internal table as shown below:  
REPORT  yreport2.
TABLES: pa0001.
SELECT-OPTIONS: s_pernr FOR pa0001-pernr.
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.
  SELECT pernr begda endda FROM pa0001
    INTO TABLE lt_itab
      WHERE pernr IN s_pernr. 

Step 2: Internal table conversion to XML  

1.     In the event 'END-OF-SELECTION' the CALL TRANSFORMATION statement is used to convert internal table values into XML format (String value).  


Here '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.  

Step 3: Customized XML mapping  

2.     The customized XML mapping will be done by using a custom Z table (ZMAP_XML) which is maintained using Table maintenance generator.  

3.     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 field.  

4.     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.  


6.     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.  

7.     All the required XML Fields which are in CAPS will be modified into customized XML fields as per the requirement.

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image