Application Development 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: 

How-to convert a character to its hex value?

Former Member
0 Kudos

Dear All,

I have an issue with a string and I would like to parse it to get the hexadecimal value of every character of the string.

Does anybody know how to do this?

Any help highly appreciated

Thanks

Ioan

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Ioan,

Try function module CHAR_HEX_CONVERSION.

Mike Vondran

9 REPLIES 9

Former Member
0 Kudos

Hi Ioan,

Try function module CHAR_HEX_CONVERSION.

Mike Vondran

0 Kudos

Here is a sample program. This will convert one character at a time.



report zrich_0001.

data: s type string.
data: h(1) type x.
data: c(1) type c.
data: byte(2) type c.
data: length type i.

  FIELD-SYMBOLS: <DUMMY>.

s = 'ThisIsAString'.
length = strlen( s ).

do length times.

  byte = ( sy-index - 1 ).
  c = s+byte(1).

* You can do this 

  ASSIGN h TO <DUMMY> TYPE 'X'.
  WRITE c TO <DUMMY>.

* or you can do this

*  call function 'CHAR_HEX_CONVERSION'
*       exporting
*            input     = c
*       importing
*            hexstring = h.

  write:/ h.
enddo.


Regards,

Rich Heilman

Message was edited by: Rich Heilman

Message was edited by: Rich Heilman

Former Member
0 Kudos

Hi Ioan,

pls check this code:


data: d_string_char(50),
      d_string_hex(100).
field-symbols: <fs1>.
start-of-selection.
*** populate d_string_char with the string...
  assign d_string_char to <fs1> type 'X'.
  write <fs1> to d_string_hex.
*** now in d_string_hex you have the hex-conversion

I hope it helps. BR,

Alvaro

Former Member
0 Kudos

Hi Ioan,

Sorry, but that function module is not supported after a certain SAP version. OSS Note 394935 describes this.

If you are on 4.6D you can use the following code.

Also you'll need to loop through all of the single characters of the string for the following code, minus the data declaration.

data wa_input(1) type c value 'M'.
data: wa_hex type x.

FIELD-SYMBOLS: <DUMMY>.
ASSIGN wa_input TO <DUMMY> TYPE 'X'.
wa_hex = <dummy>.

I hope this helps.

Mike V.

0 Kudos

If you look at the source code of the function module, it is doing exactly the same.



  FIELD-SYMBOLS: <DUMMY>.
  ASSIGN HEXSTRING TO <DUMMY> TYPE 'X'.
  WRITE INPUT TO <DUMMY>.

Regards,

Rich Heilman

Former Member
0 Kudos

Thank you guys, you all got the answer to my question. I am assigning the point to the first answer, sorry for the other ones ...

Ioan

0 Kudos

Regards,

Rich Heilman

Message was edited by: Rich Heilman

Former Member
0 Kudos

I gave 10 to Mike (first answer). I would like to give you a 10, but I could not, so I gave you a 6. This is cool, isn't it?

Thanks again, this is saving my life (for a BW data load)

Ioan

0 Kudos

Cool. Glad that we all could help.

Regards,

Rich Heilman