Application Development 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: 

Problem In Down loading Data From SAP in XML Format

Former Member
0 Kudos
135

Hi Friends,

I am using SAP 4.6 C.

I am downloading data from SAP in XML format by using following Code.

REPORT ZBPO_PO_DOWNLOAD .

SELECTION-SCREEN BEGIN OF BLOCK selscr WITH FRAME TITLE text-s01.

PARAMETER:p_file TYPE rlgrap-filename MODIF ID fil." Output File Name

SELECTION-SCREEN END OF BLOCK selscr.

DATA: Begin of PURCHASE_ORDER_HEADER_DETAILS occurs 0,

TD_PO_ID LIKE EKKO-EBELN,

TD_COMPANYCD LIKE EKKO-BUKRS,

TD_BUYERID LIKE EKKO-EKGRP,

End of PURCHASE_ORDER_HEADER_DETAILS.

*

  • LOOP AT ITAB.

*

  • WRITE:/ ITAB-EBELN.

*

  • ENDLOOP.

*

  • Data for xml conversion

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

parameters: ds(132) lower case.

DATA: l_dom TYPE REF TO if_ixml_element,

m_document TYPE REF TO if_ixml_document,

g_ixml TYPE REF TO if_ixml,

w_string TYPE xstring,

w_size TYPE i,

w_result TYPE i,

w_line TYPE string,

it_xml TYPE dcxmllines,

s_xml LIKE LINE OF it_xml,

w_rc LIKE sy-subrc.

DATA: xml TYPE dcxmllines.

DATA: rc TYPE sy-subrc,

BEGIN OF xml_tab OCCURS 0,

d LIKE LINE OF xml,

END OF xml_tab.

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

  • Initialization

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

INITIALIZATION.

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

  • At Selection-Screen On Value Request

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

AT SELECTION-SCREEN.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  • Validating file

PERFORM get_local_file_name USING p_file.

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

  • Start-of-selection

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

START-OF-SELECTION.

  • Populate the internal table

PERFORM populate_data.

  • Create xml file

PERFORM create_xml.

END-OF-SELECTION.

  • Down load the xml file

PERFORM download_xml.

FORM populate_data .

SELECT EBELN BUKRS EKGRP FROM EKKO INTO TABLE

PURCHASE_ORDER_HEADER_DETAILS UP TO 10

ROWS.

ENDFORM. " populate_data

FORM create_xml .

***m_document TYPE REF TO if_ixml_document,

***g_ixml TYPE REF TO if_ixml,

***l_dom TYPE REF TO if_ixml_element,

      • w_rc LIKE sy-subrc

      • s_xml LIKE LINE OF it_xml,

CLASS cl_ixml DEFINITION LOAD.

g_ixml = cl_ixml=>create( ).

CHECK NOT g_ixml IS INITIAL.

m_document = g_ixml->create_document( ).

CHECK NOT m_document IS INITIAL.

WRITE: / 'Converting DATA TO DOM 1:'.

CALL FUNCTION 'SDIXML_DATA_TO_DOM'

EXPORTING

name = 'PURCHASE_ORDER_HEADER_DETAILS'

dataobject = PURCHASE_ORDER_HEADER_DETAILS[]

IMPORTING

data_as_dom = l_dom

CHANGING

document = m_document

EXCEPTIONS

illegal_name = 1

OTHERS = 2.

IF sy-subrc = 0.

WRITE 'Ok'.

ELSE.

WRITE: 'Err =',

sy-subrc.

ENDIF.

CHECK NOT l_dom IS INITIAL.

w_rc = m_document->append_child( new_child = l_dom ).

IF w_rc IS INITIAL.

WRITE 'Ok'.

ELSE.

WRITE: 'Err =',

w_rc.

ENDIF.

***BEGIN OF xml_tab OCCURS 0,

***d LIKE LINE OF xml,

***END OF xml_tab.

CALL FUNCTION 'SDIXML_DOM_TO_XML'

EXPORTING

document = m_document

IMPORTING

xml_as_string = w_string

size = w_size

TABLES

xml_as_table = it_xml

EXCEPTIONS

no_document = 1

OTHERS = 2.

IF sy-subrc = 0.

WRITE 'Ok'.

ELSE.

WRITE: 'Err =',

sy-subrc.

ENDIF.

*WRITE:/'MURALI', W_STRING, 'KRISHNA'.

LOOP AT it_xml INTO xml_tab-d.

WRITE:/ SY-TABIX.

WRITE:/ XML_TAB-D.

APPEND xml_tab.

ENDLOOP.

*APPEND xml_tab.

open dataset ds for output.

loop at xml_tab.

transfer xml_tab to ds.

endloop.

close dataset ds.

ENDFORM. " create_xml

&----


*& Form get_local_file_name

&----


  • text

----


  • -->P_P_FILE text

----


FORM get_local_file_name USING p_p_file.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

CHANGING

file_name = p_p_file

EXCEPTIONS

mask_too_long = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE i007(zu). " 'Error in getting filename'.

ENDIF.

ENDFORM. " get_local_file_name

&----


*& Form download_xml

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM download_xml .

CALL FUNCTION 'WS_DOWNLOAD'

EXPORTING

bin_filesize = w_size

filename = p_file

filetype = 'BIN'

TABLES

data_tab = xml_tab

EXCEPTIONS

OTHERS = 10.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ELSE.

  • SKIP 5.

  • WRITE:(15) 'The ', p_file , 'is created successfully'.

*

ENDIF.

ENDFORM. " download_xml

<b>My O/p is</b>

<b>My O/p is</b>

<b>My O/p is</b>

<?xml version="1.0" ?>

- <PURCHASE_ORDER_HEADER_DETAILS>

- <item>

<TD_PO_ID>3000000004</TD_PO_ID>

<TD_COMPANYCD>3000</TD_COMPANYCD>

<TD_BUYERID>013</TD_BUYERID>

</item>

- <item>

<TD_PO_ID>3000000005</TD_PO_ID>

<TD_COMPANYCD>3000</TD_COMPANYCD>

<TD_BUYERID>013</TD_BUYERID>

</item>

<?xml version="1.0" ?>

- <PURCHASE_ORDER_HEADER_DETAILS>

- <item>

<TD_PO_ID>3000000004</TD_PO_ID>

<TD_COMPANYCD>3000</TD_COMPANYCD>

<TD_BUYERID>013</TD_BUYERID>

</item>

- <item>

<TD_PO_ID>3000000005</TD_PO_ID>

<TD_COMPANYCD>3000</TD_COMPANYCD>

<TD_BUYERID>013</TD_BUYERID>

</item>

</PURCHASE_ORDER_HEADER_DETAILS>

1) Actually I don't want to Print <item> and </item>.

Instead of it I want to Print <Details> and </Details>

2. CALL FUNCTION 'SDIXML_DOM_TO_XML'

This FM giving O/p in XMl Format.

How to Convert it into STRING format.

Please Help me Friends. It is very Urgent.

Thanks & Regards,

Murali Krishna K.

1 REPLY 1

athavanraja
Active Contributor
0 Kudos
72

<i>1) Actually I don't want to Print <item> and </item>.

Instead of it I want to Print <Details> and </Details>

2. CALL FUNCTION 'SDIXML_DOM_TO_XML'

This FM giving O/p in XMl Format.

How to Convert it into STRING format.</i>

SDIXML_DOM_TO_XML - function returns the xml in both as table format and as a xstring.

if you want to convert the results to a string.

1. convert xstring to a string.

use FM ECATT_CONV_XSTRING_TO_STRING

2. convert to xml in table format to string

use FM

CONVERT_TABLE_TO_STRING or

SOTR_SERV_TABLE_TO_STRING

once its converted string, then you can use

replace all occurrences of '<items>' in <xmlstring> with '<Details> .

replace all occurrences of '</items>' in <xmlstring> with '</Details> .

Hope this is clear.

Regards

Raja