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 validation

Former Member
0 Likes
702

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?

5 REPLIES 5
Read only

Former Member
0 Likes
623

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

Read only

andreas_mann3
Active Contributor
0 Likes
623

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 numeric

A.

Read only

Former Member
0 Likes
623

If lstr CA Sy-abcde.

-> dont do any calculation.

else.

-> do your calculation.

endif.

Read only

Former Member
0 Likes
623

Hi

Alternatively you can use FM: <b>CATS_NUMERIC_INPUT_CHECK</b> for the same or even: <b>NUMERIC_CHECK</b>

Kind Regards

Eswar

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
623

Hi,

One simple way is this.

If var CO `0123456789`.

  • this contains only numerics

else.

endif.

Regards,

Sesh