Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

string Contains only digits

Former Member
0 Likes
46,071

Hi Guys,

I have a string = 8425-67123

I need to put a validation which says " enter only digits " if anything other than a digit is entered.

How do i check if anything other than a digit is entered ( in the above case " - " should not be allowed ).

Thanks and regards,

Frank

14 REPLIES 14
Read only

Former Member
0 Likes
14,856

Hi,

You can check it with CO(contains only)

Regards,

jaya

Read only

Former Member
0 Likes
14,856

consider this eg:

v_var = 8425-67123

if v_var CO '0123456789'.

write:success.

else.

write:/ error message.

endif.

Read only

Former Member
14,856

hi,

Use

if str1 CO '0123456789'.
process
else.
message.
exit
endif

 if str1 CN  '0123456789'.
message.
exit
else.
process
endif

 if str1 CA  sy-abcde.
message.
exit
else.
process
endif

Use any of the above three conditions to achieve your purpose. It would resolve.

Thanks and regards

Sharath

Read only

Former Member
0 Likes
14,856

Try this

if string CA sy-abcde.

<<<<<<<<<error message>>>>>>>>>>>

endif.

Read only

Former Member
0 Likes
14,856

Hi,

Try this

declare a constant like this

DATA: c_string(59) TYPE c VALUE

'ABCDEFGHIJKLMNÑOPQRSTUVWXYZ!"#$%&/()=?¡*¨][_:;^`~|°¬ÁÉÍÓÚ´'.

Now check check whether the entered value has any of thiese.

if g_var ca c_string.

message 'Enter only digits' type 'E'.

endif.

Regards,

Venkatesh

Read only

Former Member
0 Likes
14,856

Hi Frank

{code]

IF string CO '0123456789'.

ELSE.

*display error

ENDIF.

{code}

Pushpraj

Read only

huseyindereli
Active Contributor
0 Likes
14,856

Hi Guys,

I have a string = 8425-67123

I need to put a validation which says " enter only digits " if anything other than a digit is entered.

How do i check if anything other than a digit is entered ( in the above case " - " should not be allowed ).

Thanks and regards,

Frank

Hi ,

Use Function Module NUMERIC_CHECK.

call function 'NUMERIC_CHECK'

exporting

string_in = lv_str

importing

htype = lv_type

.

      • NUMC or NOT

if lv_type eq 'NUMC'.

clear p_del.

else.

p_del = 'X'.

endif.

Edited by: Hüseyin Dereli on Feb 16, 2009 8:59 AM

Edited by: Hüseyin Dereli on Feb 16, 2009 9:00 AM

Read only

Former Member
0 Likes
14,856

Hi Frank,

Try to use FM NUMERIC_CHECK

Also refer the following thread:

Regards,

Nitin.

Read only

Former Member
0 Likes
14,856

You can use this FM for your requirement,

CALL FUNCTION NUMERIC_CHECK.

Regards,

Joan

Read only

Former Member
0 Likes
14,856

eg:

data : v_va type string .

v_var = 8425-67123

if v_var CO '0123456789'.

logic......

else.

endif.

Regards

Read only

Former Member
0 Likes
14,856

Hi,

Do like this...

parameters:

p_num(6) type n.

data

DATA:

w_str(36) TYPE c VALUE '0123456789'.

IF p_num CO w_str

MESSAGE 'Only Numbers Allowed in this Fields'(009) TYPE 'S'.

endif.

Regards

Kiran

Read only

Former Member
0 Likes
14,856

Hi

You can use any one condition

If string CO '0123456789' .

message 'SUCCESS' type 'S'.

endif.

if string CA sy-abcde.

message 'ERROR' type 'E'.

endif.

Regards,

Rajani

Read only

Former Member
0 Likes
14,856

Hi Frank,

this may help.....


if str CO '1234567890'.

PROCEED.....
else.
MESSAGE 'invalid input' type 'E'.
endif.

Regards,

Mdi.Deeba

Read only

Former Member
0 Likes
14,856

hi!

try this,

DATA: w_str(72) TYPE C Value
'ABCDEFGHIJKLMNÑOPQRSTUVWXYZ!"#$%&/()=?¡*¨][_:;^`~|°~*%$#@(){}[]<>,.?/_-'.

if w_no ca w_str.
message 'Error' type 'E'. 
else.
---------------------------(processing of ur code)
endif.