Skip to Content
-1

Get Ascii Value A to 65

Feb 07, 2017 at 08:54 AM

81

avatar image
Former Member

Data : LV_S type c.

DATA : LV_AN TYPE i.

FIELD-SYMBOLS: <fc> TYPE x.

LV_S = 'A'.

ASSIGN LV_S to <fc> CASTING.

MOVE <fc> to LV_AN.

Now get data in dubugging as ,

<fc> = 4100

LV_AN = 16640

Now i want lv_an = 65 ... but it is display lv_an = 16640.

kindly , give proper solution

Regards,

Pratiksha

10 |10000 characters needed characters left characters exceeded

Why do you need this? What is the business functionality you're trying to achieve?

0

Look for UCS-2 in Abap documentation to understand.


0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Raghu Govindarajan Feb 07, 2017 at 03:31 PM
1

You are dealing with double byte. If you read your <fc> as hex 41 00 - that is the ASCII equivalent of 65 00. You will have to convert the first 2 numbers from hex to ascii and then ignore the rest. Try this instead

DATA(ascii) = cl_abap_conv_in_ce=>uccp( 'A' ).

Also, see all the wiki on code page conversions Character encoding conversion - ABAP Development - SCN Wiki. If for some reason, you change your mind and want to work with the hex... you can try this snippet. When you create the conversion object, you optionally can change the code-page too.

DATA(o_conv) = cl_abap_conv_out_ce=>create( ).

o_conv->convert(
  EXPORTING
    data        = 'ABC'    " Field to Be Converted
  IMPORTING
    buffer      = DATA(buffer)    " Converted Data
).

WRITE buffer.
Share
10 |10000 characters needed characters left characters exceeded