‎2009 Apr 09 9:32 AM
Hi,
Can any body tell me the best option for validating the select-option field in selection screen.
suppose i have a select option s_lifnr on selection screen.how i can validate that vendor.we have to validate the range or we have to check for at least single value..is valid..what is the best possible solution?
Thanks.
‎2009 Apr 09 9:37 AM
At selection-screen.
Select Lifnr
from LFA1
Into Z_lifnr
up to 1 rows
where lifnr in s_lifnr.
Endselect.
If sy-subrc NE 0.
Error message.
Endif.Regards,
Gurpreet
‎2009 Apr 09 9:37 AM
Hi
It depends on which validation u need to do, give us more details
Max
‎2009 Apr 09 9:37 AM
At selection-screen.
Select Lifnr
from LFA1
Into Z_lifnr
up to 1 rows
where lifnr in s_lifnr.
Endselect.
If sy-subrc NE 0.
Error message.
Endif.Regards,
Gurpreet
‎2009 Apr 09 9:38 AM
hi ,
please go through the below mentioned example :
*--- Validate Plant
AT SELECTION-SCREEN ON s_werks.
PERFORM validate_werks.
*******************************
FORM validate_werks.
DATA: l_v_werks TYPE ewerk.
SELECT SINGLE werks
FROM
t001w
INTO l_v_werks
WHERE werks IN s_werks
AND kosher_flag EQ c_true .
IF sy-subrc IS NOT INITIAL.
MESSAGE e047 WITH s_werks-low. " & is not a valid Plant
ENDIF.
** if there is even a single plant with non kosher
* throw error
SELECT SINGLE werks
FROM
t001w
INTO l_v_werks
WHERE werks IN s_werks
AND kosher_flag EQ '' .
IF sy-subrc IS INITIAL.
MESSAGE e047 WITH s_werks-low. " & is not a valid Plant
ENDIF.
ENDFORM. " validate_werksregards
rahul
‎2009 Apr 09 9:39 AM
Hi,
AT SELECTION-SCREEN .
IF NOT S_LIFNR[] IS INITIAL.
SELECT SINGLE LIFNR
FROM LFA1
INTO (LFA1-LIFNR)
WHERE LIFNR IN S_LIFNR
IF SY-SUBRC 0.
MESSAGE E002. " Error Message
ENDIF.
ENDIF.
Regards,
Nitin.
‎2009 Apr 09 9:40 AM
AT SELECTION-SCREEN on s_lifnr.
SELECT SINGLE * FROM EKKO WHERE lifnr IN s_lifnr.
IF sy-subrc <> 0.
MESSAGE e002(00). <---- Error Message
ENDIF.
Edited by: Sap Fan on Apr 9, 2009 10:41 AM
‎2009 Apr 09 9:42 AM
the best solution is to check if a single value is fetched from the db
at selection screen on so_lifnr
select single * from lfa1
where lifnr in so_lifnr.
if sy-subrc NE 0.
Message 'Invalid vendor' type 'E'.
endif.
The reason is simple imagine you give a range of 1 to 10 in so_lifnr, then there might be vendors only for 1, 3, 5 ,7. You dont want to give an error message in this case if there is no vendor 2,4, etc...
Also imagine that there are 10000 vendors and the range now has 1 to 10000, imagine the performance if you are to validate each value in the select option.
Last but not the leaset the user has a free option to use patterns (astericks ), signs ( E or I ) , options ( EQ, NE, GE, LE, GT, LT,BT etc ) in select options. So user may enters ABC and 'I in the sign. It would then be hard to code to find exactly all the possible entries the user wants, unless they are selected from db.
So as you can see there are a lot of possible inputs for a select option, the best approach is to validate a single value from database.
regards,
Advait
‎2009 Apr 09 10:02 AM