Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to generate xml table from internal table data

Former Member
0 Likes
2,471

Hi All,

I have an internal table with data from different tables.I would like to generate an xml file from the internal table.Please let me know if there is any fm or report for this

Thanks

Bala Duvvuri

15 REPLIES 15
Read only

Former Member
0 Likes
2,249

Hi,

Check "simple transformations" .

http://help.sap.com/abapdocu_70/en/ABENABAP_ST.htm.

or

SE80->Workbench _>edit object->more->transofrmation radio button enter 'Name' and click view.

CALL TRANSFORMATION ('Name')

SOURCE tab = ITAB[]

RESULT XML xml_out.

Here XML_OUT stores the converted data in XML format.

After that depends on your requirement. You can store in custom table or in the application server (unix directory) or download to front end.

Thanks!

Read only

0 Likes
2,249

Boby,

I checked the link and it has used CL_ABAP_BROWSER to display xml but i dont find that class.Please clarify

Thanks

Bala Duvvuri

Read only

0 Likes
2,249

That's only to display the resulting XML from the example. You can render the XML using ST or XSLT in the transformation as he said or you can use one of the other XML functions or classes available. Read the rest of the help files regarding transformations.

Read only

0 Likes
2,249

I followed this link

http://sapblog.rmtiwari.com/2009/04/generate-simple-transformation-for-xml.html

and created xsd and report and it created xml file but when i tried to open it ,it shows the following error in browser

As mentioned in the link i executed tcode SSTDEMO1 to download a sample xml file ,but when i tried to open it i am getting the same error

The XML page cannot be displayed

Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

-


Invalid at the top level of the document. Error processing resource 'file:///C:/Download/xmlfile.xml'. Line 1, Position 124

As mentioned in the link i executed tcode SSTDEMO1 to download a sample xml file ,but when i tried to open it i am getting the same error

Please let me know how i can solve this

Thanks

Bala Duvvuri

Read only

0 Likes
2,249

This means that the xml is malformed.

Try adding -

OPTIONS addition to the CALL TRANSFORMATION statement to avoid header .

Syntax :

CALL TRANSFORMATION (`ID`) OPTIONS XML_HEADER = 'no'

SOURCE itab = itab[]

RESULT XML output.

Read only

0 Likes
2,249

Boby,

I am already using that but still i get the problem

Thanks

Bala Duvvuri

Read only

0 Likes
2,249

BALA,

I checked it ,

call function 'GUI_DOWNLOAD'

exporting filename = s

filetype = 'ASC'

write_lf = ' '

tables data_tab = xmltab_res

While downloading a special character is there in the xmltab_res internal table record-

0<flights/>

Please remove it while debugging and execute .

You will not encounter the error,

Thanks!

Read only

0 Likes
2,249

Boby,

thanks for the answer but how will i remove that special character in the program

Thanks

Bala Duvvuri

Edited by: Bala Duvvuri on Jun 20, 2010 7:21 PM

Read only

0 Likes
2,249

Set up the correct encoding while downloading with 'GUI_DOWNLOAD".

You will have code page option in the import parameters

DATA: encode TYPE ABAP_ENCODING.

encode = '4103'. "'4103' - UTF-16 LE(Little Endian)

PAss

code page = encode

Read only

0 Likes
2,249

Boby,

Still it is not working.

when i open the xml using notepad it has some two special characters ,if i remove them it is working fine from browser and these characters are created only when i use the code page parameter

this is the code i am writing


*&---------------------------------------------------------------------*
*& Report  ZDEMOXML
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZDEMOXML.
CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.

data xml_xstring        TYPE XSTRING.
data lt_tab type ZNEWDATASET.
data ls_tab type ZNEWSTRUCTURE.
ls_tab-name = 'sdsd'.
append ls_tab to lt_tab.
ls_tab-name = 'sdsd'.
append ls_tab to lt_tab.
*
 CALL TRANSFORMATION ZDUMMY
                        SOURCE NEWDATASET = lt_tab
                        RESULT XML xml_xstring
                        OPTIONS xml_header = 'NO'.
 data : l_tab      type tsfixml.
 data lv_file_length type i.
 call function 'SCMS_XSTRING_TO_BINARY'
    exporting
      buffer        = xml_xstring
    importing
      output_length = lv_file_length
    tables
      binary_tab    = l_tab.

* CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
*   EXPORTING
*     input_length       = lv_file_length
*
*  IMPORTING
*    BUFFER             =  xml_xstring
*   tables
*     binary_tab         = l_tab
*           .
* IF sy-subrc <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
**         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
* ENDIF.

  DATA: encode TYPE ABAP_ENCODING.
encode = '4103'. "'4103' - UTF-16 LE(Little Endian)
CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
*   BIN_FILESIZE                    =
    filename                        = 'C:\Temp\xls.xml'
   FILETYPE                        = 'ASC'
   CODEPAGE                        = encode
  tables
    data_tab                        = l_tab

          .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'SCOL_TRACE_SHOW_XML'
  EXPORTING
    xdoc = xml_xstring.
**
*
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
demo=>main( ).

Thanks

Bala Duvvuri

Edited by: Bala Duvvuri on Jun 21, 2010 12:51 AM

Edited by: Bala Duvvuri on Jun 21, 2010 11:06 PM

Read only

0 Likes
2,249

Try downloading it in Binary format using 'BIN' in GUI_DOWNLOAD.

Read only

0 Likes
2,249

I tried but still it is not working

Thanks

Bala Duvvuri

Read only

0 Likes
2,249

Could you please post your XML Transformation code as well.....Is it a Simple/XSLT Transformation?

Read only

0 Likes
2,249

Satyajit,

I followed this link and create simple transformation

http://sapblog.rmtiwari.com/2009/04/generate-simple-transformation-for-xml.html

Thanks

Bala Duvvuri

Read only

former_member907073
Participant
0 Likes
2,249

Hi,

Hope Use of SAP_CONVERT_TO_XML_FORMAT helps.

regd,

abhee

Edited by: abheesawant on Jun 19, 2010 8:29 AM