Skip to Content

Here by I am mentioning a sample report program to download the internal table data into XML file.

For converting  the internal table data into XML. We do the following steps

1. Create a table type at dictionary level for final internal table in our report program and XML Conversion program.

2. Create internal table referring that dictionary data type.

3. Fetch and fill the data into internal table.

4. In XML Transformation (XSLT_TOOL) add that table type as root node and activate the transformation.

5. Call that Transformation in our report program and give our internal table as input for that and we will get the XML data as output.

6. Use Function module, SCOL_TRACE_SHOW_XML to display the XML on list output.

7. Use Method , CL_SALV_DATA_SERVICES=>DOWNLOAD_XML_TO_FILE to download the converted XML file as file.

Below is the Screenshot driven flow.

1. OPEN Tcode XSLT_TOOL . Give the name and click on create.

  Select Simple transformation and click on Save.

1.JPG

2. Click on Edit simple transformation graphically.

2.JPG

3. Right Click on Root and select INSERT ROOT NODE. And give a name to root and give the dictionary table type as below.

and drag the newly created root node from left window to right window (simple transformation).

Activate it and exit from it.

3.JPG

4.JPG

5.JPG

4. Open ABAP Editor and do the following Code to get the data transformed into XML.

*&———————————————————————*

*& Report  ZR_C101_XML_TEST1

*&

*&———————————————————————*

*&    Report program to dispaly & Download the Internal table data into

*& XML file.

*&

*&———————————————————————*

REPORT  ZR_C101_XML_TEST1.

** Declaration of Internaltable referring to abap dictionary structure.

DATA: IT_MARD TYPE ZTT_MARD WITH HEADER LINE.

** Select options for Material number.

SELECT-OPTIONS S_MATNR FOR IT_MARD-MATNR.

**Select the file path to download the XML file.

PARAMETERS P_FILE TYPE STRING.

DATA PRAVEEN_XML TYPE XSTRING.

** F4 funtionality for file name field.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

  CALL METHOD CL_RSAN_UT_FILES=>F4

    EXPORTING

      I_APPLSERV       = SPACE

      I_TITLE          = ‘SAVE TO XML’

      I_GUI_EXTENSION  = ‘XML’

      I_GUI_EXT_FILTER = ‘XML’

    CHANGING

      C_FILE_NAME      = P_FILE

    EXCEPTIONS

      FAILED           = 1

      OTHERS           = 2.

  IF SY-SUBRC <> 0.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

START-OF-SELECTION.

** Fetch the data from database to internal table.

  SELECT MATNR

         WERKS

         LGORT

         LFGJA INTO TABLE IT_MARD

               FROM MARD

               WHERE MATNR IN S_MATNR.

******************************************************************************************

** Call the transformation Program name which we created in TCODE XSLT_TOOL.

  CALL TRANSFORMATION ZTR_C101_3

  SOURCE ZROOT = IT_MARD[]

  RESULT XML PRAVEEN_XML.

******************************************************************************************

** Call function for displaying the XML file on to list output.

  CALL FUNCTION ‘SCOL_TRACE_SHOW_XML’

    EXPORTING

      XDOC = PRAVEEN_XML.

******************************************************************

**************************************************************

* Call the Method to download the XML data as File on the file system.

  CALL METHOD CL_SALV_DATA_SERVICES=>DOWNLOAD_XML_TO_FILE

    EXPORTING

      FILENAME = P_FILE

      XCONTENT = PRAVEEN_XML.

**************************************************************

And in the final the output as below.

6.JPG

Thanks & Regards,

Mayure.

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. vamsilakshman pendurti

    Hi Its very useful Document.

    I need another requirement like as below…

    I want to send the mail directly to some one with out display the data as an output .

    How could we do that…

    Just give me one example to send XML  file through mail

    Thanks,

    vamsi.

    (0) 

Leave a Reply