Skip to Content
avatar image
Former Member

Converting xstring to string and back?

Hello, everybody

I have a problem where I have an ID for an element that is made of 32 hexadecimal elements (hence a size 32 xstring). I need to use it in another system which requires a shorter parameter, but of type string. Therefore, I came to the conclusion that converting my xstring to a string I could turn it into a smaller element than making a simple "one-to-one" conversion (for example, converting 'AF543' where each element is a Hexadecimal to 'AF543' where each element is a character).

I looked into the forum and I found the following Function Modules: NLS_STRING_CONVERT_TO_SYS and NLS_STRING_CONVERT_FROM_SYS.

However, when I convert the xstring '00300571B3851DDD9DFFF7A753C08326' to a string, I get '#0#q³##Ý#ÿ÷§SÀ#&' as a result. I realized that the character # repeats itself several times, although there is no repetition of elements in the xstring. Obviously, when I converted this string back to xstring, I got a different result, because the # character was always interpreted as the same number.

Isn't this conversion supposed to be unique? How could I convert my xstring to a unique string and be able to make the conversion the other way around, getting my original xstring back?

Any support will be very appreciated. Thank you in advance.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

8 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 04, 2008 at 01:12 PM

    try this FM's

    HR_KR_STRING_TO_XSTRING

    Convert unicode string into xstring

    HR_KR_XSTRING_TO_STRING

    Convert encoded string to unicode string

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 12:40 PM

    This is the code which is not working:

    data: lv_uuid1 type xstring,

    test type xstring,

    l_out type string,

    l_out2 type xstring.

    lv_uuid1 = '00300571B3851DDD9DFFF7A753C08326'.

    CALL FUNCTION 'NLS_STRING_CONVERT_TO_SYS'

    EXPORTING

    LANG_USED = 'D'

    SOURCE = lv_uuid1

    IMPORTING

    RESULT = l_out.

    write: lv_uuid1, ' ', l_out.

    CALL FUNCTION 'NLS_STRING_CONVERT_FROM_SYS'

    EXPORTING

    LANG_USED = 'D'

    SOURCE = l_out

    IMPORTING

    RESULT = l_out2.

    write: / lv_uuid1, ' ', l_out2.

    Notice that the l_out2 result is not the same as lv_uuid1, what proves that the conversion is not unique.

    Edited by: Vitor Eduardo Seifert Bazzo on Sep 4, 2008 2:42 PM

    Edited by: Vitor Eduardo Seifert Bazzo on Sep 4, 2008 2:42 PM

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Victor,

      Try this code...

      REPORT yh_sample.
      DATA: w_s TYPE string.
      DATA: w_s1 TYPE xstring.
      DATA: lr_conv_ci TYPE REF TO cl_rpe_convert .
      
      CREATE OBJECT lr_conv_ci.
      
      w_s1 = '42'.
      CALL METHOD lr_conv_ci->xstring_to_string
        EXPORTING
          input  = w_s1
        IMPORTING
          output = w_s.
      WRITE:/ w_s.
      
      CALL METHOD lr_conv_ci->string_to_xstring
        EXPORTING
          input  = w_s
        IMPORTING
          output = w_s1.
      
      WRITE w_s1.

      Regards

      Indu

  • avatar image
    Former Member
    Sep 04, 2008 at 12:12 PM

    Victor,

    Try these FM,

    CRM_IC_XML_STRING2XSTRING : Converts string to xstring

    CRM_IC_XML_XSTRING2STRING : Converts xstring to string

    Regards

    Indu.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 12:14 PM
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 12:30 PM

    @ Indu: Thank you for the tip, but I couldn't find these Function Modules on my system.

    @ Syed: The solution presented in this link has the same problem I had before: it repeats the # characters on the conversion, therefore the resulting string is not unique.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 12:38 PM

    Hi,

    If possible show code.

    Adil

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 01:18 PM

    @ Indu: Thank you for the code, but I am still not able to recover my original xstring. This time the resulting xstring is even larger than the one I had before.

    @ Adil: Thank you for the tip, but I can't find these function modules in the system.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 01:26 PM

    Which system your using.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thank you for all the support. I will stop looking into this issue for now.

      Edited by: Vitor Eduardo Seifert Bazzo on Sep 4, 2008 4:09 PM