Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

This is a continuation of a previous document which I discussed custom popup search helps on Adobe Forms for HCM Process and Forms:

Part 7: basic (but tricky) HCM Process and Forms scenario (Popup Search Helps):  http://scn.sap.com/docs/DOC-39487

This document uses the same components we created in the prior documents.  The only difference is that now we want to do real time validation and data retrieval when a user enters anything into a specifc form field.  This is great for real time field value validation without having to hit the "Check and Send" button.  Field validation is normally done with the "Check and Send" in a backend service.  However, most users want some kind of real time field validation and that's what this document covers.  Another good option for using this method is for returning texts.  For example, if a user types an employee number into a form field, you can automatically, and real time, bring the employee's name back to another field on the form.  And all this is done in the background.  Of course, all of this is for online forms.

Building upon the previous example, I want to modify the form so if a user types in a State value, the form will automatically validate the state and retreive the State text for display on the form.

Open your form and go to the “exit” event of your STATE field.  Make sure to select JavaScript.  Enter the following code:

//send values to WebDynPro

xfa.resolveNode("SEARCH_WINDOW_NAME").rawValue = "ASR_NOPOPUP_SEARCH";  //WebDynPro Window Name

xfa.resolveNode("SEARCH_VALUE_GET_1").rawValue = "STATE";               //Pass This Value In For Validation

xfa.resolveNode("SEARCH_VALUE_GET_2").rawValue = "";                    //Pass This Value In For Validation

xfa.resolveNode("SEARCH_VALUE_GET_3").rawValue = "STATE_CHK";           //Which Validation routine

//receive values from WebDynPro

xfa.resolveNode("SEARCH_VALUE_SET_1").rawValue = "STATE";               //Return This Value From Validation 

xfa.resolveNode("SEARCH_VALUE_SET_2").rawValue = "";                    //Return This Value From Validation

xfa.resolveNode("SEARCH_VALUE_SET_3").rawValue = "";                    //Return This Value From Validation

//Process The Call To SAP

xfa.record.CONTROL_PARAM.ISR_EVENT.value = "USER_EVENT_POPUP";

xfa.record.HRASR_FORM_WINDOW.DATA.FIELD.value = "ZHRASR_MY_SEARCH_HELP"; //WebDynPro Name

ContainerFoundation_JS.SendMessageToContainer(event.target, "submit", "", "", "", "");

Now go to your WebDynro:  ZHRASR_MY_SEARCH_HELP

Create a new window called:  ASR_NOPOPUP_SEARCH

Create a new view called: NOPOPUP_SEARCH

Adjust the window structure to look as follows:

In the view context, drag the component controller context node over to the view:

Add the following code to the method WDDOINIT of the view NOPOPUP_SEARCH:

********************************************************************************************
* Get all the data from the form
 
data lo_nd_special_data type ref to if_wd_context_node.
 
data lt_special_data type wd_this->elements_special_data.

  lo_nd_special_data
= wd_context->get_child_node( name = wd_this->wdctx_special_data ).
  lo_nd_special_data
->get_static_attributes_table( importing table = lt_special_data ).
********************************************************************************************

 
data lo_nd_value_help_data type ref to if_wd_context_node.
 
data lt_value_help_data type wd_this->elements_value_help_data.


  lo_nd_value_help_data
= wd_context->get_child_node( name = wd_this->wdctx_value_help_data ).
  lo_nd_value_help_data
->get_static_attributes_table( importing table = lt_value_help_data ).

 
data: l_qisrsspecial_param type qisrsspecial_param.
 
data: wa_special_data type qisrsspecial_param.
 
data: value_help_data type wd_this->element_value_help_data.
 
data: value_help_datas type wd_this->elements_value_help_data.
 
data: node_value_help_data type ref to if_wd_context_node.
 
data: l_value_set_1 type qisrdfieldvalue.
 
data: l_value_set_2 type qisrdfieldvalue.
 
data: l_value_set_3 type qisrdfieldvalue.
 
data: l_field type qisrdfieldvalue.

 
define clear_form_field.
   
read table lt_value_help_data with key fieldname = &1 into l_qisrsspecial_param.
   
if sy-subrc eq 0.
      l_field
= l_qisrsspecial_param-fieldvalue.
     
if not ( l_field is initial ).
        value_help_data
-fieldname = l_field.
        value_help_data
-fieldindex = 1.
        value_help_data
-fieldvalue = ''.
       
append value_help_data to value_help_datas.
        node_value_help_data
= wd_context->get_child_node( name = wd_this->wdctx_value_help_data ).
        node_value_help_data
->bind_table( value_help_datas ).
     
endif.
   
endif.
 
end-of-definition.

 
define set_form_field_value.
   
read table lt_value_help_data with key fieldname = &1 into l_qisrsspecial_param.
   
if sy-subrc eq 0.
      l_field
= l_qisrsspecial_param-fieldvalue.
     
if not ( l_field is initial ).
        value_help_data
-fieldname = l_field.
        value_help_data
-fieldindex = 1.
        value_help_data
-fieldvalue = &2.
       
append value_help_data to value_help_datas.
        node_value_help_data
= wd_context->get_child_node( name = wd_this->wdctx_value_help_data ).
        node_value_help_data
->bind_table( value_help_datas ).
     
endif.
   
endif.
 
end-of-definition.

 
read table lt_value_help_data with key fieldname = 'SEARCH_VALUE_GET_1' into l_qisrsspecial_param.
 
if sy-subrc eq 0.
*   we have the form field name of field we need to validate
    l_value_set_1
= l_qisrsspecial_param-fieldvalue.

*   there may be a second field to needed to assist with validation
   
read table lt_value_help_data with key fieldname = 'SEARCH_VALUE_GET_2' into l_qisrsspecial_param.
   
if sy-subrc eq 0.
      l_value_set_2
= l_qisrsspecial_param-fieldvalue.
   
endif.

*   there should be a third field to indicate which validation routine to use
   
read table lt_value_help_data with key fieldname = 'SEARCH_VALUE_GET_3' into l_qisrsspecial_param.
   
if sy-subrc eq 0.
      l_value_set_3
= l_qisrsspecial_param-fieldvalue.
   
endif.

*   we have to find the form field value for the name above
   
sort lt_special_data by fieldname as text fieldindex.
   
read table lt_special_data into wa_special_data with key fieldname = l_value_set_1.
   
if sy-subrc eq 0.
     
case l_value_set_3.
       
when 'STATE_CHK'.
         
data: l_bland type regio.
         
data: l_state type regio.
         
data: l_state_txt type bezei20.

          l_bland
= wa_special_data-fieldvalue.
         
select single bland bezei from t005u into (l_state, l_state_txt)
           
where spras = 'EN'
             
and land1 = 'US'
             
and bland = l_bland.
         
if sy-subrc = 0.
            set_form_field_value
'SEARCH_VALUE_SET_1' l_state.
            set_form_field_value
'SEARCH_VALUE_SET_2' l_state_txt.
            set_form_field_value
'SEARCH_VALUE_SET_3' ''.
         
else.
            clear_form_field
'SEARCH_VALUE_SET_1'.
            clear_form_field
'SEARCH_VALUE_SET_2'.
            clear_form_field
'SEARCH_VALUE_SET_3'.
         
endif.
     
endcase.
   
else.
*     no value found - do nothing
   
endif.
 
else.
   
clear l_value_set_1.
 
endif.

********************************************************************************************
* Close the pop up before it opens
 
data lv_wc type ref to if_wd_window_controller.
 
data lv_view type ref to if_wd_view_controller.
 
data lo_window  type ref to if_wd_window.

  lv_view
= wd_this->wd_get_api( ).
  lv_wc
= lv_view->get_embedding_window_ctlr( ).
  lo_window
= lv_wc->get_window( ).
  lo_window
->close( ).
********************************************************************************************

Now you can test your form.  You will see that when a State is entered, that the text for the state is returned automatically without having to press the "Check and Send" button.  It was also very easy to add this field validation/text retrieval capability to the existing webdynpro we created in the previous example.  Hopefully you can see how generic this has become and how adaptable it can be.

1 Comment
Labels in this area