
Background:
In Many scenarios, the End User would like to see the list of values matching the value that the User has entered in a field. This would help the User to select the appropriate value with ease without any difficulty.
This in turn leads to User able to fill the right values in the field without any difficulty and in turn leads to complete the work Effectively and Efficiently.
This blog describes the steps in detail to display list of matching values entered by the user in a field so that the user will be able to pick the values accordingly.
Pre-Requisites:
Database table having the values:
Structure and Table Type:
Field where the User will enter the value:
In the above field, once the User gives the value and presses Enter the user will get a Pop Up having list of matching values and the user will be able to select the correct value from the Pop Up.
Steps:
Step 1:
Create an Event in the Context node Class in the Event tab of the Context Node Class. Go to Parameters and give the Parameters for the Event.
Step 2:
Now go to the Set Method of the Attribute and add the code to raise the Event incase the value has in the field has been changed.
Step 3:
Now go to the IMPL Class and add the below attributes:
Step 4:
Now Create a New method in the IMPL Class to react to the Event ( once the event is raised from the SET method ).
Step 5:
Click on Parameters Button
Step 6:
Now add Code inside the method to get the values to be displayed in the Popup and to call the Popup Close Event.
Step 7:
Now Create an Event to get triggered once the Popup is Closed.
Step 8:
Now register in the DO_INIT_CONTEXT method.
Detailed Explanation:
Step 1:
Create an Event in the Context node Class in the Event tab of the Context Node Class:
Go to Parameters and give the Parameters for the Event.
Step 2:
Now go to the Set Method of the Attribute and add the code to raise the Event incase the value has in the field has been changed.
Code given in above screenshot is given below:
*****************************************************************************
* In this section we check of the New Value is Different from the Old Value and if yes then we raise the Event.
* We set the value in the Pop Up Close Event
*****************************************************************************
* Only set new value if value has changed
IF <nval> <> <oval>.
* Here we are raising the Event
raise event name_changed EXPORTING current = current
search_term = <nval>.
ENDIF.
Step 3:
Now go to the IMPL Class and add the below attributes:
Step 4:
Now Create a New method in the IMPL Class to react to the Event (Once the event is raised from the SET method).
Step 5:
Click on Parameters Button
Step 6:
Now add Code inside the method to get the values to be displayed in the Popup and to call the Popup Close Event.
Code given in above screenshot is given below:
******************************************************************
*This method gets trigerred when the Event NAME_CHANGED is
*trigerred in the SET Method of the Attribute
*****************************************************************
method ON_NAME_CHANGED.
*******************************************************************
* Data declaration
*******************************************************************
DATA : LV_VALUE TYPE CHAR40,
LV_VALUE1 TYPE CHAR40,
LV_LINES TYPE INT4.
CONSTANTS : LC_PER TYPE CHAR1 VALUE '%'.
*******************************************************************
*In this section we check if the Search term is Not Initial.
*If the Serach term is filled , then we select the relevant values
*from the Database Table and display the values in a Pop up.
*******************************************************************
*Checking if the Search term is not initial
IF SEARCH_TERM IS NOT INITIAL.
* Assigning the Search Term to a Variable
LV_VALUE = SEARCH_TERM.
* Concatenating
CONCATENATE LV_VALUE LC_PER INTO LV_VALUE1.
* Selecting from the Database Table
SELECT * FROM ZNAME INTO TABLE GT_NAME_TAB WHERE NAME LIKE LV_VALUE1.
* Cehcking if the Internal Table is Not Initial
IF GT_NAME_TAB[] IS NOT INITIAL.
* Checking the Number of Lines in the Internal table
DESCRIBE TABLE GT_NAME_TAB LINES LV_LINES.
* Calling a Pop Up to display the values
dec_popup = comp_controller->window_manager->create_decision_popup(
iv_title = 'Multiple values found'
iv_description = 'Please select one VALUE'
iv_visible_row_count = LV_LINES
iv_display_table = gt_name_tab ).
* calling the Pop Up Close Event
dec_popup->set_on_close_event( iv_event_name = 'NAME_POPUP_CLOSED'
iv_view = me ).
gv_current = current.
* Opening the Pop Up
dec_popup->open( ).
ENDIF. "End of IF GT_NAME_TAB[] IS NOT INITIAL.
ENDIF. "Ënd of IF SEARCH_TERM IS NOT INITIAL.
endmethod.
Step 7:
Now Create an Event to get triggered once the Popup is Closed.
Now add the Code in the Pop up Close Event Handler.
Code given in above screenshot is given below:
******************************************************************
*This method gets trigerred when the Pop Up is Closed
******************************************************************
method EH_ONNAME_POPUP_CLOSED.
******************************************************************
*Data Declarations
******************************************************************
DATA : lr_outputnode TYPE REF TO cl_bspwdcmp_bspwdcomponen_cn01,
lv_index TYPE i,
lv_value TYPE char40,
WA_NAME LIKE LINE OF GT_NAME_TAB.
FIELD-SYMBOLS: <fs_prods> TYPE ZTEST_JAN2024.
* Getting the Context Node details
lr_outputnode ?= dec_popup->get_context_node( 'OUTPUTNODE' ).
* Getting the selected row Index
lv_index = lr_outputnode->get_selectedrowindex( ).
FREE dec_popup.
* Read the Internal table to get the value of the Selected Index
READ TABLE GT_NAME_TAB INDEX lv_index INTO WA_NAME.
* Checking the value of sy-subrc
CHECK sy-subrc = 0.
WRITE WA_NAME-NAME to LV_VALUE.
* Setting the selected value to the Field
gv_current->set_property( iv_attr_name = 'FIELD2'
iv_value = lv_value ).
endmethod.
Step 8:
Now register in the DO_INIT_CONTEXT method.
Code given in above screenshot is given below:
method DO_INIT_CONTEXT.
CALL METHOD SUPER->DO_INIT_CONTEXT.
SET HANDLER ON_NAME_CHANGED FOR TYPED_CONTEXT->ZTEST.
endmethod.
Now let us Test.
The below is the field where the user will enter the value.
Scenario 1:
Give the value A and Press Enter.
We can see all the Values in the Database table starting with A.
Database Table screenshot:
On selecting a value in the Pop Up the selected value gets filled in the field:
Scenario 2:
Give the value B and Press Enter.
We can see all the Values in the Database table starting with B.
Database Table screenshot:
On selecting a value in the Pop Up the selected value gets filled in the field:
By this the User will be able to select the correct value and complete the work much efficiently and effectively.
End of Document.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.