‎2006 Nov 03 9:03 AM
Hi.
i have one variable type string.
i want to validate these variable such that when it contain numeric value then only it should proceed as i have to use for calculation.
in it contain char then it should out from condition.
how to do this?
‎2006 Nov 03 9:06 AM
Check out below code. It will help you.
data: str(100) type c.
data: str_n type string.
data: str_c type string.
data: str_d type string.
data: str_p type string.
data: len1 type i.
data: ofst1 type i.
str = '#ABCD%123'.
len1 = strlen( str ).
do.
if ofst1 = len1.
exit.
endif.
if str+ofst1(1) co sy-abcde .
concatenate str_c str+ofst1(1) into str_c.
elseif <b>str+ofst1(1) co '0123456789'</b> .
concatenate str_p str+ofst1(1) into str_p.
else.
concatenate str_d str+ofst1(1) into str_d.
endif.
ofst1 = ofst1 + 1.
enddo.
Best Regards,
Vibha
*Please mark all the helpful answers
‎2006 Nov 03 9:40 AM
hi,
try:
data str type string.
data p_field type p decimals 2.
CATCH SYSTEM-EXCEPTIONS conversion_errors = 1.
MOVE str to p_field.
ENDCATCH.
IF sy-subrc EQ 1.*not numericA.
‎2006 Nov 03 10:02 AM
If lstr CA Sy-abcde.
-> dont do any calculation.
else.
-> do your calculation.
endif.
‎2006 Nov 03 10:09 AM
Hi
Alternatively you can use FM: <b>CATS_NUMERIC_INPUT_CHECK</b> for the same or even: <b>NUMERIC_CHECK</b>
Kind Regards
Eswar
‎2006 Nov 03 10:15 AM
Hi,
One simple way is this.
If var CO `0123456789`.
this contains only numerics
else.
endif.
Regards,
Sesh