Skip to Content
author's profile photo Former Member
Former Member

How to check value is numeric or not

hi how to check whether a value is numeric or not.

example. data : x type n.

x = 12345.

Now how to check whether X contains numeric value or not.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

8 Answers

  • Best Answer
    Posted on Oct 19, 2006 at 10:47 AM

    Hi sam,

    You can use the Function Module:

    numeric_check.

    Usage:

    CALL FUNCTION 'NUMERIC_CHECK'

    EXPORTING

    STRING_IN = X

    IMPORTING

    STRING_OUT = X

    HTYPE = H_TYPE.

    if h_type = 'CHAR'.

    WRITE:/ 'NOt Numeric'.

    else.

    write:/ 'Numeric'.

    ENDIF.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2006 at 10:42 AM

    you could do

    if not x ca sy-abcde.

    .......

    endif.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2006 at 10:42 AM

    If the type is N it would be numeric as it cannot contain an alphabet.

    Secondly lets say if it was of type C.

    you can check it using

    If x CO '0123456789'.

    it is numeric.

    endif.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 19, 2006 at 10:42 AM

    if x co '0123456789'.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2006 at 10:44 AM

    Hi

    IF i_val CN '0123456789 '.

    Message..for not a numeric

    else.

    message...for numeric

    ENDIF.

    Regards,

    Raj

    Message was edited by: Rajasekhar Dinavahi

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 19, 2006 at 10:46 AM

    hi,

    use this functionmodule.

    its accurate.

    CATS_NUMERIC_INPUT_CHECK

    rgds

    anver

    if hlped pls help points

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 19, 2006 at 10:47 AM

    Hi sam,

    try this

    if x CA '0123456789'.

    write : 'Contains Numeric Data'.

    endif.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 19, 2006 at 10:48 AM

    Hi,

    If your type is 'N' there is no way that 'X' can have any value apart for numberics (i.e. 0 - 9).

    You can also check that as follows.

    Data: num_list(10) type c value '0123456789',

    x type n.

    X = '12345'.

    • This is more useful if your X is of type C.

    if X CO num_list.

    • Its only numeric

    else.

    • its contains non numeric

    endif.

    Regards,

    Sesh

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.