‎2006 Aug 17 2:52 PM
Hello,
please tell me a possibility how i can check if the value of a variable is numeric.
Thank you!
Ronny
‎2006 Aug 17 2:57 PM
‎2006 Aug 17 2:56 PM
Hi,
make a constant
c_numeric type string value ' .,0123456789'.
if value cn c_numeric.
not numeric
else.
numeric
endif.
grtz
Koen
‎2014 Mar 27 5:45 AM
thanks Labie koen, I had the same doubt your answer clarified my doubt.
‎2006 Aug 17 2:57 PM
‎2006 Aug 17 2:58 PM
try this
if var CO '0123456789'.
*var is numeric.
else.
*non numeric.
endif.
‎2006 Aug 17 2:58 PM
Hi ronald,
1. This is one way
2. we can use CO (contains only relational operator)
3. just copy paste
4.
NOTE :
'0123456789. ' (There is a SPACE after .DOT)
report abc.
PARAMETERS : A(15) TYPE C.
<b>if A CO '0123456789. '.</b>
WRITE 😕 'NUMBER'.
ELSE.
WRITE 😕 'NOT A Number'.
ENDIF.
regards,
amit m.
‎2006 Aug 17 2:59 PM
data : v_char(10) type c value '0123456789'.
if v_number CO v_char.
its a number
else.
its not a number
endif.
‎2006 Aug 17 3:00 PM
‎2006 Aug 17 2:59 PM
‎2006 Aug 17 3:00 PM
‎2006 Aug 17 3:01 PM
Hi,
check this :
IF x_data <b>CN</b> '12345 67890'.
write : ' Not a number'.
ELSE.
write : 'Number'.
ENDIF.Regards
Appana
‎2006 Aug 17 3:07 PM
Also, if your field is a fix length and your value does not take up the entire field, you should check the length and check only that part of the field.
report zrich_0001.
data: c(20) type c value '123456'.
data: length type i.
length = strlen( c ).
if c+0(length) co '1234567890'.
write:/ 'It is a numeric'.
else.
write:/ 'It is not a numeric'.
endif.
Regards,
Rich Heilman
‎2006 Aug 17 3:07 PM
‎2013 Oct 23 6:15 AM
Hi,
I want to check for only numeric value for material i.e. if my material contains only numbers then i want to set indicator to Y. I have written following code in field level routine.
DATA: lc_num(12) TYPE c VALUE '0123456789'.
DATA: lv_string TYPE c.
lv_string = SOURCE_FIELDS-MATERIAL .
IF lv_string CO lc_num.
RESULT = 'Y'.
ENDIF.
The problem is when i input '1234' value it sets indicator to Y which is correct,when i input value 'K1234' it sets indicator to blank which is right but when i input value '1234K' it sets indicator to Y which is incorrect as value is not numeric.
Please help.....
‎2013 Oct 23 6:28 AM
Hi Anuradha,
Use 'NUMERIC_CHECK' Function Module to check value is char or int.
Regards
Lingaraj
‎2013 Oct 24 5:02 AM
Hi Lingaraj,
Thanks for your suggestion. I have used NUMERIC CHECK function module and it's working fine.
Regards,
Anuradha
‎2014 Jul 25 8:13 PM
Hello Ronald,
you can try FM - CATS_NUMERIC_INPUT_CHECK [It helps me]
This FM fetches the user's default setting on decimal place.
and then accordingly, classify if entered data is numeric or not.
Infact, this FM is internally used by SAP standard program especially to check quantity value liek ekpo-menge.
this FM is sophisticated enough that it wont allow any alphabets except digits and literals like comma and decimal.
At least it will help one, who comes across this page.
FYI - NUMERIC CHECK [is not good enough to distinguish NUMC and CHAR if u enter comma/deccimal]
Thank you.
best regards,
Rahul Agarwal
‎2023 May 05 5:16 AM
‎2022 Oct 23 7:49 PM
Hello there,
How do we do it using the Numeric_Check function.
‎2023 Sep 13 11:58 AM
Hi everyone,
I know this is an old thread, but maybe someone will come across it anyway. You could try something like this:
DATA(value) = '-20233.44'.
IF value CO '0123456789.,-'.
TRY.
DATA(test) = CONV decfloat16( value ).
DATA(is_numeric) = abap_true.
CATCH cx_sy_conversion_no_number.
is_numeric = abap_false.
ENDTRY.
ENDIF.However, if you'd like date and time values not to be considered as numeric values, the logic above must be extended accordingly.