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: 

Selection Screen

graghavendra_sharma
Contributor
0 Kudos

Hi

i have selection screen like this

SELECT-OPTIONS: S_WERKS LIKE AUFK-WERKS.

how do I validate S_WERKS in AT SELECTION-SCREEN ON s_werks.

pls let me know the exact way.

Thanks & Regards

1 ACCEPTED SOLUTION

Former Member
0 Kudos

It depends on what sort of validation if you wish to carry out.. but one general check can be as describe below.

AT SELECTION-SCREEN ON s_werks.

select werks into table iwerks

from t001w

where werks in s_werks.

describe table iwerks lines lcnt.

if lcnt = 0.

Error - No plants found as per the specified filters

endif.

16 REPLIES 16

Former Member
0 Kudos

Hi,

field aufk-werks has a foreign key in table T001W so it shoul validate automatically.

Rgds,

jose

0 Kudos

Hi

Did you mean it will be validated by the system automatically. My question is if i enter a wrong value, for example "abcd" to "xyza" in from and to fields of S_WERKS, i want to validate against values in T001W. how do i do this.

Thanks for your response

regards

0 Kudos

Please check my post it would do the required as you wish !!

0 Kudos

Hi,

that is what i mean, if you enter wrong values the system will validate them automatically, so you don´t have to write any code.

Rgds,

Jose

0 Kudos

Hi Jose,

I think system will not validate the plants entered in select options automatically. Let me know if I am wrong. Pls give me one example if possible

Regard

Sharma

Former Member
0 Kudos

It depends on what sort of validation if you wish to carry out.. but one general check can be as describe below.

AT SELECTION-SCREEN ON s_werks.

select werks into table iwerks

from t001w

where werks in s_werks.

describe table iwerks lines lcnt.

if lcnt = 0.

Error - No plants found as per the specified filters

endif.

0 Kudos

Hi Anurag,

This is really helpful answer. I have some doubts here.

1. If you see the answer from Santhosh, can't I do my validation in that way.

2. to implement your answer, I need to have an internal table to store all the plants. in this is way i need to do for my other select option variables also. will that not be a performance problem?

3. as you said, how many types of validations we can carry out on this select options. pls let me know

regards

0 Kudos

This is really helpful answer. I have some doubts here.

1. If you see the answer from Santhosh, can't I do my validation in that way.

The problem with that method is that you are using a select-option and hence there can be many variations of input and that could be a problem for validating it individually. example if the use a pattern or between etc. So my solution would give you a list of plants which match the selection criteria. If the count is zero means there are no plants with the selected criteria, whether it be a pattern/between or purely a value.

2. to implement your answer, I need to have an internal table to store all the plants. in this is way i need to do for my other select option variables also. will that not be a performance problem?

Nope it would not impact the performance as it will hardly take a second to validate it.

3. as you said, how many types of validations we can carry out on this select options. pls let me know

The other validations can be something like the particular report is for specific country then you wish the plants only for that country should be entered etc..or the report needs to be executed only for a list of plants...

Regards

anurag

0 Kudos

Hi Anurag,

Regading Point # 1, santhosh's point of view is correct I believe. In select options, I may enter multiple values in "from" or "to" fields. Ultimately, your solution is checking for single record existance only (counting no. of lines in internal table). The same thing is done in Santhosh's code also.

Pls correct me if my view is wrong.

Regards

0 Kudos

I think Santosh's code would do similar to mine whereas he just comes out if there is a single correct plant enter while I take the list of the plants, which can be useful in later on report. It does not matter either way.

U do not require to validate the low and high parameters for the select-option because with a select-option you can various filters as to fetch data for a pattern, use between to clause etc. Hence it is more appropriate to check it with code given by me or Santosh.

0 Kudos

Raghav,

generally u give multiple values in select-option.

in AT SELECTION-SCREEN.

if you write like this..

  • Validate Material Number

SELECT matnr UP TO 1 ROWS

INTO mara-matnr

FROM mara

WHERE matnr IN s_matnr.

ENDSELECT.

IF sy-subrc <> 0.

MESSAGE e000(zffi) WITH

'Invalid Mateial'(e01).

ENDIF.

- this means at least one matnr should have correct value.

if at all all your values are wrong than only it will give you the error message o.w. it will work with your correct value/s.

still u want to check with all your values,

you can do select and get all values into internal table

and check the count with the total no. of record you entered in selection screen.

if count is same- all values entered are fine.

-Anu

Former Member
0 Kudos

at selection-screen on s_werks.

if not s_werks[] is initial.

select single werks

from t001w

into g_werks

where werks in s_werks.

if sy-subrc <> 0.

Message 'Check Plant entry' type 'E'.

endif.

endif.

santhosh

Message was edited by: Kaluvala Santhosh

0 Kudos

Hi Santhosh,

Thanks for the response.

I have one doubt here. If I give a valid plant in "from" field and invalid plant in "to" field of S_WERKS and also vice versa, how do I handle this situation

Regards

0 Kudos

hi raghav,

Here u need to understand 1 think. A select option is a range for the client and the client would like to see any data he is entering betw the given values. atleast one hit from the selection would interest him hence i used the 'single' in my select staement

hope thats clear

santhosh

Former Member
0 Kudos

define internal table with werks say I_WERKS.

AT SELECTION-SCREEN ON s_werks.

select werks into table i_werks from T001W where werks in s_werks.

if sy-subrc <> 0.

message s000 with 'Invalid plant'

endif.

thanks

Ravi

Former Member
0 Kudos

Hi,

At selection-screen on s_werks.

select werks from T001w into v_werks

where werks in s_werks.

if sy-subrc <> 0.

message e000(zz) with 'Please enter valid plant'.

endif.

The select statement fails if the value entered by you in the selection screen is not present in the T001w table.Then u will get the error message.

regards,

keerthi.