2008 Sep 04 1:05 PM
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.
2008 Sep 04 2: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
2008 Sep 04 1:12 PM
Victor,
Try these FM,
CRM_IC_XML_STRING2XSTRING : Converts string to xstring
CRM_IC_XML_XSTRING2STRING : Converts xstring to string
Regards
Indu.
2008 Sep 04 1:14 PM
2008 Sep 04 1: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.
2008 Sep 04 1:38 PM
2008 Sep 04 1: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
2008 Sep 04 2:02 PM
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
2008 Sep 04 2: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
2008 Sep 04 2: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.
2008 Sep 04 2:26 PM
2008 Sep 04 2:27 PM
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
2023 Nov 21 7:32 AM
You can refer to below class-method set to convert instead of using unreleased FMs.
*&---------------------------------------------------------------------*
*& " Convert XString to String
*&---------------------------------------------------------------------*
DATA: lv_string TYPE string,
lv_xstring TYPE xstring.
DATA: lo_conv_in TYPE REF TO CL_ABAP_CONV_IN_CE.
lo_conv_in = CL_ABAP_CONV_IN_CE=>CREATE( input = lv_xstring ).
lo_conv_in->READ( IMPORTING data = lv_string ).*&---------------------------------------------------------------------*
*& " Convert String to XString
*&---------------------------------------------------------------------*
DATA: lo_conv TYPE REF TO cl_abap_conv_out_ce.
lo_conv = cl_abap_conv_out_ce=>create( encoding = '4110' ).
lo_conv->convert( EXPORTING data = lv_string
IMPORTING buffer = lv_xstring ).*&---------------------------------------------------------------------*
*& " Convert XString to Binary
*&---------------------------------------------------------------------*
data: lt_binary_tab TYPE solix_tab. " table of solix
CLEAR: lt_binary_tab.
lt_binary_tab = cl_document_bcs=>xstring_to_solix(
ip_xstring = lv_xstring ).