Application Development 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: 

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

tennisfanvenkat
Participant
0 Kudos

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

7 REPLIES 7

Former Member
0 Kudos

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.

0 Kudos

I tried CA but then special characters can come in it...then it fails...

0 Kudos

Please give any example of special characters so I understand the situation.

Former Member
0 Kudos

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.

former_member196601
Active Participant
0 Kudos

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

rajkumarnarasimman
Active Contributor
0 Kudos

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

jayanthi_jayaraman
Active Contributor
0 Kudos

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.