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

VAlidation in Select options

lijisusan_mathews
Active Contributor
0 Likes
14,633

hi,

How can we validate the entries in select option?

Regards,

Suzie

14 REPLIES 14
Read only

Former Member
0 Likes
5,717

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

Read only

former_member404244
Active Contributor
0 Likes
5,717

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

Read only

Former Member
0 Likes
5,717

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

Read only

Former Member
0 Likes
5,717

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.

Read only

Former Member
0 Likes
5,717

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

Read only

former_member632729
Contributor
0 Likes
5,717

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.

...

Read only

AjayJangid
Explorer
0 Likes
5,717

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

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
5,717

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

Read only

Former Member
0 Likes
5,717

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.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
5,717

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

Read only

Former Member
0 Likes
5,717

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

Read only

Former Member
0 Likes
5,717

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?

Read only

Former Member
0 Likes
5,717

Hi,

We can validate select option field using At selection screen on field value request.

Regards

Md.MahaboobKhan

Read only

Former Member
0 Likes
5,717

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