Skip to Content

A field to be validated as having only numbers of type char03

Hi All,

I'm uploading an XL file.

One field needs to be validated as having only numbers between '1' and '999'. It is of type char 3.

I tried LV_NUM CO '0123456789', but it does not work for single character numbers like '1'.

Please help.

Thanks,

Venkat

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • avatar image
    Former Member
    Dec 22, 2014 at 05:29 PM

    Hi venkat,

    You can try CA instead of CO.

    Sample code:

    DATA: LV_NUM TYPE c LENGTH 3 VALUE '1'.

    IF LV_NUM CA '0123456789'.
       WRITE: / 'CONTAINS'.
    ELSE.
       WRITE: / 'NOT CONTAINS'.
    ENDIF.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 23, 2014 at 12:41 AM

    For single charcter numbers the variable is also considering the trailing spaces as the character length is C. You probably need to truncate the trailing spaces or define as string.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 23, 2014 at 02:27 AM

    Hi Venkat,

    You will have to probably try as below: You will have to give a space as below:

    LV_NUM CO '0123456789 '.


    Thanks,

    Naveen

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 23, 2014 at 04:04 AM

    Hi Venkat,

    Please find the below code.

    DATA: LV_NUM TYPE CHAR3.
    LV_NUM = '12'.
    IF  LV_NUM CO '0123456789 '.   "Add empty space after 9... 
       WRITE 'EQUAL'.
    ELSE.
       WRITE 'NOT EQUAL'.
    ENDIF.
    

    Also find the link below for string comparison

    String Comparison operators - ABAP Development - SCN Wiki


    Regards


    Rajkumar Narasimman

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 23, 2014 at 04:58 AM

    Hi,

    Try with CO.

      DATA: LV_NUM TYPE c LENGTH 3 VALUE '123'.

    IF LV_NUM CO '0123456789'.
       WRITE: / 'CONTAINS'.
    ELSE.
       WRITE: / 'NOT CONTAINS'.
    ENDIF.

    It will not consider special characters.

    Add comment
    10|10000 characters needed characters exceeded