cancel
Showing results for 
Search instead for 
Did you mean: 

validating the value in the table element

Former Member
0 Kudos

hello all,

I have a column in the table element as editable and i want to validate the value entered in the editable column with value in another column.can this achieved without selecting the row in the table...like on change of value etc...

i am new to web dynpros..can any one help me on this.

with regards,

sandeep akella.

Edited by: sandeep akella on Aug 10, 2009 2:42 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

First get the table entires using the following code.

Get the data of the node to which the table is bound.

DATA:
lr_node type ref to if_wd_context_node.

lr_node = wd_context->get_child_node( 'EMP' ).  "node name

lr_node->get_elements
importing
items = lt_elements.

loop at lt_elements into ls_element

ls_element->get_static_attributes
importing
new_items = ls_table
if ls_table-pernr eq 'ABC'        "suppose PERNR is 1st column and name is 2nd column

if ls_table-name eq space.
lr_messager->
report_attribute_error_message
attribute = 'NAME'
element = ls_element
msg_text = 'Invalid'           "Your message
endif.
endif.
endloop.

Use code wizard to get the code.

Regards,

Lekha.

Answers (2)

Answers (2)

Former Member
0 Kudos

validations are done in the onbeforeaction menthod for the submit method.

Former Member
0 Kudos

can we do this more interactively like while entering the values and moving to next editable cell.

Former Member
0 Kudos

Hi, You can implement the OnEnter action and validate the contents of the cell. Regards, Radhika.

Former Member
0 Kudos

We can implement it in the 'on enter' event..thank you for that...but can it be possible as soon as we enter the value and moved to next cell by using tab or any other means ? like we caprute the 'data changed' attribute in normal alv in the dynpros.I want this scenario because i have 3 editable columns and if i write the event on enter in all the three columns it wont be done then and there and also this will work only when i press ENTER i want it to be checked before i update in database also(give me another method other than checking in the update in database event..done through push button) and also when does the 'ONACTION' event in the 'TABLE COLUMN PROPERTIES' trigger can we do at that event.

with regards,

sandeep akella.

Edited by: sandeep akella on Aug 10, 2009 4:43 PM

Edited by: sandeep akella on Aug 10, 2009 5:07 PM

Edited by: sandeep akella on Aug 11, 2009 6:22 AM

uday_gubbala2
Active Contributor
0 Kudos

Hi Sandeep,

There is no event to capture the pressing of TAB key within WDA. Why dont you go for an ALV? It would make things a lot easier for you. So the better possible way for you would to place a button on your layout (either within the ALV's toolbar or just as any other normal UI element on your layout). Within the buttons action handler you can make a call to the DATA_CHECK method of the ALV. This way whenever you press on the button it would check if any data has changed inside the ALV & if any changes have been done it would trigger the ON_DATA_CHECK event of ALV. So now you create an event handler method for the ON_DATA_CHECK event of ALV. Within this event handler method you would be able to access the details of the modified rows using R_PARAM->T_MODIFIED_CELLS & perform your validations.

Regards,

Uday

uday_gubbala2
Active Contributor
0 Kudos

Hi Sandeep,

Let me explain you through an example as to how you can achieve this validation logic by using a Table UI element. Let us suppose that am displaying the data from SFLIGHT within a table. Now I have a column in the table called "Number Of Seats Needed" which is an input field. The number of seats available for the particular flight are displayed in another column "Number Of Seats Available". (The values for this column are computed as SEATSMAX - SEATSOCC within my WDDOINIT method before I bind the internal table to my context.) I have a button within my tables toolbar upon pressing which I want to check whether the number of seats the user is trying to book are less than the number of seats available. If he is trying to book more than the number of seats available I want to throw an error message and highlight the erroneous cell within the table.

Regards,

Uday

uday_gubbala2
Active Contributor
0 Kudos

My context consists of a node by name SFLIGHT with the attributes: CARRID, CONNID, FLDATE, PRICE, SEATSMAX, SEATSOCC, SEATS_NEEDED & SEATS_AVAILABLE. The attributes SEATS_NEEDED & SEATS_AVAILABLE are both of type I. I place a table on my layout and make only the cell editor of the SEATS_NEEDED column as an input field. I want the rest of the fields to appear as readOnly.

Below is the coding inside my WDDOINIT method where in I populate the data on to my SFLIGHT context node:

METHOD wddoinit .
  DATA: lr_node TYPE REF TO if_wd_context_node,
        lt_sflight TYPE wd_this->elements_sflight,
        wa_sflight TYPE wd_this->element_sflight.


  lr_node = wd_context->get_child_node( name = wd_this->wdctx_sflight ).
  SELECT * FROM sflight INTO CORRESPONDING FIELDS OF TABLE lt_sflight.

" Calculate the number of seats available as SEATSMAX-SEATSOCC
  LOOP AT lt_sflight INTO wa_sflight.
    wa_sflight-seats_available = wa_sflight-seatsmax - wa_sflight-seatsocc.
    wa_sflight-seats_needed = 0.
    MODIFY lt_sflight FROM wa_sflight TRANSPORTING seats_available seats_needed.
    CLEAR wa_sflight.
  ENDLOOP.

  lr_node->bind_table( lt_sflight ).
ENDMETHOD.

uday_gubbala2
Active Contributor
0 Kudos

I now create a toolbar for my table and within that toolbar am creating a Toolbarbutton. Now upon pressing this button I want to validate the entries of SEATS_NEEDED against the entry in SEATS_AVAILABLE. In case of any inconsistency I not only throw an error message but also highlight the particular columns cell in which the error has occured. Below is the coding inside my buttons action handler:

METHOD onactionvalidate_booking .
  DATA: lr_node TYPE REF TO if_wd_context_node,
        lt_sflight TYPE wd_this->elements_sflight,
        wa_sflight TYPE wd_this->element_sflight,
        lr_element TYPE REF TO if_wd_context_element.

  lr_node = wd_context->get_child_node( name = wd_this->wdctx_sflight ).

" Fetch the entire tables data into an internal table for validation purpose
  lr_node->get_static_attributes_table(  EXPORTING from   = 1
                                                    to     = 2147483647
                                         IMPORTING table  = lt_sflight ).

  LOOP AT lt_sflight INTO wa_sflight WHERE seats_available <> 0.
" Check if user is trying to book more seats than what are available & throw an error message if needed
    IF wa_sflight-seats_needed > wa_sflight-seats_available.
      lr_element = lr_node->get_element( index = sy-tabix ).

" 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->report_attribute_error_message
        EXPORTING
          message_text   = 'Number of desired seats greater than available seats!'
          element        = lr_element
          attribute_name = 'SEATS_NEEDED'.
    ENDIF.
  ENDLOOP.
ENDMETHOD.

former_member189058
Active Contributor
0 Kudos

Hi Sandeep,

As there is no event that handles the tab key in wda, you may use the follwoing approach.

WDDOBEFOREACTION is the method for validation of input. This method is called before the event handler for any events defined on the view are called.

Say you have a button called 'Save' with an action 'SAVE_DATA' and you need to validate the user enteries before saving to the database.


  DATA lo_api_controller TYPE REF TO if_wd_view_controller.
  DATA lo_action         TYPE REF TO if_wd_action.

  lo_api_controller = wd_this->wd_get_api( ).
  lo_action = lo_api_controller->get_current_action( ).
  if lo_action is bound.
    case lo_action->name.
        WHEN 'SAVE_DATA'.
           perform your validations and checks here.
           if validation fails, show error message and cancel navigation.
    endcase.  
  endif.

In order to report errors, use IF_WD_MESSAGE_MANAGER.

In order to cancel navigation, use CANCEL_NAVIGATIION method of IF_WD_COMPONENT interface.

You may use the following link for further information:

http://help.sap.com/saphelp_nw70/helpdata/EN/d2/8acd409cc4dd50e10000000a1550b0/frameset.htm

Navigate to Basics -- Programming Controller Methods -- Phase Model

Hope this helps.

Regards,

Reema.