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

Selection screen validation

Former Member
0 Likes
1,132

Hi All,

I have a field Plant(werks) on my selection screen.

I need to give a error message on selection screen if the name2 of the plant doesnt starts with P.

how do i do such kind of validation ?

i am trying something like this its not working

AT selection screen

SELECT werks

name1

name2

FROM t001w

INTO TABLE i_temp

WHERE werks IN s_pharid

AND name2 <> 'P%'.

IF sy-subrc = 0.

MESSAGE e000.

ENDIF.

Bu in the select there also comes the plant which has name2 which doesnt starts with P

Any useful suggestions?

8 REPLIES 8
Read only

Former Member
0 Likes
952

Hi, Try the bolow code..

AT selection screen on '<selection-screen field name>'

SELECT SINGLE werks

name1

name2

FROM t001w

INTO TABLE i_temp

WHERE werks IN s_pharid

AND name2 LIKE 'P%'.

IF sy-subrc not equal 0.

MESSAGE e000.

ENDIF.

Edited by: SHRIKANTH R on Dec 17, 2009 9:00 AM

Edited by: SHRIKANTH R on Dec 17, 2009 9:03 AM

Read only

Former Member
0 Likes
952

Hi Bhanu,

1. We can also validate using itab, instead of using select query directly and using %.

2.




AT selection screen
SELECT werks  name1 name2
FROM t001w
INTO TABLE i_temp
WHERE werks IN s_pharid.

loop at i_temp.

if i_temp-name2(1) NE 'P'.
message e000.
exit.
endloop.


regards,

amit m.

Read only

0 Likes
952

Hi Amit,

Thnkx for reply but here is a problem

if i click the option to give multiple range it gives a error message straight forwrd without entering any values

in plants now.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
952

Hello Bhanu,

A small modification to Amit's code:

AT selection screen.

IF s_pharid IS NOT INITIAL. "Add this line
SELECT werks  name1 name2
FROM t001w
INTO TABLE i_temp
WHERE werks IN s_pharid.
 
loop at i_temp.
 
if i_temp-name2(1) NE 'P'.
message e000.
exit.
endloop.
ENDIF.

I think you need not take data into an internal table & then process. I wrote this test code & seems to work:

TABLES t001w.

SELECT-OPTIONS s_werks FOR t001w-werks.

AT SELECTION-SCREEN ON s_werks.
  DATA:
        lst_werks TYPE t001w.

  IF s_werks IS NOT INITIAL.
    SELECT * FROM t001w UP TO 1 ROWS
      INTO lst_werks
      WHERE werks IN s_werks
      AND   name2 LIKE 'P%' OR name2 LIKE 'p%'. "NAME2 is case sensitive, so have to take care accordingly
    ENDSELECT.
    IF  sy-subrc NE 0.
*   Error Message
    ENDIF.
  ENDIF.

BR,

Suhas

Edited by: Suhas Saha on Dec 17, 2009 9:42 AM

Read only

0 Likes
952

Hi again,

Thats right. It will give message because we are using that event.

Normally I use START-OF-SELECTION event.

Like this:



START-OF-SELECTION.

SELECT werks  name1 name2
FROM t001w
INTO TABLE i_temp
WHERE werks IN s_pharid.
 
loop at i_temp.
 
if i_temp-name2(1) NE 'P'.
message I000.
leave list-processing.
endloop.


Important point:

1. message should be of type I or W (Not E, other wise it will come out)

2. The statement leave list-processing is important.

regards,

amit m.

Read only

Former Member
0 Likes
952

Hi Bhanu

You try this.

AT selection screen < field name >      "Plant in your case
SELECT SINGLE WERKS
NAME1
NAME2
FROM T001W
INTO TABLE i_temp
WHERE werks IN s_pharid
AND name2 LIKE 'P%'.
IF sy-subrc not equal 0.              " If no data, then error
MESSAGE e000.
ENDIF.

Read only

anup_deshmukh4
Active Contributor
0 Likes
952

Hi Bhanu,

When you have select options a runtime range internal table is generated with the same name as the select option field .

this internal table contains SIGN, OPTION, LOW, and HIGH. fields so if you access and check it at AT-SELECTION-SCREEN. event it would be possible whithout accessing the data base .....

Read only

former_member936723
Participant
0 Likes
952

Hi Bhanu,

Try using the following code this will help:-

PARAMETERS       : name2  LIKE t001w-name2.

data: name(1).
AT SELECTION-SCREEN output.

  if name2 is not initial.
     condense name2 no-gaps.
   name = name2+0(1) .
   TRANSLATE NAME TO UPPER CASE.
  if name NE 'P'.
  < type error message here>
endif.

If you need any further help do let me know.

Regards,

Ankita