‎2009 Dec 17 7:56 AM
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?
‎2009 Dec 17 8:00 AM
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
‎2009 Dec 17 8:08 AM
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.
‎2009 Dec 17 8:18 AM
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.
‎2009 Dec 17 8:26 AM
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
‎2009 Dec 17 11:32 AM
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.
‎2009 Dec 17 8:30 AM
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.
‎2009 Dec 17 8:39 AM
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 .....
‎2009 Dec 17 10:13 AM
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