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: 

Fast conversion from 0..25 to a..z

rainer_hbenthal
Active Contributor
0 Kudos

Hi,

i need a very fast conversion from

0 => A

1 => B

2=> C

.

.

.

25=> Z

It can be done via a case statement, but this is rather slow. Performance analysis shows that this is the third time consuming process. So i need a rather fast conversion routine.

A hash table is faster, but still it takes a long time. From other programming languages i know the function ORD which gives back the ascii value of the character. Subtracting 64 will give the wanted vonversion routine, but i cant find a function similar to ORD. Any other ideas to do the conversion?

1 ACCEPTED SOLUTION

Clemenss
Active Contributor
0 Kudos

Hi Rainer,

the offset solution will be fastest:

lv_letter = sy-abcde+lv_number(1).

will give exactly what you want: character field lv_letter stortes the letter for integer value lv_number for values 0..25 as in your example.

Regards,

Clemens

P.S.: If there is anything faster than this, I'd eat my shoes

Message was edited by:

Clemens Li

3 REPLIES 3

Former Member
0 Kudos

hi,

try this

a = 'ABCD..XYZ'.

DO 26 times.

l_index = sy-index - 1.

wa-var = a+l_index(1).

Append wa to itab.

clear wa.

ENDDO.

Regards,

Atish

former_member188827
Active Contributor
0 Kudos

first populate an internal table with values from a to z. and den use following logic:

PARAMETERS:zchar type c.

data:BEGIN OF it OCCURS 0,

zch(1) TYPE c,

end of it.

data zint type i.

it-zch = 'A'.

APPEND it.

it-zch = 'B'.

APPEND it.

it-zch = 'C'.

APPEND it.

it-zch = 'D'.

APPEND it.

it-zch = 'E'.

APPEND it.

READ TABLE it with key zch = zchar.

zint = sy-tabix - 1.

WRITE / zint.

plz reward points if dis helps

Clemenss
Active Contributor
0 Kudos

Hi Rainer,

the offset solution will be fastest:

lv_letter = sy-abcde+lv_number(1).

will give exactly what you want: character field lv_letter stortes the letter for integer value lv_number for values 0..25 as in your example.

Regards,

Clemens

P.S.: If there is anything faster than this, I'd eat my shoes

Message was edited by:

Clemens Li