10-28-2008 11:40 AM
We have a string as an input.
We need to check if it contains any characters other than digits ( ie. 0123456789) The other characters could be special characters, albhabets etc.
Please suggest any RFC / Logic to get this .
Rohit
10-28-2008 11:44 AM
IF string CO '0123456789'.
==> only digits
ELSE.
==> not just digits (could be space as well)
ENDIF.
10-28-2008 11:41 AM
if lv_str CA '0123456789'
else.
endif.
use CA option in ur case..
vijay
10-28-2008 11:44 AM
IF string CO '0123456789'.
==> only digits
ELSE.
==> not just digits (could be space as well)
ENDIF.
10-28-2008 11:54 AM
Suppose string = '1234ABCD'.
Then your logic will give results that the string contains digits/
My requirement is that we have to raise an error if the string contains any thing other than digits.
Please help
10-28-2008 12:00 PM
string = '1234ABCD'.
if string ca '0123456789 '
write 'ok'
else.
message ' string contains non numeric fields.
endif.
so trigger the message in the else part .
10-28-2008 12:02 PM
Eric's solution (CO) works just fine, sniper's (CA) is wrong, at least for your requirement here.
CO = "contains only", CA = "contains any".
Thomas
P.S. you could also use CN "contains not only" and switch the IF/ELSE-parts around, if you prefer...
10-28-2008 12:03 PM
10-28-2008 12:17 PM
if you know the solution better, than why ask at all?
if you get different replies, why don't you try them and see if works or not?
CA stands for contains any
IF string CA '0123456789'
it will be true if the string contains at least one digit
IF string CA '0123456789'
==> the string contains at least one digit
ELSE.
==> the string does NOT contain any digit (however could contain space or special characters)
ENDIF.
CO stands for contains only
IF string CO '0123456789'
it will be true if the string contains only digits
IF string CO '0123456789'
==> the string contains only digits
ELSE.
==> the string contains not only digits (could be no digits at all)
ENDIF.
==> the string contains only
</Spoonfeeding>
PS: Thomas: Thanks for your support / Vielen Dank für die Unterstützung!
10-28-2008 11:47 AM
hi,
compare that string with system field sy-abcde..
ex:
data : var type string.
var = '84748291'.
if var CA sy-abcde.
write : 'Hello'.
else.
write : 'NO'.
endif.
.
Rgds.,
subash