Validation of SELECT OPTIONS

Hi Gurus,
Please let me know which is the best way to validate a select option and performance way also it must be best.
May be this is a silly question but still I was not able to find the best convincing answer in the FORUM.
Kindly validate.
Method 1:
AT SELECTION-SCREEN ON so_vbeln . " Delivery document
PERFORM validate_vbeln .
FORM validate_vbeln.
DATA : l_t_vbeln TYPE TABLE OF vbuk-vbeln WITH HEADER LINE ,
l_f_vbeln TYPE vbuk-vbeln .
RANGES ra_vbeln FOR vbuk-vbeln.
LOOP AT so_vbeln.
IF NOT so_vbeln-low IS INITIAL.
ra_vbeln-sign = 'I'.
ra_vbeln-option = 'EQ'.
ra_vbeln-low = so_vbeln-low.
APPEND ra_vbeln.
ENDIF.
IF NOT so_vbeln-high IS INITIAL.
ra_vbeln-sign = 'I'.
ra_vbeln-option = 'EQ'.
ra_vbeln-low = so_vbeln-high..
APPEND ra_vbeln.
ENDIF.
ENDLOOP .
IF NOT so_vbeln[] IS INITIAL.
SELECT vbeln INTO TABLE l_t_vbeln
FROM vbuk
WHERE vbeln IN ra_vbeln.
ENDIF.
LOOP AT so_vbeln.
IF so_vbeln-low space.
READ TABLE l_t_vbeln WITH KEY = so_vbeln-low.
IF sy-subrc 0.
SET CURSOR FIELD 'SO_vbeln-LOW'.
MESSAGE e001(vb) WITH so_vbeln-low.
ENDIF.
ENDIF.
IF so_vbeln-high space.
READ TABLE l_t_vbeln WITH KEY = so_vbeln-high.
IF sy-subrc 0.
SET CURSOR FIELD 'SO_vbeln-HIGH'.
MESSAGE e001(vb) WITH so_vbeln-high.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " validate_vbeln
Method 2
AT SELECTION-SCREEN ON so_werks.
PERFORM validate_plant.
FORM validate_plant.
DATA: BEGIN OF l_t_werks OCCURS 0,
werks LIKE t001w-werks,
END OF l_t_werks.
IF NOT so_werks[] IS INITIAL.
SELECT werks INTO TABLE l_t_werks
FROM t001w
WHERE werks IN so_werks.
ENDIF.
LOOP AT so_werks.
IF so_werks-low space.
READ TABLE l_t_werks WITH KEY werks = so_werks-low.
IF sy-subrc 0.
MESSAGE e892(m7) WITH so_werks-low.
ENDIF.
ENDIF.
IF so_werks-high space.
READ TABLE l_t_werks WITH KEY werks = so_werks-high.
IF sy-subrc 0.
MESSAGE e892(m7) WITH so_werks-high.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.

Hello Raj,
For me if the SELECT-OPTION fetches atleast one record from the check table, processing should be allowed to proceed.
It's not required to check each & every records in the select-option & throw an error message for these invalid records (unlike PARAMETERs)
I would code something like this:
SELECT vbeln INTO TABLE l_t_vbeln UP TO 1 ROWS
FROM vbuk
WHERE vbeln IN so_vbeln. ENDSELECT.
IF sy-subrc NE 0.
  MESSAGE 'No valid Sales Order selected for the input range. Please check.' TYPE 'E'.
ENDIF.
BR,
Suhas

Similar Messages

  • How to do validations for select-options

    Hi gurus,
    can you suggest me
    how to do validations for select-options
    Thanks&ragards,
    Kals.

    HI,
    TABLES: BKPF.
    TYPES: BEGIN OF TY_BKPF,
           BUKRS TYPE BUKRS,   "COMPANY CODE
           GJAHR TYPE GJAHR,   "FISCAL YEAR
           MONAT TYPE MONAT,   "FISCAL PERIOD
    DATA: T_BKPF TYPE TABLE OF TY_BKPF,
          W_BKPF TYPE TY_BKPF.
    SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS: S_CODE   FOR BKPF-BUKRS,
                    S_YEAR   FOR BKPF-GJAHR,
                    S_PERIOD FOR BKPF-MONAT.
    SELECTION-SCREEN: END OF BLOCK B1.
                        AT SELECTION-SCREEN                           *
    IF S_CODE IS INITIAL OR S_YEAR IS INITIAL OR S_PERIOD IS INITIAL.
      MESSAGE E000(0) WITH 'ENTER VLAUES'.
    ENDIF.
    SELECT SINGLE * FROM BKPF WHERE BUKRS IN S_CODE.
      IF SY-SUBRC <> 0.
      MESSAGE E000(0) WITH 'ENTER VALID VALUES'.
      ENDIF.
    reward if useful
    thanks and regards

  • Validation of select-options in WEb DynPro ABAP

    Can anyone please help me on validating select-options. I want to have a functionality like what we use in normal text field while validating the field. We generally use the REPORT_ATTRIBUTE_ERROR_MESSAGE funciton.
    How can we achieve the same thing with select-options, cuz the select-options are not bound with any attribute.
    Edited by: Tirth Pandya on May 7, 2009 2:02 AM

    Hi,
    Refer to this link..Re: validate select option fields

  • Validation for Select-Option - Issue

    Hi Experts!!
    I have a select-option s_field on which I have written a validation under AT SELECTION-SCREEN. Now, the problem is that, if validation fails in second line of s_field, then to change it when we click on Extension, it's not allowing to enter but is throwing error message again and again as AT SELECTION-SCREEN is called.
    Suppose, I have entered 2 single values as C001 and F001. s_field will have 2 entries. Now, C001 is a valid value but F001 is not. PFB my code:
    LOOP AT s_field.
    SELECT SINGLE *
      FROM ztable INTO ls_field
      WHERE field EQ s_field-low.
    IF sy-subrc NE 0.
    " Error Message
    ENDIF.
    ENDLOOP.
    Now, for C001, sy-subrc will be 0. But for F001 sy-subrc is 4 and hence will throw an error. Now, to correct this, I am trying to enter into extension, but as this will be called again, I am unable to. Hope I explained it clearly.
    I do not see any possibility to correct this. Can anybody please suggest if any workaround can be implemented?
    Your help is highly appreciable.

    Hi,
    You can try the following:
    AT SELECTION-SCREEN on s_field.
    LOOP AT s_field.
    SELECT SINGLE *
      FROM ztable INTO ls_field
      WHERE field EQ s_field-low.
    IF sy-subrc NE 0.
    MESSAGE s398(00) DISPLAY LIKE 'E' with 'ERROR MESSAGE'.
    ENDIF.
    ENDLOOP.
    I hope this works as per your requirement.
    <<point-begging removed>>
    Edited by: micky prasad on Jan 6, 2012 1:00 PM
    Edited by: kishan P on Jan 9, 2012 1:40 PM

  • Validation of SELECT-OPTIONS in selection screen

    Hi Experts,
    I need to validate the user entered values in the selection screen, specifically in SELECT-OPTIONS. So, currently am doing by checking S_VBELN-LOW and S_VBELN-HIGH.
    BUt, curious that Is there any standard SAP Function module to use for this purpose? I searched in SE37 by giving OPTIONS but did not find any!!
    Thank you

    Hi,
    Instead of searching  for the function module .. use the event at selection-screen on or  at selection-screen  and write your validation logic only if there  no value table for the particular field..
    Thanks
    Krishna

  • Validation of Select Options for a field

    Hi All,
    I need to write a validation logic for a select option for VTWEG (Distribution Channel).
    select-options:  s_vtweg for komg-vtweg.
    I need to check whether the user has entered the correct value based on the search help. The check table of this particular field is TVTW. 
    Following is the code i wrote under the AT SELECTION-SCREEN block:
    IF NOT S_VTWEG-LOW IS INITIAL.
    SELECT SINGLE VTWEG INTO KOMG-VTWEG FROM TVTW
                                     WHERE VTWEG IN S_VTWEG.
    IF SY-SUBRC NE 0.
    CONCATENATE ' Please enter the correct
                                    Distribution Channel '
    Z_MSG INTO Z_MSG.
    SET CURSOR FIELD 'S_VTWEG-LOW'.
    MESSAGE E000 WITH Z_MSG.
    ENDIF.
    ENDIF.
    It works fine when the user enters a wrong value in the S_VTWEG-LOW field, where as if i gives more than one wrong value in the range or giving individual values its not working. Let me know how to do the validation check for multiple values entered individually or in ranges.
    Could you please suggest how to resolve this problem.
    Thank You,
    Suresh

    You could do something like this.....here looping at the select-option table and check the values for low and high.
    report zrich_0003.
    tables: komg.
    data: z_msg(100) type c.
    select-options: s_vtweg for komg-vtweg.
    at selection-screen.
      loop at s_vtweg.
        if not s_vtweg-low is initial.
          select single vtweg into komg-vtweg from tvtw
                 where vtweg = s_vtweg-low.
          if sy-subrc ne 0.
            concatenate ' Please enter the correct
            distribution channel '
                      z_msg into z_msg.
            set cursor field 'S_VTWEG-LOW'.
            message e001(00) with z_msg.
          endif.
        endif.
        if not s_vtweg-high is initial.
          select single vtweg into komg-vtweg from tvtw
                 where vtweg = s_vtweg-high.
          if sy-subrc ne 0.
            concatenate ' Please enter the correct
            distribution channel '
                      z_msg into z_msg.
            set cursor field 'S_VTWEG-HIGH'.
            message e001(00) with z_msg.
          endif.
        endif.
      endloop.
    Regards,
    Rich Heilman

  • Validation for select-options

    need help in validaiton for select-options.

    Hi..,
    could u paste ur selection screen declarations here !!!
    check this..
    *"Selection screen elements............................................
    select-options :
      s_vbeln for vbak-vbeln,              " Sales document number
      s_vkorg for vbak-vkorg,              " Sales organization
      s_erdat for vbak-erdat .             " Run date
                          AT SELECTION-SCREEN ON EVENT                  *
    *Validation on Sales document number range...
    at selection-screen on s_vbeln.
    Perform to validate Sales document number range...
      perform f0000_validate_vbeln.
                          AT SELECTION-SCREEN ON EVENT                  *
    *Validation on Sales Organization range...
    at selection-screen on s_vkorg.
    *Perform to validate the Organization number user input...
      perform f0100_validate_vkorg.
                          AT SELECTION-SCREEN ON EVENT                  *
    *Validation on Creation date range...
    at selection-screen on s_erdat.
    *Perform to validate the Creation date of the sales documents...
      perform f0100_validate_erdat.
    *&      Form  f0000_validate_vbeln
          This subroutine validates the user input - Sales document      *
          number range                                                   *
          There are no interface parameters                              *
    form f0000_validate_vbeln.
      select vbeln                         " Sales Document number
        from vbuk
       up to 1 rows
        into vbak-vbeln
       where vbeln in s_vbeln.
      endselect.
      check sy-subrc ne 0.
        message e001(zsls640) with s_vbeln-low s_vbeln-high.
    endform.                               " Form f0000_validate_vbeln
    *&      Form  f0100_validate_vkorg
          This subroutine validates the user input - Sales Organization  *
          range                                                          *
          There are no interface parameters                              *
    form f0100_validate_vkorg.
      select vkorg                         " Sales Organization
        from vbak
       up to 1 rows
        into vbak-vkorg
       where vkorg in s_vkorg.
      endselect.
      check sy-subrc ne 0.
        message e002(zsls640) with s_vkorg-low s_vkorg-high.
    endform.                               " Form f0100_validate_vkorg
    *&      Form  f0100_validate_erdat
          This subroutine validates the user input - Creation date of the*
          Sales documents                                                *
          There are no interface parameters                              *
    form f0100_validate_erdat.
      select erdat                         " Creation date
        from vbak
       up to 1 rows
        into vbak-erdat
       where vkorg in s_erdat.
      endselect.
      check sy-subrc ne 0.
        message e003(zsls640) with s_erdat-low s_erdat-high.
    endform.                               " Form f0100_validate_erdat
    <b>regards,
    sai ramesh</b>

  • Validation of select-option in module pool

    Hi experts,
    I want to make a check according to a field on my dynpro 100. The dynpro has a subscreen area and there is a select-option which I want to check (so_matnr).
    According to the check I want to update my table control on the same dnypro.
    How can I check so_matnr if it is on the subscreen?
    When I'm trying to use FIELD statement it says that input/output field "so_matnr" not defined.

    you need to use  event at selection-screen or at selection-screen on <selectoption>
    at selection-screen on s_matnr.
    "here you need to place the logic.
    Though it is a module pool screen. but you designed the select-options in the normal way. so for the subscreen you have to follow normal events.

  • Validating a select option

    What is the best way to validate a select option on the selection screen. Is there any way to do it without firing a select query.

    Hi,
    Refer This code.
                    AT SELECTION SCREEN                                  *
    AT SELECTION-SCREEN.
    *--This perform verify the material number in table MCHB.
      PERFORM validate_material.
    *&      Form  validate_material                                        *
    This form will verify the material number in table MCHB              *
    FORM  validate_material.
    *--It will verify the material number in table MCHB.
      SELECT matnr UP TO 1 ROWS               "Material Number
        FROM mchb                             "Material Master
        INTO mchb-matnr
        WHERE matnr IN s_matnr.
      ENDSELECT.
    *--Check SUBRC
      IF sy-subrc <> 0 AND mchb-matnr IS INITIAL.
    *--Invalid Material
        MESSAGE e065.
      ENDIF.
      CLEAR mara.
    ENDFORM.                                  "validate_material
    Regards,
    Prashant

  • Date validation using select-options

    i have declared date1 as select-options which is in date format.
    I need to validate min of SIX months duration from LOW value to HIGH value in select-options.How to validate for min SIX months

    Hi,
    u can go through the following code..
    data:
      w_date like sy-datum.
    select-options:
      s_date for w_date.
    initialization.
    s_date-high = sy-datum.
    CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
      EXPORTING
        DATE            = s_date-high
        DAYS            = 0
        MONTHS          = 6
        SIGNUM          = '-'
        YEARS           = 0
    IMPORTING
       CALC_DATE       = w_date .
    s_date-low = w_date.
    append s_date.
    Reward if helpful..........

  • Select-option validation

    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.

    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

  • Selection-options validation

    i want to do required field validation for select-options:s_slmtnr for mara-matnr.
    that is whether user has entered the high and low value.
    s_slmtnr-high and low show not be blank.
    Moderator message: please search for available information/documentation before asking.
    Edited by: Thomas Zloch on Dec 4, 2010 9:49 PM

    aswk,
    thanks for the reply.
    my code:
    IF MA_DE = 'X'.
       IF S_MATUM-LOW = 0 OR S_MATUM-HIGH = 0.
         MESSAGE: 'PLEASE ENTER RANGE' TYPE 'E'.
       ENDIF.
    ENDIF.
    but here if i put 'AND' instead of 'OR'.it will not work for both low and high.
    what i know is 'AND' is used to do for both true,but here 'OR' works like that why.

  • Validate select option fields

    Hi all,
    I have two fields on my selection screen(Select Options). Now I want to validate if the user the entered the values in the select options or not.
    I have used the following code which are not working.
    data: range_table_chn type ref to data,
    range_table_chn = WD_THIS->M_HANDLER->GET_VALUE_OF_PARAMETER_FIELD( i_id = 'KUNNR' ).
    if not range_table_chn is initial.
    Message.
    endif.
    and
    data: range_table_chn type ref to data,
    range_table_chn = WD_THIS->M_HANDLER->GET_RANGE_TABLE_OF_SEL_FIELD( i_id = 'KUNNR' ).
    if not range_table_chn is initial.
    Message.
    endif.
    Both of these are not working . Can any one suggest me the correct way of validating the select options if the user entered or not?
    Thanks,

    Hi,
    Try this code for validation.
    METHOD onactionsearch_data .
    Processing For OnAction ´SEARCH` on Screen
      DATA:lo_po_list             TYPE REF TO if_wd_context_node     ,
           lo_el_po_list          TYPE REF TO if_wd_context_element  ,
           lo_werks               TYPE REF TO data                   ,
           lo_ebeln               TYPE REF TO data                   ,
           lo_ebdat               TYPE REF TO data                   .
    DATA lt_werks TYPE if_wd_select_options=>tt_selection_screen_item.
    DATA:lt_po_list     TYPE /bay0/msdts_cl_whp_goods_rcp=>tt_po_list ,
    lv_valid       TYPE abap_bool                             .
    DATA lv_text_key    TYPE wdr_text_key .
    FIELD-SYMBOLS: <lt_ebeln>  TYPE ANY TABLE,
    <lt_ebdat>  TYPE ANY TABLE.
    **----Get the Data from the select Option&Parameter-----***
      Returns the data from a parameter field-P_WERKS*
    wd_this->m_handler->get_parameter_fields( IMPORTING et_fields = lt_werks ).
      Retrieve the data from the select option*
    lo_ebeln = wd_this->m_handler->get_range_table_of_sel_field( i_id = 'SO_EBELN' ).
      Assign it to a field symbol*
    ASSIGN lo_ebeln-> TO .*
      Retrieve the data from the select option
    lo_ebdat = wd_this->m_handler->get_range_table_of_sel_field( i_id = 'SO_EBDAT' ).
      Assign it to a field symbol
    ASSIGN lo_ebdat-> TO .*
    **----Data access using the methods of Assistance Class-----***
      Validate the entered data on Selection Screen
    wd_assist->validate_sel_screen_data( EXPORTING it_so_ebeln = lo_ebeln
    it_p_werks  = lt_werks
    IMPORTING ev_valid    = lv_valid
    ev_text_key = lv_text_key ).
      Display Message if LV_VALID = X means when input is Invalid
      IF lv_valid EQ 'X'.
      Msg-Please enter correct Purchase Order Num.
        EXIT.
      ENDIF.
    ENDMETHOD.
    METHOD validate_sel_screen_data.
      DATA ls_ekko TYPE ekko.
      DATA lv_werks TYPE werks_d.
      DATA ls_werks TYPE if_wd_select_options=>t_selection_screen_item.
      FIELD-SYMBOLS:   TYPE ANY .
      READ TABLE it_p_werks INTO ls_werks INDEX 1.
      IF sy-subrc EQ 0.
      Assign it to a field symbol
        ASSIGN ls_werks-m_value->* TO  IS not ASSIGNED.
         MOVE '106' TO ev_text_key.
          ev_valid = 'Y'.
          exit.
        ENDIF.
      Validate Plant eneterd on selection screen
        SELECT SINGLE werks
          FROM t001w
          INTO lv_werks
         WHERE werks EQ .
        IF sy-subrc EQ 0.
         Do the Authority Check
          AUTHORITY-CHECK OBJECT 'M_BEST_WRK'
          ID 'ACTVT' FIELD '03'
          ID 'WERKS' FIELD lv_werks.
          IF sy-subrc NE 0.
            MOVE '105' TO ev_text_key.
            ev_valid = abap_true.
            exit.
          ENDIF.
        ELSE.
          MOVE '104' TO ev_text_key.
          ev_valid = abap_true.
          exit.
        ENDIF.
      ENDIF.
    Assign it to a field symbol
      ASSIGN it_so_ebeln->* TO  IS NOT INITIAL.
    Get Purch. Order from EKKO table
      SELECT ebeln
        FROM ekko
        INTO ls_ekko
        UP TO 1 ROWS
       WHERE ebeln IN .
      ENDSELECT.
      IF sy-subrc EQ 0.
        ev_valid = abap_false.
      ELSE.
        MOVE '102' TO ev_text_key.
        ev_valid = abap_true.
      ENDIF. "if sy-subrc eq 0.
    ENDMETHOD.
    Regard
    Manoj Kumar
    Edited by: Manoj Kumar on Mar 10, 2009 10:30 AM

  • Multiple select options validation at selection screen

    Hi,
    I have the requirement to create a selection screen with 3 select options. Two of them are cross-dependent. It is mandatory to fill one of them and it is not allowed to fill both. The third one is optional. I tried the validation at selection-screen on block... and I have a problem that search help buttons for select options react like execution buttons, when I press any of them I am getting one of errors instead of search help.
    Any help on this issue would be appreciated.
    Here is my code:
    DATA:
          so_rbkp TYPE rbkp,
          so_mseg TYPE mseg.
    SELECTION-SCREEN BEGIN OF BLOCK blok WITH FRAME.
      SELECT-OPTIONS:
            s_fakt   FOR so_rbkp-belnr,
            s_matdok FOR so_mseg-mblnr,
            s_god FOR so_mseg-gjahr.
    SELECTION-SCREEN END OF BLOCK blok.
    INITIALIZATION.
    SET TITLEBAR '0100'.
    START-OF-SELECTION.
      AT SELECTION-SCREEN on block blok.
          if s_fakt <> space and s_matdok <> space.
            MESSAGE 'Message1' TYPE 'E'.
          elseif s_fakt = space and s_matdok = space.
            MESSAGE 'Message2' TYPE 'E'.
          endif.
        ENDIF.

    Only perform the check when user wants to execute or submit the program, not when pressing F4 or even Enter, but in a selection-screen event, before START-OF-SELECTION which were program would terminate in error :
    TABLES: SSCRFIELDS.
    AT SELECTION-SCREEN OB BLOCK b01.
        IF sscrfields-ucomm EQ 'ONLI'
        OR sscrfields-ucomm EQ 'PRIN'
        OR sscrfields-ucomm EQ 'SJOB'.
          IF s_fakt[] IS NOT INITIAL AND s_matdok IS NOT INITIAL.
            MESSAGE 'Message1' TYPE 'E'.
          ELSEIF s_fakt[] IS INITIAL and s_matdok[] IS INITIAL.
            MESSAGE 'Message2' TYPE 'E'.
          ENDIF.
        ENDIF.
    (You could also always send the message, but using type 'E' for those function code and 'S' status for any other value.)
    Regards,
    Raymond

  • Event should trigger when enter is pressed on select option for validation

    Hi,
    I want to trigger a event when enter is pressed on a select option field for validation.
    I have created a select option through coding. I am not able to find out any method or class for that.
    please advice.

    Hi Sachin ,
         If you want ot use the methods in the class CL_WDR_SELECT_OPTIONS.
    You can find here:-
    [WDR_SELECT_IPTIONS|https://cw.sdn.sap.com/cw/docs/DOC-20864.pdf]
    Check these if can find ur required one.
    If you are using any ui element then you can use ON_ENTER event as a action as stated by Baskaran.
    Check also if these threads can help you:-
    [WebDynpro ABAP select options method SET_VALUE_OF_PARAMETER_FIELD;
    [http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/60474842-91ca-2b10-3390-d2fd30f335fd]
    Thanks & Regards,
    Monishankar Chatterjee

Maybe you are looking for