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

OPEN DATASET for XML utf-8

Former Member
0 Likes
2,456

Hello,

I need to read data from SAP 710 and save it in the server as a XML utf-8 file. Then this file is going to be read in a non SAP system.

I am reading data in a simple transformation to a STRING, but it come as UTF-16.

Then I call method CL_RSWAD_CONVERT=>STRING_TO_TABLE where I Import a binary table TYPE STANDARD TABLE OF char255.

So when I do 'OPEN DATASET lv_temp_unix_filen in BINARY MODE for OUTPUT.' the file is in UTF-16 format.

I tried to replace UTF-16 for UTF-8 (using: REPLACE FIRST OCCURRENCE OF 'utf-16' in lv_xml_string with 'utf-8'.)

but then the NON SAP system doesn't recognize the file.

I also tried to read the simple transformation data into a XSTRING.

Then I used CL_RSWAD_CONVERT=>XSTRING_TO_TABLE where I get the content in a binary table TYPE SOLIX_TAB.

If I use method cl_gui_frontend_services=>gui_download this works fine, but for the server, the file shows an error:

"The XML page cannot be displayed

Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

----


Invalid at the top level of the document. Error processing resource 'file:///C:/test.xml'. "

Can anyone help me?

Thanks and Kind regards!

1 ACCEPTED SOLUTION
Read only

mvoros
Active Contributor
0 Likes
1,484

Hi,

you can use FM SCMS_STRING_TO_XSTRING which takes a string and returns a string of bytes in encoding defined in paramter ENCODING. For UTF-8 you need to enter 4110. You should also check what encoding is mentioned in XML file. If it's UTF-16 you need to change it to UTF-8.

Cheers

Hi,

you can use FM SCMS_STRING_TO_XSTRING which takes a string and returns a string of bytes in encoding defined in paramter ENCODING. For UTF-8 you need to enter 4110. You should also check what encoding is mentioned in XML file. If it's UTF-16 you need to change it to UTF-8.

Cheers

6 REPLIES 6
Read only

mvoros
Active Contributor
0 Likes
1,485

Hi,

you can use FM SCMS_STRING_TO_XSTRING which takes a string and returns a string of bytes in encoding defined in paramter ENCODING. For UTF-8 you need to enter 4110. You should also check what encoding is mentioned in XML file. If it's UTF-16 you need to change it to UTF-8.

Cheers

Read only

Former Member
0 Likes
1,484

Hello Martin,

Thanks for your answer.

So, after I have all the date in a XSTRING as utf-8, how can I create a file in the server?

I do it like this:

OPEN DATASET lv_temp_unix_filen in BINARY MODE for OUTPUT.

But the output file has at the end the error described in last post.

Kind regards.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,484

Hello Luis,

Which release of ABAP are you using? You can use the addition [ENCODING UTF-8|http://help.sap.com/abapdocu_702/en/abapopen_dataset_encoding.htm#!ABAP_ALTERNATIVE_2@2@] provided you open the file in [TEXT MODE|http://help.sap.com/abapdocu_702/en/abapopen_dataset_mode.htm#!ABAP_ALTERNATIVE_2@2@].

If you're opening the file in BINARY MODE, you don't have to worry about the encoding!

BR,

Suhas

Read only

mvoros
Active Contributor
0 Likes
1,484

Hi,

are you sure that XML is valid. Have you tried to open that file in text editor and check if that XML is valid. For example what encoding is set there.

Cheers

Read only

Former Member
0 Likes
1,484

Sorry for taking so long to answer.

I am using Abap 710.

What do you mean with valid XML?

I can have a valid one in my pc (frontend) using method "CALL METHOD cl_gui_frontend_services=>gui_download",

but if I try to download it to the server using "OPEN DATASET lv_temp_unix_filen in BINARY MODE for OUTPUT." it gives me the error I described on my first post.

Is it possible to add in the simple transformation the enconding? Then I could load that transformed data to a STRING as UTF-8. Because right now from the simple transformation I get it as UTF-16. That's why I am reading it to a XSTRING to be UTF-8 (I read it in another topic from this forum).

Does anyone have a solution?

Thanks for helping me.

Kind regards.

Read only

Former Member
0 Likes
1,484

I solved my problem.

For unix I used an approach similar to the one posted on:

For frontend file I read the simple transformation to a xstring, then I convert it to binary table and I call method cl_gui_frontend_services=>gui_download.

Thanks for helping.

Kind regards.