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: 

Convert integer to letter ASCII

Former Member
0 Kudos

How can I turn a number into a letter?

For example if I have i = 65 that it one turns into one 'A'.

I have tried to look for something in the forum but I have not found anything that works.

Thanks!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Take a look at class CL_ABAP_CONV_IN_CE - method UCCP will take hex 0041 as input and return A as output, method UCCPI will take decimal 65 and return A. Other methods provide the functionality for more complicated scenarios.

There is also class CL_ABAP_CONV_OUT_CE - method UCCPI takes A as input and returns 65.

These are documented online under ABAP keyword documentation (the little blue i button in SE38) under ABAP - by Theme,

ABAP System Classes and Interfaces, Classes for Converting Character Sets and Number Formats.

Andrew

12 REPLIES 12

Former Member
0 Kudos

Well, they're not the same thing and basically incompatible. Could you please give more information?

Rob

0 Kudos

I have seen this code that it should write 'A' but it does not work.

data : i type i value 65.
data : x type x.
field-symbols : <fc> type c.
move i to x.
assign x to <fc> casting type c.
move <fc> to c.
write c.

0 Kudos

It worked for me when I tried it (after adding):

DATA: c(1).

at the top.

Rob

0 Kudos

returns sintax error;

The length of "X" in bytes must be a multiple of the size of a Unicode

character (regardless of the size of the Unicode character).

This is the code I use;

DATA: c(1).
data : i type i value 65.
data : x type x.
field-symbols : <fc> type c.
move i to x.
assign x to <fc> casting type c.
move <fc> to c.
write c.

0 Kudos

I see - for some reason, the "Unicode code checks" was clicked off in my test program.

Rob

Former Member
0 Kudos

DATA: c(2) type c.

data : i type i value 65.

data : x type x.

field-symbols : <fc> type x.

move i to x.

assign x to <fc> CASTING.

move <fc> to c.

write c.

you can write ur code like this.

0 Kudos

Thansk, but...

the result is '41' not 'A'....

0 Kudos

The FM URL_ASCII_CODE_GET does the opposite, you put an 'A' as input and returns '41' (65 in hex)

But, how do the opposite?

Former Member
0 Kudos

Take a look at class CL_ABAP_CONV_IN_CE - method UCCP will take hex 0041 as input and return A as output, method UCCPI will take decimal 65 and return A. Other methods provide the functionality for more complicated scenarios.

There is also class CL_ABAP_CONV_OUT_CE - method UCCPI takes A as input and returns 65.

These are documented online under ABAP keyword documentation (the little blue i button in SE38) under ABAP - by Theme,

ABAP System Classes and Interfaces, Classes for Converting Character Sets and Number Formats.

Andrew

0 Kudos

Thanks Andrew !

This is the solution;

DATA: num(4) TYPE c VALUE '0041'.

DATA: c TYPE C.

c = CL_ABAP_CONV_IN_CE=>uccp( num ).

WRITE c.

venkat_o
Active Contributor
0 Kudos

Hi, <li>Here is the sample program which Converts Letter to ASCII and ASCII to Letter.


REPORT ztest.
"Going from A to 65
DATA : c  TYPE c VALUE 'A'.
DATA : rn TYPE i.
FIELD-SYMBOLS : <n> TYPE x.
ASSIGN c TO <n> CASTING.
MOVE <n> TO rn.
WRITE:/ rn.
"Going from 66 to B
DATA : i TYPE i VALUE 66.
DATA : x TYPE x.
FIELD-SYMBOLS : <fc> TYPE c.
MOVE i TO x.
ASSIGN x TO <fc> CASTING TYPE c.
MOVE <fc> TO c.
WRITE:/ c.
Thanks Venkat.O

jijo_jacob
Member
0 Kudos

This will print A..Z in Unicode as well

DATA: c(4) TYPE c.

DATA : i TYPE i VALUE 65.

DATA : x(4) TYPE x.

FIELD-SYMBOLS : <fc> TYPE c.


DO.

  MOVE i TO x.

  ASSIGN x TO <fc> CASTING.

  MOVE <fc> TO c.

  WRITE:  c+3(1), ' '.

  ADD 1 TO i.

  IF i > 90.

    EXIT.

  ENDIF.

ENDDO.