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

Converting xString To String

Former Member
0 Likes
9,985

Dear Experts,

I tried this code below to convert hex into string but why did the result is becoming ###



  DATA conv TYPE REF TO cl_abap_conv_in_ce.

  DATA buffer(4) TYPE x.

  DATA text(100) TYPE c.

  buffer = '02'. " 

  conv = cl_abap_conv_in_ce=>create(

        encoding = 'UTF-8' ).

  conv->convert(

        EXPORTING input = buffer

        IMPORTING data = text ).

Please advice.

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
8,781

The answer is simply because the hex in abap is 16 bits and not the same with this one. everything in abap must be multiply by 100. If I adjust it then the # will not appear.

6 REPLIES 6
Read only

Sandra_Rossi
Active Contributor
8,781

In ABAP debugger and many UIs in ABAP, non-characters (example: byte hexadecimal values "00" to "1F" converted to UTF-8) are often represented with:

#
Read only

FredericGirod
Active Contributor
8,781

there a really usefull class for conversion CL_BCS_CONVERT

Read only

FredericGirod
Active Contributor
8,781

Do you try the opposite ?

data hexa type xstring value '02'.
data(dec)  = conv string( hexa ).
write dec.


dec = 2.
hexa = dec.
write hexa.

Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
8,781

I do not see any problem. Your code works OK.

Your code is converting HEX value 02000000 (it is defined as X length 4 so it is = 02 00 00 00).
And result is corectly "control characte" U+0002. Which is not "printable" so SAP is displaying it as # in debugger.

Maybe you wanted to convert number 2 (DIGIT TWO) character ?
That is not 02 in HEX but 32 in HEX (U+0032). Check for example https://www.utf8-chartable.de/ or similar tables of HEX / UTF-8 characters...

-- Tomas --
Read only

Sandra_Rossi
Active Contributor
8,781

In an ABAP Unicode system (any system with release >= 7.50 can only be Unicode), a character occupies two bytes. What you did is to convert four bytes with hexadecimal value 02.00.00.00 representing UTF-8 "characters" into ABAP characters. If your system is Unicode (UTF-16) big endian, you'll get four characters with hexadecimal value 0002.0000.0000.0000. With little endian: 0200.0000.0000.0000. You can see that in the debugger, you may display the hexadecimal representation of characters.

Read only

Former Member
0 Likes
8,782

The answer is simply because the hex in abap is 16 bits and not the same with this one. everything in abap must be multiply by 100. If I adjust it then the # will not appear.