Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Problematic

Sometimes you need to have an input field in read-only with F4 Help capability for several reasons:

  • You don't want the user to enter an ID because most of the time he doesn’t know it!
  • You don't want the user to change the ID after he selected it in the F4 Help!
  • You don’t want to put extra coding to check if the value is correct in WDDOBEFOREACTION or ONENTER methods; the less code you have, the better the maintenance and don't forget: Run Simple!

Unfortunately, if you switch you input field to read-only, Web Dynpro does not display the F4 Help button anymore.

The goal of this article is to show you how to make this possible via public WD APIs.

Prerequisites

You have already a Web Dynpro application with a context element already bound to an input field and working at runtime.


Steps

Context

For the sake of this example, let's define the following context:

  1. The name of the WD Context Structure is ‘AGS_S_PLUGIN
  2. The name of the WD Context Element is ‘CLASS_NAME
  3. The Element is bound to a search help (here we select a class)


Trigger the Search Help

Here is the read-only input field with the button to trigger the search help:

  1. Set the WD Input Field to read-only in the View (property named ‘readOnly’)
  2. Create a button to trigger the Search Help (ideally with only the Search Help icon, no title)
  3. Create a handler for the 'onAction' event of the button and put the code below in it

method onactionbrowse_class .

data lo_nd_plugin type ref to if_wd_context_node.
data ls_plugin type ags_s_plugin.
data lo_view  type ref to if_wd_view.
data lr_structure type ref to data.

" Get the view
lo_view ?= wd_this
->wd_get_api( ).

" Get the Plugin attribs
lo_nd_plugin
= wd_context->get_child_node( name = wd_this->wdctx_plugin ).
lo_nd_plugin
->get_static_attributes(
  
importing
     static_attributes
= ls_plugin ).

" Get the struct ref
get reference of ls_plugin into lr_structure.

" Call the search help
wd_this
->wd_get_api( )->get_component( )->

  get_window_manager( )->open_value_help(
    search_term    
= 'Select a Plugin Class'" Search Term (Label)
    view           
= lo_view                " Web Dynpro: View Controller
    event_handler  
= 'EVT_F4_HELP_SELECTED' " Name of Event Handler
    fieldname      
= 'CLASS_NAME'           " Field Name
   
structure       = lr_structure           " Structure
    multi_select   
= abap_false             " Multiple selection
).

endmethod.

You can notice that you pass an event name to handle the user’s selection.

The rest is self-explanatory.


When clicking on the button you should have the F4 Help pop-up appearing:


Handle the Search Help Event

  1. In the view, create an event handler method named ‘EVT_F4_HELP_SELECTED’
  2. Put the generic code below:

method evt_f4_help_selected .

data lo_nd_plugin type ref to if_wd_context_node.
data ls_plugin type wd_this->element_plugin.
data l_parameter type wdr_event_parameter.
field-symbols <lft_table_field_vals> type any table.
field-symbols <lft_table_fields> type any table.
field-symbols <lfs_field_new_value> type any.
field-symbols <lfs_field_value> type any.

" Get the context
lo_nd_plugin_edit
= wd_context->get_child_node( name = wd_this->wdctx_plugin_edit ).
lo_nd_plugin_edit
->get_static_attributes(
  
importing
    static_attributes
= ls_plugin_edit ).

" Get the fields (here only ‘CLASS_NAME’ is in the list)
read table wdevent->parameters
 
with table key name = `EXPORT_PARAMETER_TAB`
 
into l_parameter.
assign l_parameter-value->* to <lft_table_fields>.


loop at <lft_table_fields> assigning field-symbol(<lfs_field>).
 
" Get the selection
 
read table wdevent->parameters
   
with table key name = `RESULT_TAB`
   
into l_parameter.
 
assign l_parameter-value->* to <lft_table_field_vals>.

 
" Get the values
 
loop at <lft_table_field_vals> assigning field-symbol(<lfs_table_field_val>).
   
" Get the field new value
   
assign component <lfs_field> of structure <lfs_table_field_val> to <lfs_field_new_value>.

   
" Get the field current value
   
assign component <lfs_field> of structure ls_plugin to <lfs_field_value>.

   
" Change value
    <lfs_field_value>
= <lfs_field_new_value>.
 
endloop.
endloop.

" Trigger changes?
if lines( <lft_table_fields> ) > 0.
 
" Update WD context
  lo_nd_plugin
->set_static_attributes(
   
exporting
      static_attributes
= ls_plugin ).
endif.

method.

This code is generic for the single value selection in the search help, for multiple values, you’ll need to adapt if.

The first list contains the field ‘CLASS_NAME’. It can be, in your structure, that you linked 2 fields together with a search help, for instance a WD Component and a WD View; when you select the view of a component, you will have 2 fields in it: one for the Component and one for the View.

The second list contains the user selection values with your structure. Here this is a single selection, then you’ll get one line.

The code within the second loop will assign each value from what the user has selected to the current WD context structure.

In the end, the WD structure is set and the selection appears in the read-only input field.

After the selection here is you read-only input field filled with the selected value:

Clear the Input Field

And once you did all of this, you may wonder how to empty the input field !

If you are the owner of the search help, you can always add a blank line at the beginning, then selecting it would empty the input field.

The other option is to add a second button.

Here is the F4 help pop-up with a blank line:

Et voila, that's it!

2 Comments