Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Xstring to String

Former Member
0 Likes
2,334

I need to convert a xstring to a string, in the following way:

xstring contains 3C3F78 (hex value)

string should contain that value as hex, not as character-value.


How can i do that ?

10 REPLIES 10
Read only

bernat_loscos
Explorer
0 Likes
2,069

Hello roberto,

You can try to use this FM: ECATT_CONV_XSTRING_TO_STRING


Regards,

Read only

0 Likes
2,069

Hi, the problem of this function is that the returned string is converted in utf 16 mode, no matter which parameter i pass in  IM_ENCODING. But, for my purpose, i need the string to be in uft 8 mode.

Any idea ?

Read only

0 Likes
2,069

Hi, if you try this:

CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
   EXPORTING
     im_xstring  = l_xstr
     im_encoding = 'UTF-8'
   IMPORTING
     ex_string   = l_string.


The ex_string is in UTF-8.. 


How is your expected result?


regards.

Read only

0 Likes
2,069

In my case in l_xstr i have the utf-8 hex code of a japanese ideogram (i converted it from standard utf 16 to utf 8 with

data: lr_conv type ref to cl_abap_conv_obj.

       create object lr_conv

         exporting

           incode  = '4103'                                  "UTF-16

           outcode = '4110'.                                 "UTF-8

       call method lr_conv->convert

etc..


the hex value of l_xstr is E5B882. I expect the hex value of l_string to be the same, i.e. E5B882. But, actually, the hex value of l_string is 025E which is, by the way, the original utf 16 hex value of the ideogram.

Read only

0 Likes
2,069

The hex value is supposed to change as the encoding specifies how the bits would be arranged.

Hex value plus the encoding is able to give the exact text. xE5B882 as UTF-8 is same as x025E as UTF-16 when converted to text.

Move the hex value to a string type variable directly does give you a string that has hex value, not char representation.

Message was edited by: Manish Kumar

Read only

0 Likes
2,069

Thank you Manish. Let's say that, ignoring the conversion thing, i just want to copy the hex value stored in the xstring to the string. Is there a way to do that ?

Read only

0 Likes
2,069

Yes, just move it to variable of type string.

Data hex type xstring.

Data str type string.

hex = 'E5B882'.

str = hex.

break-point.

Read only

Former Member
0 Likes
2,069

Hi,

try below methods/FM

1. DATA: LOC_CONV TYPE REF TO CL_ABAP_CONV_IN_CE,
          LOC_XSTRING TYPE XSTRING,
          LOC_STRING TYPE STRING.
*   Convert XString to String
CALL METHOD CL_ABAP_CONV_IN_CE=>CREATE
  EXPORTING
    INPUT       = LOC_XSTRING
    ENCODING    = 'UTF-8'
    REPLACEMENT = '?'
    IGNORE_CERR = ABAP_TRUE
  RECEIVING
    CONV        = LOC_CONV.

TRY.
    CALL METHOD LOC_CONV->READ
      IMPORTING
        DATA = LOC_STRING.
  CATCH CX_SY_CONVERSION_CODEPAGE.
*-- Should ignore errors in code conversions
  CATCH CX_SY_CODEPAGE_CONVERTER_INIT.
*-- Should ignore errors in code conversions
  CATCH CX_PARAMETER_INVALID_TYPE.
  CATCH CX_PARAMETER_INVALID_RANGE.
ENDTRY.

2.

CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
in_xstring = l_xstring
IMPORTING
out_string = l_string.

Read only

0 Likes
2,069

Hi rohit, i don't have the fm hr_kr etc in my system. where can i find it ?

Read only

ThangaPrakash
Active Contributor
0 Likes
2,069

Hello Roberto,

Try with the FM's

HR_KR_XSTRING_TO_STRING


CRM_IC_XML_XSTRING2STRING

HR_PSD_CONV_XSTRING_TO_STRING

Regards,

Thanga