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

SAP_CONVERT_TO_XML_FORMAT Function Module

Former Member
0 Likes
3,540

Hello All,

I want to use the FM SAP_CONVERT_TO_XML_FORMAT to generate an xml file from an internal table. I am not sure what parameters to pass to do this, assistance please? I have looked at the following link but still don't understand http://sap.ittoolbox.com/groups/technical-functional/sap-dev/using-sap_convert_to_xml_format-281858

Can the FM be used to generate xml in a custom format?

Thanks,

Wilson.

1 ACCEPTED SOLUTION
Read only

RemiKaimal
Active Contributor
0 Likes
2,409

Hi Wison,

Check out Sample code :

TABLES USR03.

DATA: BEGIN OF ISAPDAT OCCURS 0,

          BNAME  LIKE USR03-BNAME,

          NAME1  LIKE USR03-NAME1,

          NAME2  LIKE USR03

-NAME2,

      END  OF ISAPDAT.

PARAMETERS P_FNAME LIKE RLGRAP-FILENAME

                    DEFAULT  'd:\sapdata.xls' OBLIGATORY.

SELECT * FROM USR03 INTO CORRESPONDING FIELDS OF TABLE  ISAPDAT.

SORT ISAPDAT.

CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'

     EXPORTING

          I_FILENAME          =  P_FNAME

     TABLES

          I_TAB_SAP_DATA      =  ISAPDAT

     EXCEPTIONS

          CONVERSION_FAILED  = 1

          OTHERS              =  2.

IF SY-SUBRC EQ 0.

  WRITE:/  'Download to Excel complete'.

ELSE.

  WRITE:/  'Error with download'.

ENDIF.

Hope this helps...

Cheers,

Remi

5 REPLIES 5
Read only

Former Member
0 Likes
2,409

Hi Wilson,

This demo program talks about how to convert internal table into XML and download to PC and upload the same to SAP.

*&---------------------------------------------------------------------*

*& Report  ZTOXML

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

REPORT  ZTOXML.

*-------------- DATA

DATA : t001 type TABLE OF t001 WITH HEADER LINE.

DATA : BEGIN OF itab OCCURS 0,

a(100) TYPE c,

END OF itab.

DATA: xml_out TYPE string .

DATA : BEGIN OF upl OCCURS 0,

f(255) TYPE c,

END OF upl.

DATA: xmlupl TYPE string .

******************************* FIRST PHASE

******************************* FIRST PHASE

******************************* FIRST PHASE

*------------------ Fetch Data

SELECT * FROM t001 INTO TABLE t001.

*------------------- XML

CALL TRANSFORMATION ('ID')

SOURCE tab = t001[]

RESULT XML xml_out.

*------------- Convert to TABLE

CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'

EXPORTING

i_string = xml_out

i_tabline_length = 100

TABLES

et_table = itab.

*-------------- Download

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filetype = 'BIN'

filename = 'D:\vino\WD\first.xml'

TABLES

data_tab = itab.

******************************* SECOND PHASE

******************************* SECOND PHASE

******************************* SECOND PHASE

BREAK-POINT.

REFRESH t001.

CLEAR t001.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'D:\vino\WD\first.xml'

filetype = 'BIN'

TABLES

data_tab = upl.

LOOP AT upl.

CONCATENATE xmlupl upl-f INTO xmlupl.

ENDLOOP.

*------------------- XML

CALL TRANSFORMATION ('ID')

SOURCE XML xmlupl

RESULT tab = t001[]

Regards,

Jawaid Alam.

Read only

RemiKaimal
Active Contributor
0 Likes
2,410

Hi Wison,

Check out Sample code :

TABLES USR03.

DATA: BEGIN OF ISAPDAT OCCURS 0,

          BNAME  LIKE USR03-BNAME,

          NAME1  LIKE USR03-NAME1,

          NAME2  LIKE USR03

-NAME2,

      END  OF ISAPDAT.

PARAMETERS P_FNAME LIKE RLGRAP-FILENAME

                    DEFAULT  'd:\sapdata.xls' OBLIGATORY.

SELECT * FROM USR03 INTO CORRESPONDING FIELDS OF TABLE  ISAPDAT.

SORT ISAPDAT.

CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'

     EXPORTING

          I_FILENAME          =  P_FNAME

     TABLES

          I_TAB_SAP_DATA      =  ISAPDAT

     EXCEPTIONS

          CONVERSION_FAILED  = 1

          OTHERS              =  2.

IF SY-SUBRC EQ 0.

  WRITE:/  'Download to Excel complete'.

ELSE.

  WRITE:/  'Error with download'.

ENDIF.

Hope this helps...

Cheers,

Remi

Read only

0 Likes
2,409

Hi Remi,

Thanks for your quick answer. Might you know if it is possible to use this FM to generate xml in custom format?

Thanks,

Wilson.

Read only

0 Likes
2,409

Yes - If your question is about the customised view of fields in the XML.

Take the case, of the sample code, above

The table : USR03 - this has 28 fields.

Now, the XML file, will have only 3 fields, based on the internal table, defined.

Hope this helps...

Read only

Former Member
0 Likes
2,409

This message was moderated.