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

Checking whether a String only containes numbers

Former Member
0 Likes
8,733

Hi,

I have a string. This can sometimes contain only numbers. Is there and method to check whether the staring is a number?

Thanks

Lilan

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
7,797

Hello Lilan

Simple code:

* String contains only digits
  IF ( string CO '0123456789' ).  " or CO '01234567890 ' including space

  ELSE.

  ENDIF.

Regards

Uwe

6 REPLIES 6
Read only

uwe_schieferstein
Active Contributor
0 Likes
7,798

Hello Lilan

Simple code:

* String contains only digits
  IF ( string CO '0123456789' ).  " or CO '01234567890 ' including space

  ELSE.

  ENDIF.

Regards

Uwe

Read only

Former Member
0 Likes
7,797

Hi

Use this FM

NUMERIC_CHECK

STRING_OUT A123344

HTYPE CHAR

regards

Shiva

Read only

Former Member
0 Likes
7,797

try this demo code -

data l_text type string.

data d1 type i.

data d2 like sy-abcde.

l_text = '12'.

d2 = sy-abcde.

translate d2 to lower case.

if l_text CA sy-ABCDE or

l_text CA d2.

write 'char'.

else.

write ' num'.

endif.

Read only

Former Member
0 Likes
7,797

hi,

u can check like this...

if v_str CO '0123456789'.

---

---

endif.

regards,

priya.

Read only

Former Member
0 Likes
7,797

use

if str co '0123456789'.

endif.

or fm NUMERIC_CHECK.

regards

shiba dutta

Read only

Former Member
0 Likes
7,797

Hi Lilan.

Just follow the foll steps :

1. Declare var1 type d

oref type ref to cx_root.

2. Write the foll code(assuming str is your string )

try.

d = s / 2.

catch cx_sy_conversion_no_number into oref.

endtry.

3. If oref is initial, the string is a number

Else the string has some alphabets.

Ravi