‎2009 Feb 11 7:19 AM
hi,
How can we validate the entries in select option?
Regards,
Suzie
‎2009 Feb 11 7:21 AM
Hi,
You can validate entires of select-options in at selection-screen ON {para|selcrit} }
event....
you can write the select query with where condition being the field_name IN <select_option_name>.
Regards,
Siddarth
‎2009 Feb 11 7:22 AM
Hi,
small example
select-options : s_matnr for mara-matnr.
suppose i want the materials to be validate on the selection screen.
at selection-screen.
select matnr from mara into lv_matnr up to 1 rows
where matnr in s_matnr.
endselect.
if sy-subrc eq 0.
material is valid.
else.
throw error message.
endif.
Regards,
Nagaraj
‎2009 Feb 11 7:23 AM
Hi,
Kinldy search in SCN / SAP Library / ABAPDOCU before posting.
Use event At Selection-Screen for this.
for more help on this press F1 on it, you will get ample help available with SAP itself.
Pratik Vora
‎2009 Feb 11 7:25 AM
Hi,
try this.
tables:
spfli.
select-options:
s_carrid for spfli-carrid.
data w_carrid type spfli-carrid.
at selection-screen on s_carrid.
select carrid
into w_carrid
from spfli
up to 1 rows
where carrid in s_carrid.
This works.
‎2009 Feb 11 7:26 AM
Hi Suzie
s_matnr.
IF s_matnr-low IS NOT INITIAL.
LOOP AT s_matnr.
SELECT SINGLE matnr FROM mara INTO lv_matnr WHERE matnr = s_matnr-low.
IF sy-subrc NE 0.
*set the flag
EXIT.
ENDIF.
ENDLOOP.
CLEAR lv_matnr.
IF s_matnr-high IS NOT INITIAL.
SELECT SINGLE matnr FROM mara INTO lv_matnr WHERE matnr = s_matnr-high.
IF sy-subrc NE 0.
*set the flag
ENDIF.
ENDLOOP.
Pushpraj
‎2009 Feb 11 7:28 AM
Hi,
For selection options validations.. we have selection screen events..
go through this prog..
REPORT demo_at_selection_screen.
Global data
DATA: sflight_tab TYPE TABLE OF sflight,
sflight_wa LIKE LINE OF sflight_tab.
Selection screens
PARAMETERS p_carrid TYPE spfli-carrid.
SELECTION-SCREEN BEGIN OF SCREEN 500.
SELECT-OPTIONS s_conn FOR sflight_wa-connid.
DATA s_conn_wa LIKE LINE OF s_conn.
SELECTION-SCREEN END OF SCREEN 500.
Handling selection screen events
AT SELECTION-SCREEN ON p_carrid.
IF p_carrid IS INITIAL.
MESSAGE 'Please enter a value' TYPE 'E'.
ENDIF.
AUTHORITY-CHECK OBJECT 'S_CARRID'
ID 'CARRID' FIELD p_carrid
ID 'ACTVT' FIELD '03'.
IF sy-subrc = 4.
MESSAGE 'No authorization for carrier' TYPE 'E'.
ELSEIF sy-subrc <> 0.
MESSAGE 'Error in authority check' TYPE 'A'.
ELSE.
IF sy-ucomm = 'ONLI'.
CALL SELECTION-SCREEN '0500'.
ENDIF.
ENDIF.
AT SELECTION-SCREEN.
IF sy-dynnr = '0500'.
IF s_conn IS INITIAL.
MESSAGE 'Please enter values' TYPE 'W'.
ELSE.
SELECT *
FROM sflight
INTO TABLE sflight_tab
WHERE carrid = p_carrid AND
connid IN s_conn.
IF sy-subrc <> 0.
MESSAGE 'No flights found' TYPE 'E'.
ENDIF.
ENDIF.
ENDIF.
Main program
START-OF-SELECTION.
...
‎2009 Feb 11 7:40 AM
Look at the Following sample to get the valid Entries which fall in range of Select Options.
SELECT-OPTIONS S_CUSTOMER_NUM FOR KNA1-KUNNR.
DATA: IT_KNA1 TYPE STANDARD TABLE OF KNA1,
WA_KNA1 LIKE LINE OF IT_KNA1.
SELECT * FROM KNA1
INTO CORRESPONDING FIELDS OF TABLE IT_KNA1
WHERE KUNNR IN S_CUSTOMER_NUM.
LOOP AT IT_KNA1 INTO WA_KNA1.
....
//Process the Valid Entries here.
.....
ENDLOOP.
Thanks
Ajay
‎2009 Feb 11 7:42 AM
Hi,
When you take in classical reports:-
select-options : s_vbeln for vbap-vbeln.
Then all the validation for field-type is done by itself.
All checks like data-type and low/high values are standard (done by itself).
All you need to check is whether the data is fetched in internal table using the select-option range.
So, you can validate if no records exists for the current select-options that the user has used to fetch data from database table.
select vbeln posnr matnr werks
from vbap
where vbeln in s_vbeln.
if sy-subrc <> 0.
"give error message
"no records found for select-options *low value-high value*
endif.
Hope this solves your problem.
Thanks & Regards,
Tarun Gambhir
‎2009 Feb 11 7:45 AM
Hi,
U can use
AT SELECTION-SCREEEN. or
AT SELECTION-SCREEN ON <<fieldname>>.
For Eg :
AT SELECTION-SCREEN ON p_afabe.
IF p_afabe IS NOT INITIAL.
SELECT SINGLE *
FROM t093
WHERE afaber = p_afabe .
IF sy-subrc <> 0.
MESSAGE e000(02) WITH text-012.
ENDIF.
ENDIF.
Hope it helps.
‎2009 Feb 11 8:02 AM
Use the event
AT SELECTION-SCREEN ON so. where so is the select options name.
If the selection can take too long, do the test only if the execution has been requested.
TABLES: sscrfields,
(...)
AT SELECTION-SCREEN ON so.
IF sscrfields-ucomm EQ 'ONLI'
OR sscrfields-ucomm EQ 'PRIN'.
" perform full selection (e.g. load all orders)
SELECT * INTO TABLE gt_data FROM database WHERE field in so.
IF sy-subrc NE 0.
IF sy-batch IS INITIAL.
MESSAGE ennn(xxx). " e.g. no order selected
ELSE.
MESSAGE innn(xxx). " e.g. no order to process, job terminated
LEAVE PROGRAM.
ENDIF.
ENDIF.
ELSE.
" only check existence of one record in master table (e.g. customer exists)
SELECT SINGLE * INTO wa FROM mastertable WHERE field in so.
IF sy-subrc NE 0.
MESSAGE ennn(xxx). " e.g. no customer exists in your selection
ENDIF.
ENDIF.NB: In this sample no individual check is performed for values of -low and -high,. Personally, I allow a user to select all items between A and B even if A and B do not exist in database. I only perform this kind of check when user is restricted to a list of values (FM [SELECT_OPTIONS_RESTRICT|https://www.sdn.sap.com/irj/scn/advancedsearch?query=select_options_restrict&cat=sdn_all])
Regards
‎2009 Feb 11 8:33 AM
Hi Suzie,
You can use at selection-screen event.
Example:
select-options: s_mara for mara-matnr.
At selection-screen on s_mara-low.
IF NOT s_mara-low IS INITIAL.
select single matnr from mara into s_mara-low where matnr = s_mara-low.
if sy-subrc <> 0 .
message 'Material no not exists' type 'E'.
endif.
endif.
Regards
Rajendra
‎2009 Feb 11 8:48 AM
The question is: what do you want to validate?
Whether the entries in the select-options LOW and HIGH exists?
Or do you want to validate the user against a value in LOW and HIGH?
‎2009 Feb 11 12:42 PM
Hi,
We can validate select option field using At selection screen on field value request.
Regards
Md.MahaboobKhan
‎2009 Feb 12 6:43 AM
Hi Suzie,
here is a sample code.....
TYPES:
BEGIN OF type_s_sflight,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldat TYPE sflight-fldate,
END OF type_s_sflight.
DATA:
fs_sp TYPE type_s_sflight.
DATA:
t_sp LIKE TABLE OF fs_sp.
DATA w_id TYPE sflight-carrid.
SELECT-OPTIONS s_carrid FOR w_id.
AT SELECTION-SCREEN ON s_carrid. '' validating the input entered in field s_carrid
SELECT single carrid
FROM scarr
into fs_sp-carrid
WHERE carrid = s_carrid-low.
IF sy-subrc NE 0.
MESSAGE ' invalid input' TYPE 'E'.
ENDIF.
START-OF-SELECTION.
SELECT carrid connid fldate
FROM sflight
INTO TABLE t_sp
WHERE carrid IN s_carrid.
IF sy-subrc EQ 0.
loop at t_sp into fs_sp.
write:/ fs_sp-carrid.
endloop.
ENDIF.
Regards,
Mdi.Deeba