03-01-2017 11:13 AM
Hi,
I have written a program which is downloading a file from a webserver. The content of the file is stored I an xstring. When I write the xstring to the directory of the applicationserver the file will be converted to a binary.
I am getting the xstring from 'IF_HTTP_CLIENT' and its 'receive' method.
DATA:
l_client TYPE REF TO if_http_client
l_content TYPE xstring.
..
l_content = l_client->response->get_data( ).
...
When I open the file again convert the file from binary to xstring every second literal is a '#'. Her is an example:
"R#I#A#D#_#C#O#D#E###C#O#U#N#T#R#Y#_#O#F#_#R#E#G#I#S#T#R#A#T#I#O#N###N#A#M#E###B#O#X###A#D#D#R#E"
I played around with different charset, binary file types, xstring and string. Sometimes the file is a binary and opening the file will getting the '#', sometimes I get Chinese literal sometimes I am getting the binary.
Can anyone give my some hints how to save and read xstrings.
Regards
Henning
03-01-2017 8:11 PM
FFFE is the BOM for UTF-16 Little Endian (SAP code page "4103").
characters = CL_ABAP_CODEPAGE=>CONVERT_FROM( source = l_content codepage = 'utf-16le' ).
PS: I don't know if there's a nice conversion method from XSTRING to STRING which automatically takes into account the UTF BOM (utf-8, utf16-le, etc.)
03-01-2017 11:33 AM
03-01-2017 11:57 AM
Xstring can be directly saved as BIN file. No need to convert it.
How are you opening that file. And what do you mean with "convert the file from binary to xstring"?
What is that file format anyway? Do you expect it to be convertible to ASCII / text?
03-01-2017 11:59 AM
This is the hexcode from the debugger:
FFFE52004900410044005F0043004F0044004500090043004F0055004E005400520
Mhhh, the 00 stands for the #. But why am i getting the 00?
03-01-2017 12:08 PM
I saved the xstring as a binary file successfully. Trying to open the file I have the Problem again. Reading the binary file and convert the binary into an xstring will end in the same problem.
I played around in opening the file with 'open dataset' in binary mode, in text mode with UTF8 and other codepages encodings.
I tried to convert the string with 'SCMS_BINARY_TO_XSTRING' and similar.
03-01-2017 8:11 PM
FFFE is the BOM for UTF-16 Little Endian (SAP code page "4103").
characters = CL_ABAP_CODEPAGE=>CONVERT_FROM( source = l_content codepage = 'utf-16le' ).
PS: I don't know if there's a nice conversion method from XSTRING to STRING which automatically takes into account the UTF BOM (utf-8, utf16-le, etc.)
03-02-2017 11:50 AM
That was the right hint. I converted the string with the wrong codepage. This Code example works.
DATA conv_in TYPE REF TO cl_abap_conv_in_ce.
CONSTANTS:
lc_utf-16_little_endian TYPE xstring VALUE 'FFFE',
lc_replace TYPE xstring VALUE ''.
"delete BOM
REPLACE FIRST OCCURRENCE OF lc_utf-16_little_endian IN l_xstring WITH lc_replace IN BYTE MODE.
"conversion
conv_in = cl_abap_conv_in_ce=>create(
encoding = '4103'
input = l_xstring ).
conv_in->read( IMPORTING data = l_string ).
Thanks to all.