2013 May 06 2:27 PM
FORM IsNumeric.
DATA: numeric(10) TYPE C VALUE '0123456789 ',
account(10) TYPE C VALUE '600',
rc TYPE C.
IF account CO numeric.
rc = ''.
ELSE.
rc = 'X'.
ENDIF.
ENDFORM.
The result is rc = 'X'
Where I'm wrong?
Regards,
Mioa
2013 May 06 2:38 PM
Hi,
your variable account(10) TYPE C VALUE '600'. Is of length 10 so account is actually ' 600' i.e. with 7 spaces in the value. but your string '0123456789 ' does not have space as the length is 10 so the space is truncated, so numeric = '0123456789' all total 10 chars the space is missing due to length. If numeric is of length 11 it will work.
Cheers,
Arindam
2013 May 06 2:38 PM
Hi,
your variable account(10) TYPE C VALUE '600'. Is of length 10 so account is actually ' 600' i.e. with 7 spaces in the value. but your string '0123456789 ' does not have space as the length is 10 so the space is truncated, so numeric = '0123456789' all total 10 chars the space is missing due to length. If numeric is of length 11 it will work.
Cheers,
Arindam
2013 May 06 2:40 PM
Try this code .
DATA: numeric(10) TYPE C VALUE '0123456789 ',
account(3) TYPE C VALUE '600',
rc TYPE C.
IF account CO numeric.
rc = ''.
ELSE.
rc = 'X'.
ENDIF.
ENDFORM.
2013 May 06 2:41 PM
Mio,
If the value for account was '0000000600' your code will work fine. Try as per below:
DATA: numeric(10) TYPE C VALUE '0123456789 ',
account(10) TYPE C VALUE '600',
len type char10,
rc TYPE C.
condense account.
len = strlen ( account ).
IF account+0(len) CO numeric.
rc = ''.
ELSE.
rc = 'X'.
ENDIF.
This should solve your issue.
Thanks,
Vikram.M
2013 May 06 2:51 PM
Hi Mio,
Check if this below function module helps you.
NUMERIC_CHECK
Regards,
Santanu.
2013 May 06 4:58 PM
Hi,
you can see this example:
REPORT z_check_string.
DATA: account(10) TYPE c VALUE '2001',
rc TYPE c,
lung TYPE i,
pos TYPE i,
char(1).
lung = strlen( account ).
DO lung TIMES.
char = account+pos(1).
IF char CO '0123456789'.
*here if you want you can move char into others flow..............
ELSE.
rc = 'X'.
EXIT.
ENDIF.
pos = pos + 1.
ENDDO.
WRITE rc.
I hope that this example helped you and solve your issue.
Regards
Ivan
2013 May 07 1:49 AM
To make use of more modern ABAP I'd rather write:
DATA: numeric(11) TYPE C VALUE '0123456789 ', "as suggested by arindam
account(10) TYPE C VALUE '600',
rc TYPE C.
rc = boolc( account CO numeric ).
boolc returns a boolean for the given expression.
Cheers,
Custodio