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

Determining number

Former Member
0 Likes
712

Hi,

I would like to know is there any simple code that would able to let me to see whether an input is an integer or is a character. For example, isNumber(0012) would return true and isNumber(CRMD) would return false.

Thanks a lot!

Regards,

Anyi

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
681

You can try something like this.



report zrich_0001.


data: value type string.
data: len type i.

value = '12348a'.
len = strlen( value ).

if value+0(len) co '1234567890'.
  write:/ 'This is a numeric value'.
else.
  write:/ 'This is not a numeric value'.
endif.

Regards,

Rich Heilman

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
682

You can try something like this.



report zrich_0001.


data: value type string.
data: len type i.

value = '12348a'.
len = strlen( value ).

if value+0(len) co '1234567890'.
  write:/ 'This is a numeric value'.
else.
  write:/ 'This is not a numeric value'.
endif.

Regards,

Rich Heilman

Read only

sridhar_k1
Active Contributor
0 Likes
681

Function module NUMERIC_CHECK returns NUMC for numeric and CHAR for character inputs.

Regards

Sridhar

Read only

Former Member
0 Likes
681

you can use the function module:

NUMERIC_CHECK:

sample code:

DATA: TYPE LIKE DD01V-DATATYPE.

CALL FUNCTION 'NUMERIC_CHECK'

EXPORTING

STRING_IN = VALUEIN

IMPORTING

STRING_OUT = HFELD

HTYPE = TYPE.

IF TYPE EQ 'NUMC'.

write:/ 'Numeric'.

else.

write:/ 'not numeric'.

ENDIF.

Regards,

ravi

Read only

Former Member
0 Likes
681

U can even use the logic..

IF linput CA sy-abcde.

write : / 'Non-numberic'.

else.

write : / 'Numeric'.

endif.

Regards

Anurag

Read only

Former Member
0 Likes
681

This should get you all the data about a field that you require:


REPORT  zz_temp.

DATA:  g_i TYPE i.
DATA:  g_c(20) TYPE c.
DATA   g_type TYPE c.
DATA   g_len TYPE i.


DESCRIBE FIELD g_i TYPE g_type.
WRITE: / g_type.

DESCRIBE FIELD g_c TYPE g_type LENGTH g_len..
WRITE: / g_type, g_len.