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

Writing an XML document to the application server using open dataset

Former Member
0 Likes
2,306

Dear all

I am trying to create an XML file on the application server of SAP and whilst I can write to the presentation server without any issues (using GUI_DOWNLOAD) I am having problems writing the file correctly to the application server on Unix.

I am using the following code to create the XML file :

CALL TRANSFORMATION ('ID')

SOURCE tab = it_err_rpt[]

RESULT XML xml_out.

CALL FUNCTION 'SCMS_STRING_TO_FTEXT'

EXPORTING

text = xml_out

TABLES

ftext_tab = itab.

I then use the open dataset / transfer and close dataset statements to try to get the file (held in this itab table) onto the apps server, although the file creates successfully, the resulting XML output is not readable in internet explorer when I copy it back to the presentation server whereas it is readable when I copy it directly to the presentation server via GUI_DOWNLOAD.

I have tried lots of permutations of the open dataset statement and none seem to work, I have noticed that the XML file that is generated is encoded in UTF-16 whereas the only options I have for encoding in text mode in the open dataset statement are default / UTF-8 and no encoding.

Any help with this issue would be appreciated.

1 ACCEPTED SOLUTION
Read only

MarcinPciak
Active Contributor
0 Likes
1,450

I would simply suggest to convert xml xstring to binary table, then transfer the file in binary mode. This way you avoid character conversions which might lead to inconsistencies. So you need the following


 CALL TRANSFORMATION ...

    DATA ex_tab TYPE TABLE OF x255.

    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer     = ostream_xml
      TABLES
        binary_tab = ex_tab.

OPEN DATASET dset FOR OUTPUT IN BINARY MODE.

"now transfer ex_tab to dset

Regards

Marcin

Dear all

I am trying to create an XML file on the application server of SAP and whilst I can write to the presentation server without any issues (using GUI_DOWNLOAD) I am having problems writing the file correctly to the application server on Unix.

I am using the following code to create the XML file :

CALL TRANSFORMATION ('ID')

SOURCE tab = it_err_rpt[]

RESULT XML xml_out.

CALL FUNCTION 'SCMS_STRING_TO_FTEXT'

EXPORTING

text = xml_out

TABLES

ftext_tab = itab.

I then use the open dataset / transfer and close dataset statements to try to get the file (held in this itab table) onto the apps server, although the file creates successfully, the resulting XML output is not readable in internet explorer when I copy it back to the presentation server whereas it is readable when I copy it directly to the presentation server via GUI_DOWNLOAD.

I have tried lots of permutations of the open dataset statement and none seem to work, I have noticed that the XML file that is generated is encoded in UTF-16 whereas the only options I have for encoding in text mode in the open dataset statement are default / UTF-8 and no encoding.

Any help with this issue would be appreciated.

2 REPLIES 2
Read only

MarcinPciak
Active Contributor
0 Likes
1,451

I would simply suggest to convert xml xstring to binary table, then transfer the file in binary mode. This way you avoid character conversions which might lead to inconsistencies. So you need the following


 CALL TRANSFORMATION ...

    DATA ex_tab TYPE TABLE OF x255.

    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer     = ostream_xml
      TABLES
        binary_tab = ex_tab.

OPEN DATASET dset FOR OUTPUT IN BINARY MODE.

"now transfer ex_tab to dset

Regards

Marcin

Read only

Former Member
0 Likes
1,450

Hi Marcin

Firstly many thanks for your quick response, Secondly with a little bit of playing around, your suggestion worked perfectly so thanks once again.