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

INTERNAL TABLE TO XML (IDOC)

Former Member
0 Likes
1,278

i have this requirement to fetch data from internal table and dowload this to an xml file.

the xml file has this XML format.

Output Sample (in XML format):

<?xml version="1.0"?>

<ORDERS01>

<IDOC BEGIN="1">

<EDI_DC40 SEGMENT="1">

<TABNAM>EDI_DC40</TABNAM>

<DIRECT>1</DIRECT>

<IDOCTYP>ORDERS01</IDOCTYP>

<MESTYP>ORDERS</MESTYP>

<SNDPOR>SAPEX3</SNDPOR>

<SNDPRT>LS</SNDPRT>

<SNDPRN>0011297603</SNDPRN>

<RCVPOR>SAPP82</RCVPOR>

<RCVPRT>LI</RCVPRT>

<RCVPFC>LF</RCVPFC>

<RCVPRN></RCVPRN>

<CREDAT>2003-09-15</CREDAT>

<CRETIM>12:39:13</CRETIM>

</EDI_DC40>

<E1EDK01>

this format is in IDOC format, is there any function modules of way to download it to this file?

please help. thanks.

i have this requirement to fetch data from internal table and dowload this to an xml file.

the xml file has this XML format.

Output Sample (in XML format):

<?xml version="1.0"?>

<ORDERS01>

<IDOC BEGIN="1">

<EDI_DC40 SEGMENT="1">

<TABNAM>EDI_DC40</TABNAM>

<DIRECT>1</DIRECT>

<IDOCTYP>ORDERS01</IDOCTYP>

<MESTYP>ORDERS</MESTYP>

<SNDPOR>SAPEX3</SNDPOR>

<SNDPRT>LS</SNDPRT>

<SNDPRN>0011297603</SNDPRN>

<RCVPOR>SAPP82</RCVPOR>

<RCVPRT>LI</RCVPRT>

<RCVPFC>LF</RCVPFC>

<RCVPRN></RCVPRN>

<CREDAT>2003-09-15</CREDAT>

<CRETIM>12:39:13</CRETIM>

</EDI_DC40>

<E1EDK01>

this format is in IDOC format, is there any function modules of way to download it to this file?

please help. thanks.

4 REPLIES 4
Read only

Former Member
0 Likes
986

Hi,

Just check if this link might help you.

Link[XML|http://sapprograms.blogspot.com/2008/11/download-to-xml.html]

Regards and Best wishes.

Read only

Former Member
0 Likes
986

thanks.

but i need the xml to have the tags from idocs the <SEGMET> etc.

is there another way?

Read only

0 Likes
986

Hi blue22,

you can solve this by using class cl_xml_document.

1. Get your data in an internal table

2. Create XML Object type cl_xml_document

3. Convert data in table to XML by using method "create_with_data" of cl_xml_document

4. Save XML to local PC by using method "export_to_file" of cl_xml_document

regards

rea

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
986

1. You use the FM: IDX_IDOC_TO_XML to get the idoc data in XML_DATA export param.

2. Now you can use this snippet to download data as an XML file:


DATA:
      v_stream TYPE string,
      lcl_xml_doc TYPE REF TO cl_xml_document,
      v_subrc TYPE sysubrc,
      v_filename TYPE localfile.

CREATE OBJECT lcl_xml_doc.

IF sy-subrc = 0.

" V_STREAM contains the idoc data in XML format which you got 
" from the func. module IDX_IDOC_TO_XML

  v_subrc = lcl_xml_doc->parse_string( stream = v_stream ).

  CHECK v_subrc = 0.

  v_filename = `C:\Users\Suhas Saha\Desktop\xml_data.xml`.

  v_subrc = lcl_xml_doc->export_to_file( filename = v_filename ).

  IF v_subrc = 0.
    WRITE / `File downloaded successfully. Yippee!!!`.
  ELSE.
    WRITE / `Why does not this work ? Sob !!!`.
  ENDIF.

ENDIF.

Hope this helps.

BR,

Suhas