<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic UTF-16 conversion problem in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606753#M2011449</link>
    <description>&lt;P&gt;I've a zipped file that contains UTF-16 LE text files. I'm using the standard SAP CL_ABAP_ZIP to unzip, which gives me an xstring. I want to convert that xstring into a string, but the problem is that the Byte Order Marker FFFE is being retained in the string. This causes problems further down the line if I want to do any string operations. &lt;BR /&gt;&lt;BR /&gt;In this code example, the output is "/AAA_Z " instead of "/AAA_ZI". &lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;REPORT.

DATA content_as_x TYPE xstring.
content_as_x = 'FFFE2F004100410041005F005A0049000A000D002F004100410041005F005A004900'.

DATA lt_data TYPE TABLE OF x255.
DATA lv_len  TYPE i.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    buffer        = content_as_x
  IMPORTING
    output_length = lv_len
  TABLES
    binary_tab    = lt_data.
DATA content_as_string TYPE string.
CALL FUNCTION 'SCMS_BINARY_TO_STRING'
  EXPORTING
    input_length = lv_len
    encoding     = CONV abap_encoding( '4103' )
  IMPORTING
    text_buffer  = content_as_string
  TABLES
    binary_tab   = lt_data.
DATA content TYPE string_table.
SPLIT content_as_string AT cl_abap_char_utilities=&amp;gt;cr_lf INTO TABLE content.
DATA first_line TYPE c length 7.
first_line = content[ 1 ].
cl_demo_output=&amp;gt;DISPLAY_DATA( first_line ).&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt; The hex content of 
  &lt;STRONG&gt;first_line&lt;/STRONG&gt; is FFFE2F004100410041005F005A00 
  &lt;P&gt;Note that although I've hardcoded the SCMS_BINARY_TO_STRING &lt;STRONG&gt;encoding&lt;/STRONG&gt; as UTF-16 LE (4103), in my real program it's a variable.&lt;BR /&gt;I've also tried&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;REPORT.

DATA content_as_x TYPE xstring.
content_as_x = 'FFFE2F004100410041005F005A0049000A000D002F004100410041005F005A004900'.
DATA content_as_string TYPE string.
DATA(conv) = cl_abap_conv_in_ce=&amp;gt;create( encoding = '4103'
                                         endian = 'L' ).
conv-&amp;gt;convert( exporting input = content_as_x
               IMPORTING data  = content_as_string ).

DATA content TYPE string_table.
SPLIT content_as_string AT cl_abap_char_utilities=&amp;gt;cr_lf INTO TABLE content.
DATA first_line TYPE c length 7.
first_line = content[ 1 ].
cl_demo_output=&amp;gt;DISPLAY_DATA( first_line ).&lt;/CODE&gt;&lt;/PRE&gt; Same issue. 
  &lt;BR /&gt; 
  &lt;BR /&gt;Is there a better way of converting an xstring with a known encoding to a string that doesn't have these problems. Note, this needs to work in 7.4 (ideally 7.31 - don't ask!). 
  &lt;BR /&gt; 
  &lt;BR /&gt;Or do I just have to snip off Byte Order Markers? 
  &lt;BR /&gt;</description>
    <pubDate>Mon, 22 Aug 2022 11:58:10 GMT</pubDate>
    <dc:creator>matt</dc:creator>
    <dc:date>2022-08-22T11:58:10Z</dc:date>
    <item>
      <title>UTF-16 conversion problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606753#M2011449</link>
      <description>&lt;P&gt;I've a zipped file that contains UTF-16 LE text files. I'm using the standard SAP CL_ABAP_ZIP to unzip, which gives me an xstring. I want to convert that xstring into a string, but the problem is that the Byte Order Marker FFFE is being retained in the string. This causes problems further down the line if I want to do any string operations. &lt;BR /&gt;&lt;BR /&gt;In this code example, the output is "/AAA_Z " instead of "/AAA_ZI". &lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;REPORT.

DATA content_as_x TYPE xstring.
content_as_x = 'FFFE2F004100410041005F005A0049000A000D002F004100410041005F005A004900'.

DATA lt_data TYPE TABLE OF x255.
DATA lv_len  TYPE i.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
  EXPORTING
    buffer        = content_as_x
  IMPORTING
    output_length = lv_len
  TABLES
    binary_tab    = lt_data.
DATA content_as_string TYPE string.
CALL FUNCTION 'SCMS_BINARY_TO_STRING'
  EXPORTING
    input_length = lv_len
    encoding     = CONV abap_encoding( '4103' )
  IMPORTING
    text_buffer  = content_as_string
  TABLES
    binary_tab   = lt_data.
DATA content TYPE string_table.
SPLIT content_as_string AT cl_abap_char_utilities=&amp;gt;cr_lf INTO TABLE content.
DATA first_line TYPE c length 7.
first_line = content[ 1 ].
cl_demo_output=&amp;gt;DISPLAY_DATA( first_line ).&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt; The hex content of 
  &lt;STRONG&gt;first_line&lt;/STRONG&gt; is FFFE2F004100410041005F005A00 
  &lt;P&gt;Note that although I've hardcoded the SCMS_BINARY_TO_STRING &lt;STRONG&gt;encoding&lt;/STRONG&gt; as UTF-16 LE (4103), in my real program it's a variable.&lt;BR /&gt;I've also tried&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;REPORT.

DATA content_as_x TYPE xstring.
content_as_x = 'FFFE2F004100410041005F005A0049000A000D002F004100410041005F005A004900'.
DATA content_as_string TYPE string.
DATA(conv) = cl_abap_conv_in_ce=&amp;gt;create( encoding = '4103'
                                         endian = 'L' ).
conv-&amp;gt;convert( exporting input = content_as_x
               IMPORTING data  = content_as_string ).

DATA content TYPE string_table.
SPLIT content_as_string AT cl_abap_char_utilities=&amp;gt;cr_lf INTO TABLE content.
DATA first_line TYPE c length 7.
first_line = content[ 1 ].
cl_demo_output=&amp;gt;DISPLAY_DATA( first_line ).&lt;/CODE&gt;&lt;/PRE&gt; Same issue. 
  &lt;BR /&gt; 
  &lt;BR /&gt;Is there a better way of converting an xstring with a known encoding to a string that doesn't have these problems. Note, this needs to work in 7.4 (ideally 7.31 - don't ask!). 
  &lt;BR /&gt; 
  &lt;BR /&gt;Or do I just have to snip off Byte Order Markers? 
  &lt;BR /&gt;</description>
      <pubDate>Mon, 22 Aug 2022 11:58:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606753#M2011449</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2022-08-22T11:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: UTF-16 conversion problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606754#M2011450</link>
      <description>&lt;P&gt;I don't get your actual question. If it's about the BOM, just remove it for further processing.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 12:24:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606754#M2011450</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2022-08-22T12:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: UTF-16 conversion problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606755#M2011451</link>
      <description>&lt;P&gt;This is the information I have seen on the topic at several sites suggesting the content can be ignored -&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For the &lt;A href="https://en.wikipedia.org/wiki/Internet_Assigned_Numbers_Authority"&gt;IANA&lt;/A&gt; registered charsets UTF-16BE and UTF-16LE, a byte order mark should not be used because the names of these character sets already determine the byte order. If encountered anywhere in such a text stream, U+FEFF is to be interpreted as a "zero width no-break space".&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 12:32:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606755#M2011451</guid>
      <dc:creator>Ryan-Crosby</dc:creator>
      <dc:date>2022-08-22T12:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: UTF-16 conversion problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606756#M2011452</link>
      <description>&lt;P&gt;  &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt;  &lt;SPAN class="mention-scrubbed"&gt;ryan.crosby2&lt;/SPAN&gt; &lt;BR /&gt;&lt;BR /&gt;"Or do I just have to snip off the BOMs".&lt;BR /&gt;&lt;BR /&gt;It seems yes! &lt;/P&gt;&lt;P&gt;Many thanks. &lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 12:42:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606756#M2011452</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2022-08-22T12:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: UTF-16 conversion problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606757#M2011453</link>
      <description>&lt;P&gt;To strip off the BOM you must not write that yourself: cl_bcs_utilities=&amp;gt;remove_bom_from_content(). Whether that exists outside an ERP System I don't know. It belongs to SAP_BASIS component and should therefor be available everywhere. &lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 13:29:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606757#M2011453</guid>
      <dc:creator>BiberM</dc:creator>
      <dc:date>2022-08-22T13:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: UTF-16 conversion problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606758#M2011454</link>
      <description>&lt;P&gt;  &lt;SPAN class="mention-scrubbed"&gt;mbiber&lt;/SPAN&gt; I can confirm it exists on none ERP systems.&lt;/P&gt;&lt;P&gt;Very useful class. Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Aug 2022 13:59:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/utf-16-conversion-problem/m-p/12606758#M2011454</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2022-08-22T13:59:11Z</dc:date>
    </item>
  </channel>
</rss>

