<?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 Re: casting X to C : ASSIGN_BASE_WRONG_ALIGNMENT in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971576#M1339355</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here I just share my "little" generic routine to cast from X (or xstring) to C (string, N... or any other character-type data). I would be happy if someone could share a simplest way to do the same (I close this thread but don't hesitate to answer this last question &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;). After this routine, there is a demo.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*----------------------------------------------------------------------*
FORM cast_copy_xstring_to_string
      USING
        i_xsequence           TYPE xsequence
        i_ignore_size_error   TYPE flag
      CHANGING
        e_string              TYPE clike
        e_xstring_size_error  TYPE flag.
  CONSTANTS con_xbuffer_size TYPE i VALUE 10000. "large buffer, max 65535, multiple of charsize
  DATA l_xbuffer TYPE x LENGTH con_xbuffer_size.
  FIELD-SYMBOLS &amp;lt;l_c&amp;gt; TYPE c.
  DATA l_xsequence_len TYPE i.
  DATA l_xsequence_type TYPE c.
  DATA l_pos TYPE i.
  DATA l_len TYPE i.
  DATA l_temp TYPE i.

  CLEAR e_string.
  CLEAR e_xstring_size_error.

* make sure the buffer size is a multiple of charsize
  l_temp = con_xbuffer_size MOD cl_abap_char_utilities=&amp;gt;charsize.
  ASSERT l_temp = 0 AND con_xbuffer_size &amp;gt;= cl_abap_char_utilities=&amp;gt;charsize.

  l_pos = 0.
  DESCRIBE FIELD i_xsequence TYPE l_xsequence_type LENGTH l_xsequence_len IN BYTE MODE.
  IF l_xsequence_type = cl_abap_typedescr=&amp;gt;TYPEKIND_XSTRING.
    l_xsequence_len = XSTRLEN( I_xsequence ). "before 6.10, use STRLEN
  ENDIF.

  l_temp = l_xsequence_len MOD cl_abap_char_utilities=&amp;gt;charsize.
  IF l_temp &amp;lt;&amp;gt; 0 AND i_ignore_size_error IS INITIAL.
    e_xstring_size_error = 'X'.
  ELSE.
    l_len = con_xbuffer_size.
    DO.
      IF l_pos &amp;gt;= l_xsequence_len.
        EXIT.
      ENDIF.
      l_temp = l_pos + con_xbuffer_size.
      IF l_temp &amp;gt;= l_xsequence_len.
* last bytes
        l_len = l_xsequence_len - l_pos.
        l_xbuffer = i_xsequence+l_pos(l_len).
* Adjust length on the last bytes in case the input x size does not fit character size
        IF i_ignore_size_error IS NOT INITIAL.
          l_len = ( l_len / cl_abap_char_utilities=&amp;gt;charsize ) * cl_abap_char_utilities=&amp;gt;charsize.
        ENDIF.
      ELSE.
        l_xbuffer = i_xsequence+l_pos(l_len).
      ENDIF.
      ASSIGN l_xbuffer(l_len) TO &amp;lt;l_c&amp;gt; CASTING.
      CONCATENATE e_string &amp;lt;l_c&amp;gt; INTO e_string.
      ADD con_xbuffer_size TO l_pos.
    ENDDO.
  ENDIF.
ENDFORM.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 Aug 2009 10:00:06 GMT</pubDate>
    <dc:creator>Sandra_Rossi</dc:creator>
    <dc:date>2009-08-18T10:00:06Z</dc:date>
    <item>
      <title>casting X to C : ASSIGN_BASE_WRONG_ALIGNMENT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971570#M1339349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in my utf-16 little endian system (unicode system, 4103 system code page), I have this little program which dumps at the ASSIGN statement (exception ASSIGN_BASE_WRONG_ALIGNMENT). For information, I made sure that the program has the unicode check property active (in case there would be some bug around that).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe it's a kernel problem, I use Linux x86_64.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you check this code, and if it works for you, could you please tell your kernel + your system code page (via SNLS transaction).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA x1 type x length 4.
field-symbols &amp;lt;c&amp;gt; type c.
x1 = '41004100'. "AA in utf-16 little endian
assign x1(4) to &amp;lt;c&amp;gt; casting. "&amp;lt;--- DUMP
write &amp;lt;c&amp;gt;.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The dump says:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the current program, an error occurred when setting the field symbol "&amp;lt;C&amp;gt;" with ASSIGN or ASSIGNING (maybe in the combination with  the CASTING addition).&lt;/P&gt;&lt;P&gt;When converting the base entry of the field symbol "&amp;lt;C&amp;gt;" (number in base table: 13), it was found that the target type requests a memory alignment of 2.&lt;/P&gt;&lt;P&gt;However, the source data object has an invalid memory alignment, that is an alignment not divisible by 2.&lt;/P&gt;&lt;P&gt;You may be able to avoid the error by using a different offset. The following must apply: Offset = n * 2, n &amp;gt;= 0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I forgot to say that I checked SAP notes and none corresponds to that issue; they only explain the general problems of alignment which is not the case here (I guess) &amp;lt;-- Added by: Sandra Rossi on Aug 10, 2009 11:08 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2009 08:52:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971570#M1339349</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-08-10T08:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: casting X to C : ASSIGN_BASE_WRONG_ALIGNMENT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971571#M1339350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I Ran this code snippet and did not get any Dump. O/P was A#A#(Looks like not appropriate Code page as well) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Database codepage                   1100     
Current Codepage of Appl. Server    1100     
Codepage of Front End               1160     
Kernal :700_REL&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2009 09:20:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971571#M1339350</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-10T09:20:34Z</dc:date>
    </item>
    <item>
      <title>Re: casting X to C : ASSIGN_BASE_WRONG_ALIGNMENT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971572#M1339351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've got the same dump, codepage 4102&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2009 09:20:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971572#M1339351</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-10T09:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: casting X to C : ASSIGN_BASE_WRONG_ALIGNMENT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971573#M1339352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you Amit and Max.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What operating systems do you use (windows 32/64, linux, unix...), and do you think it could be a bug in the sap kernel, or is there an easy workaround? (I made a "little" routine as a workaround which is not so simple!)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2009 09:36:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971573#M1339352</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-08-10T09:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: casting X to C : ASSIGN_BASE_WRONG_ALIGNMENT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971574#M1339353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you checked the notes 303607 and 538119 and 766876?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2009 10:03:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971574#M1339353</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-10T10:03:56Z</dc:date>
    </item>
    <item>
      <title>Re: casting X to C : ASSIGN_BASE_WRONG_ALIGNMENT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971575#M1339354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes. These notes just point out casting and alignment issues in "old" releases (*), and I feel I understand everything that is mentioned. But in the case of X to C, there shouldn't be any alignment issue (I made sure to have an X length which is a multiple of 4 bytes, the widest character size possible).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;(*) I forgot to say my SAP system is 7.0 SP 13, and sap kernel is 700 Linux GNU SLES-9 patch 179.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Aug 2009 10:43:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971575#M1339354</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-08-10T10:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: casting X to C : ASSIGN_BASE_WRONG_ALIGNMENT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971576#M1339355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here I just share my "little" generic routine to cast from X (or xstring) to C (string, N... or any other character-type data). I would be happy if someone could share a simplest way to do the same (I close this thread but don't hesitate to answer this last question &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;). After this routine, there is a demo.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*----------------------------------------------------------------------*
FORM cast_copy_xstring_to_string
      USING
        i_xsequence           TYPE xsequence
        i_ignore_size_error   TYPE flag
      CHANGING
        e_string              TYPE clike
        e_xstring_size_error  TYPE flag.
  CONSTANTS con_xbuffer_size TYPE i VALUE 10000. "large buffer, max 65535, multiple of charsize
  DATA l_xbuffer TYPE x LENGTH con_xbuffer_size.
  FIELD-SYMBOLS &amp;lt;l_c&amp;gt; TYPE c.
  DATA l_xsequence_len TYPE i.
  DATA l_xsequence_type TYPE c.
  DATA l_pos TYPE i.
  DATA l_len TYPE i.
  DATA l_temp TYPE i.

  CLEAR e_string.
  CLEAR e_xstring_size_error.

* make sure the buffer size is a multiple of charsize
  l_temp = con_xbuffer_size MOD cl_abap_char_utilities=&amp;gt;charsize.
  ASSERT l_temp = 0 AND con_xbuffer_size &amp;gt;= cl_abap_char_utilities=&amp;gt;charsize.

  l_pos = 0.
  DESCRIBE FIELD i_xsequence TYPE l_xsequence_type LENGTH l_xsequence_len IN BYTE MODE.
  IF l_xsequence_type = cl_abap_typedescr=&amp;gt;TYPEKIND_XSTRING.
    l_xsequence_len = XSTRLEN( I_xsequence ). "before 6.10, use STRLEN
  ENDIF.

  l_temp = l_xsequence_len MOD cl_abap_char_utilities=&amp;gt;charsize.
  IF l_temp &amp;lt;&amp;gt; 0 AND i_ignore_size_error IS INITIAL.
    e_xstring_size_error = 'X'.
  ELSE.
    l_len = con_xbuffer_size.
    DO.
      IF l_pos &amp;gt;= l_xsequence_len.
        EXIT.
      ENDIF.
      l_temp = l_pos + con_xbuffer_size.
      IF l_temp &amp;gt;= l_xsequence_len.
* last bytes
        l_len = l_xsequence_len - l_pos.
        l_xbuffer = i_xsequence+l_pos(l_len).
* Adjust length on the last bytes in case the input x size does not fit character size
        IF i_ignore_size_error IS NOT INITIAL.
          l_len = ( l_len / cl_abap_char_utilities=&amp;gt;charsize ) * cl_abap_char_utilities=&amp;gt;charsize.
        ENDIF.
      ELSE.
        l_xbuffer = i_xsequence+l_pos(l_len).
      ENDIF.
      ASSIGN l_xbuffer(l_len) TO &amp;lt;l_c&amp;gt; CASTING.
      CONCATENATE e_string &amp;lt;l_c&amp;gt; INTO e_string.
      ADD con_xbuffer_size TO l_pos.
    ENDDO.
  ENDIF.
ENDFORM.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Aug 2009 10:00:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971576#M1339355</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-08-18T10:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: casting X to C : ASSIGN_BASE_WRONG_ALIGNMENT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971577#M1339356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I forgot the demo part:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA l_string TYPE string.
DATA l_error TYPE flag.

IF cl_i18n_search_utils=&amp;gt;system_codepage( ) = '1100'.       "iso-8859-1
  PERFORM cast_copy_xstring_to_string USING '41424344' '' CHANGING l_string l_error.
  ASSERT l_error IS INITIAL AND l_string = 'ABCD'.
ELSEIF cl_i18n_search_utils=&amp;gt;system_codepage( ) = '4103'.   "utf16-le
  PERFORM cast_copy_xstring_to_string USING '4100420043004400' '' CHANGING l_string l_error.
  ASSERT l_error IS INITIAL AND l_string = 'ABCD'.
  PERFORM cast_copy_xstring_to_string USING '41004200430044' '' CHANGING l_string l_error.
  ASSERT l_error = 'X'.
  PERFORM cast_copy_xstring_to_string USING '41004200430044' 'X' CHANGING l_string l_error.
  ASSERT l_error IS INITIAL AND l_string = 'ABCD'.
ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Aug 2009 10:00:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971577#M1339356</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-08-18T10:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: casting X to C : ASSIGN_BASE_WRONG_ALIGNMENT</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971578#M1339357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;More simple version of the routine above. It assumes the input X or XSTRING is a valid string of characters in the system encoding (codepage), so that to simplify the code (I removed the 2 error parameters). It is based on the fact that the conversion classes do not convert bytes if the input and output encodings (i.e. codepages) are the same.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
FORM cast_copy_xstring_to_string
      USING
        i_xsequence           TYPE xsequence
      CHANGING
        e_string              TYPE clike.
  DATA enc TYPE abap_encod.
  DATA conv TYPE REF TO cl_abap_conv_in_ce.
  enc = cl_i18n_search_utils=&amp;gt;system_codepage( ).
  conv = cl_abap_conv_in_ce=&amp;gt;create( ENCODING = enc ).
  conv-&amp;gt;convert(
    EXPORTING INPUT = i_xsequence
    IMPORTING DATA = e_string ).
ENDFORM.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Oct 2009 09:37:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/casting-x-to-c-assign-base-wrong-alignment/m-p/5971578#M1339357</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2009-10-05T09:37:57Z</dc:date>
    </item>
  </channel>
</rss>

