cancel
Showing results for 
Search instead for 
Did you mean: 

FM FOR NUMERIC CHECK

Former Member
0 Kudos

Hello All,

Is there any FM present to check if a value is numeric and does not contain any alphanumeric or character values?

Thanks,

Accepted Solutions (1)

Accepted Solutions (1)

former_member181962
Active Contributor
0 Kudos

HI,

Use the 'CO' option. Contains only

if v_str co '0123456789'.

write:/ ' Its a pure number'.

else.

write:/ ' Its not a pure number'.

endif.

Regards,.

Ravi

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

If you are using a character field and do not want to compinsate for the SPACE in the field. You can do something like this as well.



report zrich_0001 .


data: field(10) type c value '1%56539'.
data: length type i.


length = strlen( field ).

if field(length) co '1234567890'.
  write:/ 'This is a number'.
else.
  write:/ 'This is not a number'.
endif.

Regards,

Rich Heilman

Answers (5)

Answers (5)

former_member378318
Contributor
0 Kudos

No need for a FM use the CATCH command to generate a CONVT_NO_NUMBER error for non numeric fields:

DATA I TYPE I.

      • CONVERSION_ERRORS contains CONVT_NO_NUMBER ***

CATCH SYSTEM-EXCEPTIONS CONVERSION_ERRORS = 1.

MOVE 'abc' TO I. " <- Error: CONVT_NO_NUMBER

ENDCATCH.

IF SY-SUBRC = 1.

...

ENDIF.

Former Member
0 Kudos

Thanks everyone..!! I wanted to make sure that the preffered ways is to use CO and CA. Looks like it is. Thanks much again.

andreas_mann3
Active Contributor
0 Kudos

hi ,

look here

Andreas

govind_seenivasan
Participant
0 Kudos

Check FM NUMERIC_CHECK and also check this thread :

Former Member
0 Kudos

NUMERIC_CHECK?

Rob

Former Member
0 Kudos

Actually, I don't think FM NUMERIC_CHECK will do what you want, but you also have to consider whether or not you want to consider commas and periods.

rob

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You don't need a function module. Just check it with an if statement.

If field CO '1234567890'.
* Then its ok.
else.
* Then its not ok.
Endif.

Regards,

Rich Heilman