2013 Dec 27 12:06 PM
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.
2013 Dec 27 12:49 PM
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
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.
2013 Dec 27 12:27 PM
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.
2013 Dec 27 12:49 PM
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
2013 Dec 27 1:31 PM
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.
2013 Dec 30 4:03 AM
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...
2015 Mar 19 6:56 PM
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |