In this post we will study how to provide a OVS search help to the select options field. When we are creating an input field we will bind it to the context attribute and the mode of input help for the field depends upon the input help mode property of the context attribute. Here in select option the scenario is different. We don’t have a context attribute involved and how do we set a ovs search help. By default the field assigned to select option will have a dictionary search help and there may be a scenario where the field may not have a dictionary search help and you want to provide search help for it. Or your requirement can be you need a user defined search help instead of dictionary search help. Under such conditions we may have to set search help for select options using OVS search help.
For more information of OVS search help refer to the link:
Scenario: Imagine we have created a input field for the PO number using select options component and it contains the dictionary search help. Now let us see how to set a ovs search help for the select option.
Code in the method Doinit of the view controller for select options is as below:
data lo_cmp_usage type ref to if_wd_component_usage.
lo_cmp_usage = wd_this->wd_cpuse_select( ).
if lo_cmp_usage->has_active_component( ) is initial.
lo_cmp_usage->create_component( ).
endif.
DATA lo_INTERFACECONTROLLER TYPE REF TO IWCI_WDR_SELECT_OPTIONS .
lo_INTERFACECONTROLLER = wd_this->wd_cpifc_select( ).
DATA lv_r_helper_class TYPE ref to if_wd_select_options.
lv_r_helper_class = lo_interfacecontroller->init_selection_screen(
).
data : rt_ebeln TYPE REF TO data.
CALL METHOD lv_r_helper_class->CREATE_RANGE_TABLE
EXPORTING
I_TYPENAME = 'EBELN'
* I_LENGTH =
* I_DECIMALS =
RECEIVING
RT_RANGE_TABLE = rt_ebeln
.
CALL METHOD lv_r_helper_class->ADD_SELECTION_FIELD
EXPORTING
I_ID = 'EBELN'
IT_RESULT = rt_ebeln
* I_VALUE_HELP_TYPE = IF_WD_VALUE_HELP_HANDLER=>CO_PREFIX_NONE
.
CALL METHOD lv_r_helper_class->SET_GLOBAL_OPTIONS
EXPORTING
I_DISPLAY_BTN_CANCEL = ABAP_FALSE
I_DISPLAY_BTN_CHECK = ABAP_FALSE
I_DISPLAY_BTN_RESET = ABAP_FALSE
I_DISPLAY_BTN_EXECUTE = ABAP_FALSE
.
For more information on how to create a select options help refer to the link:
http://www.teamabap.com/2014/05/setting-field-in-select-option.html
Now let us see how to set an OVS search help for the select option.
Step 1: Go to the DOINIT method of the view controller where we have done the codings to set the select options.
The code snippet for adding the select option field in the screen is as below.
I_VALUE_HELP_TYPE is an exporting parameter which determines the type of the input help the select option field is supposed to have.
Uncomment the line and double click on the attribute for forward navigation to see for more options available.
Some options available in the interface are:
Pass the input help types as ovs.
Step 2: In the methods tab of the view controller, create an event handler method and assign it to the event on_ovs of select options as shown below.
Assign this event handler method to the select option.
Step 3: Double click on the method to write the codings inside this method.
Copy paste the codings that will be generated by the system for OVS search help and we will modify it accordingly.
Code generated by system for OVS Search help:
* declare data structures for the fields to be displayed and
* for the table columns of the selection list, if necessary
types:
begin of lty_stru_input,
* add fields for the display of your search input here
field1 type string,
end of lty_stru_input.
types:
begin of lty_stru_list,
* add fields for the selection list here
column1 type string,
end of lty_stru_list.
data: ls_search_input type lty_stru_input,
lt_select_list type standard table of lty_stru_list,
ls_text type wdr_name_value,
lt_label_texts type wdr_name_value_list,
lt_column_texts type wdr_name_value_list,
lv_window_title type string,
lv_table_header type string.
field-symbols: <ls_query_params> type lty_stru_input,
<ls_selection> type lty_stru_list.
case ovs_callback_object->phase_indicator.
when if_wd_ovs=>co_phase_0. "configuration phase, may be omitted
* in this phase you have the possibility to define the texts,
* if you do not want to use the defaults (DDIC-texts)
ls_text-name = `FIELD1`. "must match a field name of search
ls_text-value = `MYTEXT`. "wd_assist->get_text( `001` ).
insert ls_text into table lt_label_texts.
ls_text-name = `COLUMN1`. "must match a field in list structure
ls_text-value = `MYTEXT2`. "wd_assist->get_text( `002` ).
insert ls_text into table lt_column_texts.
* lv_window_title = wd_assist->get_text( `003` ).
* lv_table_header = wd_assist->get_text( `004` ).
ovs_callback_object->set_configuration(
label_texts = lt_label_texts
column_texts = lt_column_texts
window_title = lv_window_title
table_header = lv_table_header ).
when if_wd_ovs=>co_phase_1. "set search structure and defaults
* In this phase you can set the structure and default values
* of the search structure. If this phase is omitted, the search
* fields will not be displayed, but the selection table is
* displayed directly.
* Read values of the original context (not necessary, but you
* may set these as the defaults). A reference to the context
* element is available in the callback object.
ovs_callback_object->context_element->get_static_attributes(
importing static_attributes = ls_search_input ).
* pass the values to the OVS component
ovs_callback_object->set_input_structure(
input = ls_search_input ).
when if_wd_ovs=>co_phase_2.
* If phase 1 is implemented, use the field input for the
* selection of the table.
* If phase 1 is omitted, use values from your own context.
if ovs_callback_object->query_parameters is not bound.
******** TODO exception handling
endif.
assign ovs_callback_object->query_parameters->*
to <ls_query_params>.
if not <ls_query_params> is assigned.
******** TODO exception handling
endif.
* call business logic for a table of possible values
* lt_select_list = ???
ovs_callback_object->set_output_table( output = lt_select_list ).
when if_wd_ovs=>co_phase_3.
* apply result
if ovs_callback_object->selection is not bound.
******** TODO exception handling
endif.
assign ovs_callback_object->selection->* to <ls_selection>.
if <ls_selection> is assigned.
* ovs_callback_object->context_element->set_attribute(
* name = `COLUMN1`
* value = <ls_selection>-column1 ).
* or
* ovs_callback_object->context_element->set_static_attributes(
* static_attributes = <ls_selection> ).
endif.
endcase.
Modify the code as below:
Set the required structure for the sub-search and the output table.
Note: Ref to OVS Search help document.
If you compare the importing parameter for the event handler method for normal OVS and OVS using search help.
Importing parameter for OVS Search help:
Importing parameter in the method for OVS Search help in select option.
Importing paramters will be different. In an normal ovs search help all the phases of the search help will be called using the object OVS_CALLBACK_OBJECT referring to type IF_WD_OVS but here in select option is the value of this call back object is stored in the structure I_OVS_DATA.
Double click on the associated type of I_OVS_DATA to see its structure.
Click on the direct type entry to see the structure.
The object reference required to call the phases of the OVS search help will be seen in the structure of same type if_wd_ovs.
So replace all the occurrence of OVS_CALLBACK_OBJECT in the coding by I_OVS_DATA-M_OVS_CALLBACK_OBJECT.
Change the Phase 0 Coding as below:
As I don’t require any subsearch field in the search help I have commented the codings in the phase 1.
Write the business logic to populate the output table in the phase 2.
The usage of first three phase is similar to that of a normal ovs search help for an attribute where as there is a lot of difference in the phase 3 where we bind the data back to the input field.
In a normal ovs search help for the input field created using attribute the system will generate the coding to bind values to the attribute whereas when using select option we don’t have the context attribute. If you see in the structure for I_OVS_DATA there will be a component mt_selected_values which will carry the data to the input field.
Change the phase 3 coding as below.
Code:
TYPES:
BEGIN OF LTY_STRU_INPUT,
EBELN TYPE EBELN,
END OF LTY_STRU_INPUT.
TYPES:
BEGIN OF LTY_STRU_LIST,
EBELN TYPE EBELN,
END OF LTY_STRU_LIST.
DATA: LS_SEARCH_INPUT TYPE LTY_STRU_INPUT,
LT_SELECT_LIST TYPE STANDARD TABLE OF LTY_STRU_LIST,
LS_TEXT TYPE WDR_NAME_VALUE,
LT_LABEL_TEXTS TYPE WDR_NAME_VALUE_LIST,
LT_COLUMN_TEXTS TYPE WDR_NAME_VALUE_LIST,
LV_WINDOW_TITLE TYPE STRING,
LV_TABLE_HEADER TYPE STRING.
FIELD-SYMBOLS: <LS_QUERY_PARAMS> TYPE LTY_STRU_INPUT,
<LS_SELECTION> TYPE LTY_STRU_LIST.
CASE I_OVS_DATA-M_OVS_CALLBACK_OBJECT->PHASE_INDICATOR.
WHEN IF_WD_OVS=>CO_PHASE_0.
LS_TEXT-NAME = `EBELN`.
LS_TEXT-VALUE = `PO NUMBER`.
INSERT LS_TEXT INTO TABLE LT_LABEL_TEXTS.
LS_TEXT-NAME = `EBELN`.
LS_TEXT-VALUE = `PO NUMBER`.
INSERT LS_TEXT INTO TABLE LT_COLUMN_TEXTS.
I_OVS_DATA-M_OVS_CALLBACK_OBJECT->SET_CONFIGURATION(
LABEL_TEXTS = LT_LABEL_TEXTS
COLUMN_TEXTS = LT_COLUMN_TEXTS
WINDOW_TITLE = LV_WINDOW_TITLE
TABLE_HEADER = LV_TABLE_HEADER ).
WHEN IF_WD_OVS=>CO_PHASE_1.
WHEN IF_WD_OVS=>CO_PHASE_2.
SELECT EBELN
FROM EKKO
INTO TABLE LT_SELECT_LIST.
I_OVS_DATA-M_OVS_CALLBACK_OBJECT->SET_OUTPUT_TABLE( OUTPUT = LT_SELECT_LIST ).
WHEN IF_WD_OVS=>CO_PHASE_3.
FIELD-SYMBOLS : <LT_SEL_OPT_RESULT> TYPE STANDARD TABLE.
ASSIGN I_OVS_DATA-M_OVS_CALLBACK_OBJECT->SELECTION->* TO <LS_SELECTION>.
IF <LS_SELECTION> IS ASSIGNED.
ASSIGN I_OVS_DATA-MT_SELECTED_VALUES->* TO <LT_SEL_OPT_RESULT>.
INSERT <LS_SELECTION>-EBELN INTO TABLE <LT_SEL_OPT_RESULT>.
ENDIF.
ENDCASE.
Save and activate the whole component. Test the application.
Output:
Press F4.
0 Comments:
Post a Comment