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

validation for NAME

Former Member
0 Likes
2,905

Hi all,

i have a selection screen for Name.

select-options: s_name for kna1-name1.

i want to do validations for the name, like...

actually the name in the Database contains combination of numbers and characters. (123reyon, etc)

if i ener only the numbers and it should give a error message ' Please enter a valid name'.

how to do this .

Vimala.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,485

Hi

It's not easy because the S_NAME is a range (select-options) so it can be several combinations, u can try to use something like this:

IF S_NAME-LOW CO (0123456789).
----> message
ENDIF.

but u need to checj the field S_NAME-HIGH too

Max

22 REPLIES 22
Read only

Former Member
0 Likes
2,485

Hi KR,

Use CO (ContainsOnly) string operation.

Check the below code which may helps you.


IF S_NAME CO '0123456789'.
  MESSAGE E001(ZMSG) 'Please enter a valid name'.
ENDIF.

Thanks,

Vinay

Read only

Former Member
0 Likes
2,485

HI,

KNA1-NAME1 is the char field and it can take either number's or Alphbets.

why do you want to validate the name field ?

Read only

Former Member
0 Likes
2,486

Hi

It's not easy because the S_NAME is a range (select-options) so it can be several combinations, u can try to use something like this:

IF S_NAME-LOW CO (0123456789).
----> message
ENDIF.

but u need to checj the field S_NAME-HIGH too

Max

Read only

0 Likes
2,485

HI all,

i have written some thing like this. but its not giving me error message when i am trying to enter any numbers.

TABLES: kna1.

SELECT-OPTIONS: s_name for kna1-name1.

AT SELECTION-SCREEN .

if s_name-low co '0123456789'.

if sy-subrc = 0.

MESSAGE e001(00) with 'Enter valid name'.

ENDIF.

ELSEIF s_name-HIGH co '0123456789'.

if sy-subrc = 0.

MESSAGE e001(00) with 'Enter valid name'.

ENDIF.

ENDIF.

Read only

0 Likes
2,485

No need to check SY-Subrc inside the IF ....CO.

Edited by: Micky Oestreich on May 26, 2009 8:13 AM

Read only

0 Likes
2,485

no need to check sy-subrc eq 0 again I suppose.

Read only

0 Likes
2,485

Hi all,

thanks for response.

now my code looks like this, but still i am unable to give Error message.

TABLES: kna1.

SELECT-OPTIONS: s_name for kna1-name1.

AT SELECTION-SCREEN .

if s_name-low co '0123456789'.

MESSAGE e001(00) with 'Enter valid name'.

ELSEIF s_name-HIGH co '0123456789'.

MESSAGE e001(00) with 'Enter valid name'.

ENDIF.

Read only

0 Likes
2,485

Hi.,

It will works in you rcase,

TABLES: kna1.

SELECT-OPTIONS: s_name for kna1-name1.

AT SELECTION-SCREEN .
if not s_name-low ca 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm'.
if sy-subrc = 0.
MESSAGE e001(00) with 'Enter valid name'.
ENDIF.
ELSEIF not s_name-HIGH ca 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm'.
if sy-subrc = 0.
MESSAGE e001(00) with 'Enter valid name'.
ENDIF.
ENDIF.

Thanks,

Naveen.I

Read only

0 Likes
2,485

'0123456789 ' (After the '9', enter at least one space).

Add the space character to it.

The name on the screen does not only hold the digits, but there are several 'spaces' in it as well. So NAME does not ONLY contain digits, but spaces as well.

Edited by: Micky Oestreich on May 26, 2009 8:22 AM

Edited by: Micky Oestreich on May 26, 2009 8:23 AM

Read only

0 Likes
2,485
TABLES: kna1.               " avoid using tables statement . its obsolete 
 
SELECT-OPTIONS: s_name for kna1-name1.
 
AT SELECTION-SCREEN .
if not s_name-low ca 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm'.
MESSAGE e001(00) with 'Enter valid name'.
ELSEIF not s_name-HIGH ca 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm'.
MESSAGE e001(00) with 'Enter valid name'.
ENDIF.

but still it will work only for one line.

u need to loop if u want for all lines of the select option

Read only

0 Likes
2,485

Soumya,

but still it will work only for one line.

u need to loop if u want for all lines of the select option

that's my thought as well, but the way you are suggesting, it would be better to use a regular expression. Then there is no need to enter all the characters UPPER and lower case.

Read only

0 Likes
2,485

change it to :

if s_name-low co


*'0123456789 '*.


TABLES: kna1.

SELECT-OPTIONS: s_name for kna1-name1.

AT SELECTION-SCREEN .
 condense: s_name-low ,  condense s_name-high.
if s_name-low co '0123456789 '.
MESSAGE e001(00) with 'Enter valid name'.


ELSEIF s_name-HIGH co '0123456789 '.
MESSAGE e001(00) with 'Enter valid name'.
ENDIF.

Edited by: madhuri sonawane on May 26, 2009 11:59 AM

Edited by: madhuri sonawane on May 26, 2009 12:00 PM

Edited by: madhuri sonawane on May 26, 2009 12:00 PM

Read only

0 Likes
2,485

yes i just copies the above code to show the difference..

u can very well use the regular expressions.

Read only

0 Likes
2,485

Hi all,

thanks for your response.

Thing is, in my Database some name are like combination of numbers and characters and some names are oonly characters..

example: 28th Medical Colony, 121st Combat Support Hospital ( Name , combination of numbers and characters)

Raja Ram (name, combination of characters only.).

i want to do avalidatin, like, if user enters only numbers, then it should through a Error message.

*************************************************************

the below code is working, if enter only numbers, say 1132424, then i am getting error message,

if i enter 28th Medical Colony, then also i am getting the error message, which coulnnot be happen in my case.

SELECT-OPTIONS: s_name for kna1-name1.

AT SELECTION-SCREEN .

if s_name-low co '0123456789 '.

  • if sy-subrc = 0.

MESSAGE e001(00) with 'Enter valid name'.

  • ENDIF.

ELSEIF s_name-HIGH co '0123456789 '.

  • if sy-subrc = 0.

MESSAGE e001(00) with 'Enter valid name'.

  • ENDIF.

ENDIF.

***************************************************************

Thanks

Read only

0 Likes
2,485

please check the previous page. we have already provided u the solution

Read only

0 Likes
2,485

Hi,

This is working fine,

tables: kna1.

select-options: s_name for kna1-name1.

at selection-screen .
if s_name-low is not initial.
if not s_name-low ca 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm'.
message e001(00) with 'Enter valid name'.
endif.
endif.
if s_name-high is not initial.
if not s_name-high ca 'QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm'.
message e001(00) with 'Enter valid name'.
endif.
endif.

RESULT: This will not allow user to give only NUMBER, He can enter either only Characters or characters with Numbers.

Thanks,

Naveen Inuganti.

Read only

0 Likes
2,485

Why not you write a select to check whether the entered name is in database or not and issue a error message ????

Regards

Karthik D

Read only

0 Likes
2,485

I too agree with Karthik

Read only

0 Likes
2,485

Hi Navven,

Thank you very much. its working.

Thing is its a select-options. so, we can give range of names, and what ever the names are there in data base that only fetched. right.

if, they entering a single value , not the range say only from value,

if they enter only numbers, then they need a Error message.

Thank you veru much all of you .

points hasbeen awarded.

Read only

Former Member
0 Likes
2,485

Hi,

try this.

AT SELECTION-SCREEN .
IF s_name-low NA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
  MESSAGE e001(00) WITH 'Enter valid name'.
ENDIF.
ELSEIF s_name-high CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.
  MESSAGE e001(00) WITH 'Enter valid name'.
ENDIF.

Regards

Vishnu Gupta

Read only

Former Member
0 Likes
2,485

Hi,

Below is the code. Can you try this?

TABLES: kna1.

SELECT-OPTIONS: s_name for kna1-name1.

AT SELECTION-SCREEN .

if s_name-low co '0123456789 '.

MESSAGE e001(00) with 'Enter valid name'.

ELSEIF s_name-HIGH co '0123456789 '.

MESSAGE e001(00) with 'Enter valid name'.

ENDIF.

I hope you wont get error.

Regards,

Jayanth G

Read only

0 Likes
2,485

I guess you will have to do the above logic within a LOOP AT so_fielname (selection option). ENDLOOP.

As Selection option works as an internal table, it will have many records and you might have to validate the whiole stuff.. Else only yeh first low and high of the current values will be validated. Correct me if I am wrong.

Regards,

S.Dakshna Nagaratnam.