‎2007 Aug 30 7:18 PM
Hi,
Is it a complicated process to convert char3 to numc3?
Thanks,
Georgy
‎2007 Aug 30 7:21 PM
‎2007 Aug 30 7:24 PM
Hi Rich,
I am not sure it'll work. Here is an example:
DATA: numc TYPE numc3.
DATA: char TYPE char3.
char = 'AOB'.
numc = char. <-this will fail
this is in a way is what you are trying to do, I assume.
Thanks,
Gerogy
‎2007 Aug 30 7:27 PM
It will NOT fail, it will simply only move the numeric value to the numeric field. So if I make it A3B, you can see that the 3 is moved to the numeric, you can not move non-numeric values to a numeric field, this is fundamentals of programming.
report zrich_0001.
data: numc type numc3.
data: char type char3.
char = 'A3B'.
numc = char.
write:/ numc.
Regards,
RIch Heilman
‎2007 Aug 30 7:21 PM
Hi Georgy,
Type C and Type n are interconvertible..
But the only thing is: If your char type field has Alphanumeric chars, then only the numeric chars will be copied in type N field...
Thanks and Best Regards,
Vikas Bittera.
**Reward if useful**
‎2007 Aug 30 7:22 PM
Hi,
report zars.
data : v_char(3) type c.
data : v_numc(3) type n.
v_char = 'A23'.
write v_char to v_numc.
write v_numc.
aRs
‎2007 Aug 30 7:25 PM
DATA : w_a(10) TYPE c,
w_b(10) TYPE n.
w_a = '12345'.
w_b = w_a. ( w_b will be '0000012345' )
w_a = 'A12345'.
w_b = w_a. ( '0000012345')
alphanumeric char will be ignored.
Thanks and Best Regards,
Vikas Bittera.
**Reward if useful**
‎2007 Aug 30 7:28 PM
Hi Vikas,
This is the point. I need to convert chars to numbers such as A to a digit. Is it possible?
Thanks,
Georgy
‎2007 Aug 30 7:29 PM
‎2007 Aug 30 7:30 PM
Hi Georgy,
Do you have any specific value to be put for 'A' or any other char??? tell me the same.. i feel by replace this will be possible..
Thanks and Best Regards,
Vikas Bittera.
**Reward if useful**
‎2007 Aug 30 7:33 PM
IF that is the case, you can do something like this.
report zrich_0001.
data: numc type numc3.
data: char type char3.
data: str type string.
char = 'A3B'.
do 3 times.
sy-index = sy-index - 1.
case char+sy-index(1) .
when 'A'. char+sy-index(1) = '1'.
when 'B'. char+sy-index(1) = '2'.
when 'C'. char+sy-index(1) = '3'.
when 'D'. char+sy-index(1) = '4'.
when 'E'. char+sy-index(1) = '5'.
when 'F'. char+sy-index(1) = '6'.
when 'G'. char+sy-index(1) = '7'.
when 'H'. char+sy-index(1) = '8'.
when 'I'. char+sy-index(1) = '9'.
endcase.
enddo.
numc = char.
write:/ numc.
Regards,
Rich Heilman
‎2007 Aug 30 7:35 PM
‎2007 Aug 30 7:40 PM
Hi Rich,
I have to disagree with you on the point that you say this is a general principle of programming. In Java for instance you can split a string in to chars and convert each to a short (if I remeber it correctly). In addition it should be possible to convert each char to an ASCII representation and store it in int. Anyhow, I thought that ABAP might have something similar like that where I can execute a function module simply to convert char to an integer. Yes, it is possible to assign number to letters and than code up the logic (as you suggested) but I do not want to handle it myself. I was hoping there is a function module for it.
Thanks for you input though.
Georgy
‎2007 Aug 30 7:44 PM
‎2007 Aug 30 7:46 PM
Hi Rich,
Gotcha 😃
Thanks for helping.
P.S. It would be nice to have some utilities like that in ABAP.
‎2007 Aug 30 7:50 PM
I agree, it would be nice. You might find this link of some interest.
http://www.sap-img.com/abap/how-can-i-get-ascii-value-of-any-letter.htm
Regards,
Rich Heilman
‎2007 Aug 30 7:51 PM