cancel
Showing results for 
Search instead for 
Did you mean: 

Validating Screen Input

Former Member
0 Kudos

Hi,

I ahve a WDA application, with a view. This view has 4 fields, Order Type (AUART), Sales Org (VKORG), Distribution Channel and Division. On click of the button I would like to validate the data enetered by the user in these fields. I have created a node and the attributes in the view context.

In the onclick event of the button I have written the following code:

i_childnode = wd_context->get_child_node( 'SALES_INITIAL' ).

What code should I write further, to access the values entered by the user on the screen.

Any help would be greatly appreciated.

Thanks

MIck

Accepted Solutions (1)

Accepted Solutions (1)

pranav_nagpal2
Contributor
0 Kudos

Hi Mick,

this is the code to get values entered by user

data lo_el_context type ref to if_wd_context_element.
    data ls_context type wd_this->element_context.
    data lv_cb1 like ls_context-cb2.
*   get element via lead selection
    lo_el_context = wd_context->get_element(  ).

*   get single attribute
    lo_el_context->get_attribute(
      exporting
        name =  `CB2`
      importing
        value = lv_cb1 ).

you can get the same code by clicking on the button code wizard in your SAP..... (button with a yellow tourch like image).. just click on that button a screen will come in that screen select read context and using f4 help select your attribute and click on ok.... you will get the similar code with value in importing parameter.. here in my code value is in lv_cb1....

regards

Pranav

Former Member
0 Kudos

Thanks Pranav.

Using the wizard, the follwoing code was included in the method

data:

Node_Sales_Initial type ref to If_Wd_Context_Node,

Elem_Sales_Initial type ref to If_Wd_Context_Element,

Stru_Sales_Initial type Wd_This->Element_Sales_Initial ,

Item_AUART like Stru_Sales_Initial-AUART.

  • navigate from <CONTEXT> to <SALES_INITIAL> via lead selection

Node_Sales_Initial = wd_Context->get_Child_Node( Name = wd_This->wdctx_Sales_Initial ).

  • get element via lead selection

Elem_Sales_Initial = Node_Sales_Initial->get_Element( ).

  • get single attribute

Elem_Sales_Initial->get_Attribute(

exporting

Name = `AUART`

importing

Value = Item_Auart ).

In debug mode, the value in Item_Auart is 'TA', whereas the user input in the field on the screen was 'OR'.

What could be the reason for this? and how do we rectify this erroneous data?

Thanks

Mick

Former Member
0 Kudos

Hi,

Check with the conversion routine for the attribute at the domain level.

Check the table TVAK for the same.

Standard order description is 'OR' and Sales document type for the same is 'TA'.

Regards,

Lekha.

pranav_nagpal2
Contributor
0 Kudos

i dont see any error in the code.... but it might be possible that it is displaying previous value...

try to invalidate the node befor asking user to enter new values......

node_name->invalidate( ).

regards

Pranav

Former Member
0 Kudos

Lekha, you are right. The conversion exit in the domain, does the trick.

Thanks,

MIck

Former Member
0 Kudos

Is there any way that I can get the values of all the fields together, instead of firing the method once each for each input field on the screen?

Thanks,

Mick.

Former Member
0 Kudos

Hi Mike,

In The code wizard while reading node, instead of selecting a single attribute select complete node, you want to read.

Former Member
0 Kudos

Hi,

use the method GET_STATIC_ATTRIBUTES of the if_wd_context_element.

Regards,

Lekha.

pranav_nagpal2
Contributor
0 Kudos

Hi Mick,

Yes you can get the whole data in an internal table of type that node and its fields are of type of attributes of that node

see the code below..

data lo_nd_cn_table type ref to if_wd_context_node.
  data lo_el_cn_table type ref to if_wd_context_element.
  data lt_table type wd_this->elements_cn_table.
  data ls_table type wd_this->element_cn_table.
  data index type i.
* navigate from <CONTEXT> to <CN_TABLE> via lead selection
  lo_nd_cn_table = wd_context->get_child_node( name =
wd_this->wdctx_cn_table ).

* @TODO handle not set lead selection
  if lo_nd_cn_table is initial.
  endif.

* get element via lead selection
  lo_el_cn_table = lo_nd_cn_table->get_element(  ).

* @TODO handle not set lead selection
  if lo_el_cn_table is initial.
  endif.

* alternative access  via index
* lo_el_cn_table = lo_nd_cn_table->get_element( index = 1 ).
* @TODO handle non existant child
* IF lo_el_cn_table IS INITIAL.
* ENDIF.

* get all declared attributes
  lo_nd_cn_table->get_static_attributes_table(
    importing
      table = lt_table ).

now lt_table contains all the data in that node....

regards

Pranav

Answers (2)

Answers (2)

arjun_thakur
Active Contributor
0 Kudos

Hi Mick,

As far as I can understand, you have four input fields on your screen and you want to access the values entered by the user. Well to do that, you must have binded each input field with an attribute. Just read that context attribute with the help of code wizard and you will get the values entered by the user.

I hope it helps.

Regards

Arjun

Former Member
0 Kudos

Hi Mike,

To Access value on entered in input box on view:

Click on web dynpro code wizard icon (Cntrl + F7)

Select Radio button Read Context

Select the context element / attribute you have binded to the text field

Automatic code will be generated to read the attribute

To Validate the field in the method:

Click on web dynpro code wizard icon (Cntrl + F7)

Select Radio Button: Generate Mesaage

Select Appropriate method as per your requirement eg REPORT_ERROR_MESSAGE

Also Exit from the code on error, to avoid further processing.