cancel
Showing results for 
Search instead for 
Did you mean: 

validate select option in webdynpro

former_member190689
Contributor
0 Kudos

Hello Gurus,

      I have created a webdynpro application including a select option(matnr) and alv table.Now my problem is without entering any data into select option , if the user clicks on submit button whole data related to matnr is shown.

How could I validate it with message to enter matnr first.

I wrote the code in WDDOBEFOREACTION but its not working.

Thanks in advance

Gaurav Gautam

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Gaurav

              You can write the validations in WDDOINIT. Raise an error message if the field is initial.

former_member190689
Contributor
0 Kudos

Hi Jula,

   

   Could you please explain with the code as it would be a great help.BEfore that I would like to say this that I wrote a loop statement with making fs_matnr-low and high - blank .then using exit command. But still its not working .

Thanks

Gaurav

Former Member
0 Kudos

Hi Gaurav

              I believe that you know the steps to get the select options screen, range table & selected field in your view controller on WDDOINIT method. Now, On action method where the select option field to trigger, just rewrite the below code according to your naming convention:

DATA: NODE TYPE REF TO IF_WD_CONTEXT_NODE.

DATA: RT_carrid TYPE REF TO DATA. (Field that you need to assign for select option)

 

   FIELD-SYMBOLS: <FS_CARRID> TYPE TABLE. (Field symbol to get the data)

* Retrieve the data from the select option

RT_CARRID = WD_THIS->M_HANDLER->GET_RANGE_TABLE_OF_SEL_FIELD( I_ID = 'S_CARR_ID' ).

* Assign it to a field symbol

   ASSIGN RT_CARRID->* TO <FS_CARRID>.

if <FS_CARRID> is initial.

* get message manager

DATA lo_api_controller     TYPE REF TO if_wd_controller.

DATA lo_message_manager    TYPE REF TO if_wd_message_manager.

lo_api_controller ?= wd_this->wd_get_api( ).

CALL METHOD lo_api_controller->get_message_manager

   RECEIVING

     message_manager = lo_message_manager

     .

* report message

CALL METHOD lo_message_manager->raise_t100_error

   EXPORTING

     msgid         =

     msgno         =

     msgty         =

*    p1            =

*    p2            =

*    p3            =

*    p4            =

*    msg_user_data =

endif.

Hope this will do the needful. If your facing any error please write here.

Thanks

Jula

Answers (4)

Answers (4)

Former Member
0 Kudos

Dear Gaurav.

I think the easierst way to do that is to edit the UI Element Inputfield 'state' from normal to required. After that you can check if the Inputfield is initial. When it is initial dont select any data and do nothing. Maybe in wddomidifyview, when you want the message in every step in the view, or in the onaction/onenter method of the inputfield or check-in Button.

The web Dynpro framework realize, that the inputfield (repuired) is initial and makes it light red. Or you can show your own message

Context:

GO_MESSAGE TYPE IF_WD_MESSAGE_MANAGER

Initialize the Message Controller:

DATA: lo_api_controller  TYPE REF TO if_wd_controller,
            lo_message_manager TYPE REF TO if_wd_message_manager.

lo_api_controller ?= wd_this->wd_get_api( ).
CALL METHOD lo_api_controller->get_message_manager
   RECEIVING
     message_manager = wd_this->go_message.

Show Message:

wd_this->go_message->report_error_message( 'Error Message' ).

Former Member
0 Kudos

hi ,

In submit button action instantiate select-options component and get range table..

Check that range table is initial or not.. if initial means using code wizard raise error message using

if_wd_message_manager...

Hope this will be helpful for u..

former_member230486
Contributor
0 Kudos

Hi Gaurav,

You have to write error message if the user not entered into select-options in the Submit button.

From the code wizard Generate Message(Which ever you want from the drop down).

Former Member
0 Kudos

Hi,

Go through the tutorial below. In the below example by checking the emptiness of the field symbol you can validate the user entry.  Cross reference the code you have written. It should work fine in the dobeforeaction method.

http://webdynproabap.wordpress.com/2012/10/06/read-select-option/

Best Regards,

Arun Krishnamoorthy

former_member190689
Contributor
0 Kudos

Hi Arun,

    

       The tutorial is great but its about how to read a value from select options.But my concern is how to validate select option.Rest of the code is working fine.I am able to fetch the data and also able to edit that data in alv.But when I dont provide any data in the select option and if I press enter then also whole data is being displayed.My concern is to stop that thing.Could you please tell me how to stop that. I have wrote the code in dobeforeaction but its not working.

Thanks

Gaurav

Former Member
0 Kudos

Hi,

you can write below code like this under WDDOINIT (  ).

data v_ebeln type ekko-ebeln.

select single ebeln

          from ekko

          into v_ebeln

         where ebeln =  s_ebeln.

   CALL METHOD LO_API_CONTROLLER->GET_MESSAGE_MANAGER

     RECEIVING

       MESSAGE_MANAGER = LO_MESSAGE_MANAGER

       .

*   report message

   CALL METHOD LO_MESSAGE_MANAGER->REPORT_MESSAGE

     EXPORTING

       MESSAGE_TEXT              = 'Enter valid input values'.

*      MESSAGE_TYPE              = CO_TYPE_ERROR

*      PARAMS                    =

*      MSG_USER_DATA             =

*      IS_PERMANENT              = ABAP_FALSE

*      SCOPE_PERMANENT_MSG       = CO_MSG_SCOPE_CONTROLLER

*      VIEW                      =

*      SHOW_AS_POPUP             =

*      CONTROLLER_PERMANENT_MSG  =

*      MSG_INDEX                 =

*      CANCEL_NAVIGATION         =

*      ENABLE_MESSAGE_NAVIGATION =

*    RECEIVING

*      MESSAGE_ID                =

       .

former_member230486
Contributor
0 Kudos

Hi Gaurav,

You have to write the code in the Submit button as shown below,

DATA LT_RANGE TYPE REF TO DATA.
FIELD-SYMBOLS <FS_EBELN> TYPE TABLE.
if not lt_range is INITIAL.
CALL METHOD wd_this->go_select->get_range_table_of_sel_field
   EXPORTING
     i_id           = 'EBELN'
   receiving
     rt_range_table = LT_RANGE
     .
ASSIGN LT_RANGE->* TO <FS_EBELN>.

   DATA lo_nd_item_details TYPE REF TO if_wd_context_node.

   DATA lt_item_details TYPE wd_this->elements_item_details.

* navigate from <CONTEXT> to <ITEM_DETAILS> via lead selection
   lo_nd_item_details = wd_context->get_child_node( name = wd_this->wdctx_item_details ).

* @TODO handle non existant child
* IF lo_nd_item_details IS INITIAL.
* ENDIF.
SELECT *
   FROM EKPO
   INTO CORRESPONDING FIELDS OF TABLE lt_item_details
  WHERE EBELN IN <FS_EBELN>.
** @TODO compute values
** e.g. call a model function
*
   lo_nd_item_details->bind_table( new_items = lt_item_details set_initial_elements = abap_true ).
else.
* get message manager
DATA lo_api_controller     TYPE REF TO if_wd_controller.
DATA lo_message_manager    TYPE REF TO if_wd_message_manager.

lo_api_controller ?= wd_this->wd_get_api( ).

CALL METHOD lo_api_controller->get_message_manager
   RECEIVING
     message_manager = lo_message_manager
     .

* report message
CALL METHOD lo_message_manager->raise_error_message
   EXPORTING
     message_text  = 'Enter the Data in Selec-Options'
*    params        =
*    msg_user_data =
     .

endif.

Former Member
0 Kudos

Hi Gaurav,

The tutorial which i gave you is about readin the values entered in the select options. By reading the value you get the value in the field symbol. By checking the emptiness of the field symbol you can get to know whether the user has entered the value or not and then throw the error message.

Otherwise mark the field as mandatory by setting the i_obligatory(add_selection_field) option while creating the selection field and follow the procedure in which system will check for mandatory attributes in the screen and terminate the process in case mandatory attributes are not filled.

Write the following code in dobefore action after setting the select option field as mandatory.

* Data declaration

  DATA: LT_MSG             TYPE        CL_WD_DYNAMIC_TOOL=>T_CHECK_RESULT_MESSAGE_TAB, " Internal table:   Importing the message
        LO_VIEW_CONTROLLER TYPE REF TO IF_WD_VIEW_CONTROLLER.                          " Object reference: View controller

* Getting the object reference of the view controller

  LO_VIEW_CONTROLLER ?= WD_THIS->WD_GET_API( ).

* Call the method check mandatory attributes to check the mandatory attributes in the view

  CL_WD_DYNAMIC_TOOL=>CHECK_MANDATORY_ATTR_ON_VIEW(
  EXPORTING
  VIEW_CONTROLLER = LO_VIEW_CONTROLLER
  DISPLAY_MESSAGES = ABAP_TRUE
  IMPORTING
  MESSAGES = LT_MSG ).

Hope this would help.

Best regards,

Arun Krishnamoorthy