on 10-14-2009 3:52 PM
Hi team,
I have some doubts on how do i validate a particular field for character or numeric in web dynpro. Can anybody please help me with the step by step solution for the same.
Thanks and Regards
Hi,
Does your input field have F4 help.
if it has then you can validate using foriegn key relationship.
no need to code exclusivley.
if F4 help is not there then you need to follow the procedure as mentioned above by others.
Regards,
Priya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Create a attribute of type matnr and bind it to the i/p field and In the event handler of input field write down following code.
DATA lo_el_context TYPE REF TO if_wd_context_element.
DATA ls_context TYPE wd_this->element_context.
DATA lv_matnr LIKE ls_context-matnr.
* get element via lead selection
lo_el_context = wd_context->get_element( ).
* get single attribute
lo_el_context->get_attribute(
EXPORTING
name = `MATNR`
IMPORTING
value = lv_matnr ).
SELECT SINGLE matnr FROM mara into lv_matnr WHERE matnr eq lv_matnr. " Here give your table name, I am assuming it mara
check sy-subrc ne 0.
* 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_error_message
EXPORTING
message_text = 'Material does not exist in Master Table'.
I hope it helps.
Regards,
Rohit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sabyasachi,
You can check using the below abap code in event handler ( may be button click).
To check whether a variable lv_name is numeric:
lv_tst_string = '0123456789'
IF lv_name CO lv_tst_string.
ENDIF.
To check for non numeric code you can use :
lv_tst_string = '0123456789'
IF lv_name NA lv_tst_string.
ENDIF.
CO : Used for Contains Only
NA : Contains Not any
But these relational operators work only with data types C,N,D,T or string.
I hope it helps.
Please let me know in case of issues.
Regards,
Sumit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Sumit,
thanks for the reply, see what i want is i have one inputfield which is binded to the matnr, now my requirement is when the enduser enters the value the it should give a message whether the value exists in the master or not. if the value exists then it will process the dynpro if the value doesnot exists then it will throw an error, if you can send me an example of how to do it will appreciate..
Hope i shold get an answer.
Regards..
hi Sumit,
thanks for the reply, see what i want is i have one inputfield which is binded to the matnr, now my requirement is when the enduser enters the value the it should give a message whether the value exists in the master or not. if the value exists then it will process the dynpro if the value doesnot exists then it will throw an error, if you can send me an example of how to do it will appreciate..
Hope i shold get an answer.
Regards..
hi sabyasachi ,
in the event handler , or any other method where u wish to do validations , u may proceed like this :
1 Read the context attribute of ur input field , let us say the context attribute is lv_att , under the context node node
u can do it using get_attribute method , with the help of codewizard ( CNTRL + F7 ).
select the radio button read context node /attribute there to read the attribute under particualar node
DATA lo_nd_node TYPE REF TO if_wd_context_node.
DATA lo_el_node TYPE REF TO if_wd_context_element.
DATA ls_node TYPE wd_this->element_node.
DATA lv_att LIKE ls_node-att.
* navigate from <CONTEXT> to <NODE> via lead selection
lo_nd_node = wd_context->get_child_node( name = wd_this->wdctx_node ).
* get element via lead selection
lo_el_node = lo_nd_node->get_element( ).
* get single attribute
lo_el_node->get_attribute(
EXPORTING
name = `ATT`
IMPORTING
value = lv_att ).
2 now lv_att contains the value which user has entered . u need to validate this entered value , with the value in the parent table
3 now using the simple ABAP syntax , u can validate whether the parent master table contains the value lv_att
I hope it wud help
regards,
amit
DATA : lv_matnr type string .
select single matnr from <table-name> into lv_matnr where matnr EQ lv_att.
if lv_att value doesnot exist in the parent table , u can generate a error message using message manager .
again this is very simple , u can generate message thru code wizard by checking the radio button Generate message
IF sy-subrc NE '0' .
// lv_att value is not in the parent table
* 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_error_message
EXPORTING
message_text = 'entered value does not exist in the parent table' .
ENDIF
Edited by: amit saini on Oct 15, 2009 5:49 AM
Hello Sabyasachi,
You need to code for data validation in the event that will happen after data input. For example an execute event. At that event check that the field is character or numeric and depending on that you may raise an error message or execute the program.
Hope this helps.
Regards
Prasenjit
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.