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

Select-option validation

Former Member
0 Likes
840

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
777
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

7 REPLIES 7
Read only

Former Member
0 Likes
777

Hi

It depends on which validation u need to do, give us more details

Max

Read only

Former Member
0 Likes
778
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

Read only

Former Member
0 Likes
777

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_werks

regards

rahul

Read only

Former Member
0 Likes
777

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.

Read only

awin_prabhu
Active Contributor
0 Likes
777

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

Read only

Former Member
0 Likes
777

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

Read only

Former Member
0 Likes
777

Thank for all the replys