on 04-24-2013 10:58 AM
Hello Guys,
Want to validate of Quantity field in PO of Standard SRM Webdynpro Component, when you enter 0 in qty field and pressing ENTER button, it should display an Error Message. my Code is working fine if there is one line item, but my code is not working, if there is 2 line items , i mean its not displaying any error message, can any please let me know , how to read 2nd line item , please help me
Thanks
Vijaya
This is my Code
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( ).
DATA lo_nd_items TYPE REF TO if_wd_context_node.
DATA lo_el_items TYPE REF TO if_wd_context_element.
DATA ls_items TYPE wd_this->element_items.
DATA lv_quantity TYPE wd_this->element_items-quantity.
* navigate from <CONTEXT> to <ITEMS> via lead selection
lo_nd_items = wd_context->path_get_node( path = `COMP_CONTEXT.ITEMS` ).
* @TODO handle non existant child
* IF lo_nd_items IS INITIAL.
* ENDIF.
* get element via lead selection
lo_el_items = lo_nd_items->get_element( ).
* alternative access via index
* lo_el_items = lo_nd_items->get_element( index = 1 ).
* @TODO handle not set lead selection
IF lo_el_items IS INITIAL.
ENDIF.
* get single attribute
lo_el_items->get_attribute( EXPORTING name = `QUANTITY` IMPORTING value = lv_quantity ).
if lv_quantity = 0.
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 = 'Please Enter Quantity' " Give your error text here
* params =
* msg_user_data =
* is_permanent = ABAP_FALSE
* scope_permanent_msg = CO_MSG_SCOPE_CONTROLLER
* view =
* show_as_popup = "VIEW_NAME" " Give Your View Name Here
* controller_permanent_msg =
* msg_index =
* cancel_navigation =
* enable_message_navigation =
* receiving
* message_id =
.
endif.
endmethod.
Hi,
In your code quantity field validation is happening only for first line item it is because the code
""* get single attribute
lo_el_items->get_attribute( EXPORTING name = `QUANTITY` IMPORTING value = lv_quantity ).""
will fetch always lead selected node only i.e only one row info.So inorder to validate even the second row fetch all the line items by GET_STATIC_ATTRIBUTE_TABLE method and perform validation on each line item.We need to change code as below ..
DATA lo_nd_items TYPE REF TO if_wd_context_node.
DATA lo_el_items TYPE REF TO if_wd_context_element.
DATA ls_items TYPE wd_this->element_items.
DATA itab_items TYPE wd_this->elements_items.
DATA lv_quantity TYPE wd_this->element_items-quantity.
lo_nd_items = wd_context->path_get_node( path = `COMP_CONTEXT.ITEMS` ).
* get element via lead selection
lo_el_items = lo_nd_items->get_element( ).
CALL METHOD lo_nd_items->get_static_attributes_table
* EXPORTING
* from = 1
* to = 2147483647
IMPORTING
table = itab_items.
loop at itab_items into ls_items.
if ls_items-quantity eq 0.
CALL METHOD lo_api_controller->get_message_manager
RECEIVING
message_manager = lo_message_manager.
CALL METHOD lo_message_manager->report_error_message
EXPORTING
message_text = 'Please Enter Quantity' " Give your error text here.
endif.
endloop.
Note:Assign points if helpful.
Thanks,
Nandi.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Instead of this code...
* @TODO handle non existant child
* IF lo_nd_items IS INITIAL.
* ENDIF.
* get element via lead selection
lo_el_items = lo_nd_items->get_element( ).
* alternative access via index
* lo_el_items = lo_nd_items->get_element( index = 1 ).
* @TODO handle not set lead selection
IF lo_el_items IS INITIAL.
ENDIF.
* get single attribute
lo_el_items->get_attribute( EXPORTING name = `QUANTITY` IMPORTING value = lv_quantity ).
Replace below code..
* get element via lead selection
lo_el_items = lo_nd_items->get_element( ).
* get all declared attributes
context_element->get_static_attributes(
IMPORTING
static_attributes = ls_items ).
If ls_items-quantity = 0.
your error message.
endif.
Before this, you have to create parameter at parameter tab.
after ed_event parameter tab create like this.
CONTEXT_ELEMENT ( Check ref to ) associated type = IF_WD_CONTEXT_ELEMENT.
Try with this it will work.
Cheers,
Kris.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.