WDA基礎十:OVS搜索幫助的使用
阿新 • • 發佈:2017-07-30
count pointer process except ive insert 查詢 clear gin
對於WDA來說,常用的搜索幫助有OVS,標準SH,Interface view等。今天來說說兩種常用的OVS的使用:
一:普通字段,表字段的搜索幫助(在創建節點的時候指定搜索幫助OVS,或者後面加上去)
1.創建WDA程序,雙擊程序組件,在使用組件界面添加OVS組件,如下圖:
OVS組件名可隨意定義,組件選擇WDR_OVS,保存激活整個程序。
2.在需要使用的視圖中,添加步驟1中定義的OVS組件:雙擊視圖,在視圖屬性頁簽,點擊新建將1中的組件添加進視圖中。
定義的OVS會生成兩個組件都添加進視圖
3.將定義的OVS組件添加到節點屬性字段的搜索幫助,如下圖:
4.為OVS事件定義方法:
輸入方法名,選擇事件類型EVENT,在事件裏F4選擇前面定義的OVS事件
5.代碼實現OVS搜索幫助:
method ON_OVS_OWNER . types: begin of lty_stru_input,"定義查詢參數結構 CODEGRUPPE type QCODEGRP, end of lty_stru_input. types: begin of lty_stru_list,"定義搜搜幫助返回結果字段列表 CODEGRUPPE type QCODEGRP, CODE type QCODE, KURZTEXT type QTXT_CODE, GROUPTEXT type QKTEXTGR, end of lty_stru_list. data: ls_search_input type lty_stru_input, ls_select_list type lty_stru_list, 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 typestring, lv_group_header type string, lv_table_header type string. DATA: ls_ORDER_QCODE type ZV_ORDER_QCODE, lt_ORDER_QCODE type table of ZV_ORDER_QCODE. field-symbols: <ls_query_params> type lty_stru_input, <ls_selection> type lty_stru_list.DATA lo_nd_l_so_header_n TYPE REF TO if_wd_context_node. DATA lo_el_l_so_header_n TYPE REF TO if_wd_context_element. DATA ls_l_so_header_n TYPE wd_this->Element_l_so_header_n. DATA lv_symptoms_code_g TYPE wd_this->Element_l_so_header_n-symptoms_code_g. lo_nd_l_so_header_n = wd_context->get_child_node( name = wd_this->wdctx_l_so_header_n ). lo_el_l_so_header_n = lo_nd_l_so_header_n->get_element( ). lo_el_l_so_header_n->get_attribute( EXPORTING name = `SYMPTOMS_CODE_G` IMPORTING value = lv_symptoms_code_g ). case ovs_callback_object->phase_indicator. when if_wd_ovs=>co_phase_0. lv_window_title = ‘Choice Symptoms Code:‘. ovs_callback_object->set_configuration( label_texts = lt_label_texts column_texts = lt_column_texts group_header = lv_group_header window_title = lv_window_title table_header = lv_table_header col_count = 3 row_count = 20 ). when if_wd_ovs=>co_phase_1. when if_wd_ovs=>co_phase_2. select * into corresponding fields of table lt_ORDER_QCODE from ZV_ORDER_QCODE where KATALOGART = ‘Z1‘ and CODEGRUPPE = lv_symptoms_code_g AND SPRACHE = SY-LANGU."ADD DEFAULT LANGU BY LY 20170113 . clear: lt_select_list. loop at lt_ORDER_QCODE into ls_ORDER_QCODE. ls_select_list-CODEGRUPPE = ls_ORDER_QCODE-CODEGRUPPE. ls_select_list-GROUPTEXT = ls_ORDER_QCODE-GROUPTEXT. ls_select_list-CODE = ls_ORDER_QCODE-CODE. ls_select_list-KURZTEXT = ls_ORDER_QCODE-KURZTEXT. append ls_select_list to lt_select_list. endloop. ovs_callback_object->set_output_table( output = lt_select_list ). when if_wd_ovs=>co_phase_3. if ovs_callback_object->selection is not bound. endif. assign ovs_callback_object->selection->* to <ls_selection>. if <ls_selection> is assigned."返回選擇結果,可返回多個字段 ovs_callback_object->context_element->set_attribute( name = `SYMPTOMS_CODE` value = <ls_selection>-CODE ). endif. endcase. endmethod.
二、select option中設置OVS
不同的是需要在SELECT OPTION中添加OVS對象:
METHOD init_select_options . DATA: lt_range_table TYPE REF TO data, rt_range_table TYPE REF TO data, read_only TYPE abap_bool, typename TYPE string, lv_value TYPE string. DATA: lr_componentcontroller TYPE REF TO ig_componentcontroller, l_ref_cmp_usage TYPE REF TO if_wd_component_usage. DATA: display_btn_cancel TYPE abap_bool, display_btn_check TYPE abap_bool, display_btn_reset TYPE abap_bool, display_btn_execute TYPE abap_bool. DATA:gt_value_set TYPE wdy_key_value_table, gw_value_set TYPE wdy_key_value, gt_type TYPE TABLE OF crmc_proc_type_t, gw_type LIKE LINE OF gt_type. * create the used component l_ref_cmp_usage = wd_this->wd_cpuse_selection( ). IF l_ref_cmp_usage->has_active_component( ) IS INITIAL. l_ref_cmp_usage->create_component( ). ENDIF. * get a pointer to the interface controller of the select options *component wd_this->m_wd_select_options = wd_this->wd_cpifc_selection( ). * init the select screen wd_this->m_handler = wd_this->m_wd_select_options->init_selection_screen( ). "sales_org * create a range table that consists of this new data element lt_range_table = wd_this->m_handler->create_range_table( i_typename = ‘CRMT_SALES_ORG‘ ). * add a new field to the selection wd_this->m_handler->add_selection_field( i_id = ‘SALES_ORG‘ it_result = lt_range_table i_read_only = read_only ). * create a range table that consists of this new data element lt_range_table = wd_this->m_handler->create_range_table( i_typename = ‘CRMT_OBJECT_ID_DB‘ ). * add a new field to the selection wd_this->m_handler->add_selection_field( i_id = ‘OBJECT_ID‘ it_result = lt_range_table i_read_only = read_only ). * create a range table PROCESS TYPE lt_range_table = wd_this->m_handler->create_range_table( i_typename = ‘CRMT_PROCESS_TYPE‘ ). "ADD DEFAULT VALUE SET SELECT * INTO TABLE gt_type FROM crmc_proc_type_t WHERE process_type IN (‘ZSO2‘,‘ZSO3‘,‘ZSO5‘) AND langu = sy-langu. LOOP AT gt_type INTO gw_type. gw_value_set-key = gw_type-process_type. gw_value_set-value = gw_type-p_description. APPEND gw_value_set TO gt_value_set. ENDLOOP. * add a new field to the selection wd_this->m_handler->add_selection_field( i_id = ‘PROCESS_TYPE‘ it_result = lt_range_table it_value_set = gt_value_set i_read_only = read_only ). * create a range table that consists of this new data element lt_range_table = wd_this->m_handler->create_range_table( i_typename = ‘BU_PARTNER‘ ). * add a new field to the selection wd_this->m_handler->add_selection_field( i_id = ‘PARTNER‘ it_result = lt_range_table i_read_only = read_only ). * create a range table that consists of this new data element lt_range_table = wd_this->m_handler->create_range_table( i_typename = ‘CRMT_POSTING_DATE‘ ). * add a new field to the selection wd_this->m_handler->add_selection_field( i_id = ‘POSTING_DATE‘ i_description = lv_value it_result = lt_range_table i_read_only = read_only ). * create a range table that consists of this new data element lt_range_table = wd_this->m_handler->create_range_table( i_typename = ‘CRM_J_STATUS‘ ). * add a new field to the selection wd_this->m_handler->add_selection_field( i_id = ‘STAT‘ it_result = lt_range_table i_value_help_type = ‘OVR‘ i_value_help_id = ‘OVS‘ i_read_only = read_only ). *End add * adjust the global options wd_this->m_handler->set_global_options( i_display_btn_cancel = display_btn_cancel i_display_btn_check = display_btn_check i_display_btn_reset = display_btn_reset i_display_btn_execute = display_btn_execute ). ENDMETHOD.
然後就與前面相同:
METHOD ovs . CHECK i_ovs_data-m_selection_field_id EQ ‘STAT‘. TYPES: BEGIN OF lty_stru_input, stsma TYPE j_stsma, "搜索條件 estat TYPE j_estat, txt30 TYPE j_txt30, END OF lty_stru_input. TYPES: BEGIN OF lty_stru_list, * add fields for the selection list here stsma TYPE j_stsma, "搜索條件 estat TYPE j_estat, txt04 TYPE j_txt04, txt30 TYPE j_txt30, END OF lty_stru_list. DATA: ls_search_input TYPE lty_stru_input, lt_select_list TYPE STANDARD TABLE OF lty_stru_list, ls_select_list TYPE 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_group_header TYPE string, lv_table_header TYPE string, gt_tj30t TYPE TABLE OF tj30t, gw_tj30t LIKE LINE OF gt_tj30t. 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. "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 = `STSMA`. "must match a field name of search ls_text-value = `Status Profile`. "wd_assist->get_text( `001` ). INSERT ls_text INTO TABLE lt_label_texts. ls_text-name = `ESTAT`. "must match a field name of search ls_text-value = `User Status`. "wd_assist->get_text( `001` ). INSERT ls_text INTO TABLE lt_label_texts. ls_text-name = `TXT30`. "must match a field name of search ls_text-value = `Object status`. "wd_assist->get_text( `001` ). INSERT ls_text INTO TABLE lt_label_texts. ls_text-name = `STSMA`. "must match a field in list structure ls_text-value = `Status Profile`. "wd_assist->get_text( `002` ). INSERT ls_text INTO TABLE lt_column_texts. ls_text-name = `ESTAT`. "must match a field in list structure ls_text-value = `User Status`. "wd_assist->get_text( `002` ). INSERT ls_text INTO TABLE lt_column_texts. ls_text-name = `TXT04`. "must match a field in list structure ls_text-value = `Individual status of an object`. "wd_assist->get_text( `002` ). INSERT ls_text INTO TABLE lt_column_texts. ls_text-name = `TXT30`. "must match a field in list structure ls_text-value = `Object status`. "wd_assist->get_text( `002` ). INSERT ls_text INTO TABLE lt_column_texts. * lv_window_title = wd_assist->get_text( `003` ). * lv_group_header = wd_assist->get_text( `004` ). * lv_table_header = wd_assist->get_text( `005` ). i_ovs_data-m_ovs_callback_object->set_configuration( label_texts = lt_label_texts column_texts = lt_column_texts group_header = lv_group_header window_title = lv_window_title table_header = lv_table_header col_count = 4 row_count = 20 ). 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. i_ovs_data-m_ovs_callback_object->context_element->get_static_attributes( IMPORTING static_attributes = ls_search_input ). * pass the values to the OVS component i_ovs_data-m_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 i_ovs_data-m_ovs_callback_object->query_parameters IS NOT BOUND. ******** TODO exception handling ENDIF. ASSIGN i_ovs_data-m_ovs_callback_object->query_parameters->* TO <ls_query_params>. IF NOT <ls_query_params> IS ASSIGNED. ******** TODO exception handling ENDIF. REFRESH:gt_tj30t. DATA: rt_object_id TYPE REF TO data. DATA:gt_file TYPE TABLE OF crmc_proc_type, gw_file LIKE LINE OF gt_file. FIELD-SYMBOLS: <process_type> TYPE table. rt_object_id = wd_this->m_handler->get_range_table_of_sel_field( i_id = ‘PROCESS_TYPE‘ ). ASSIGN rt_object_id->* TO <process_type>. IF <process_type> IS ASSIGNED. SELECT * INTO TABLE gt_file FROM crmc_proc_type WHERE process_type IN <process_type> AND process_type IN (‘ZSO2‘,‘ZSO3‘,‘ZSO5‘). ELSE. SELECT * INTO TABLE gt_file FROM crmc_proc_type WHERE process_type IN (‘ZSO2‘,‘ZSO3‘,‘ZSO5‘). ENDIF. IF gt_file IS NOT INITIAL. SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_select_list FROM tj30t FOR ALL ENTRIES IN gt_file WHERE stsma = gt_file-user_stat_proc AND spras = sy-langu. ENDIF. * call business logic for a table of possible values * lt_select_list = ??? i_ovs_data-m_ovs_callback_object->set_output_table( output = lt_select_list ). WHEN if_wd_ovs=>co_phase_3. * apply result FIELD-SYMBOLS : <lt_sel_opt_result> TYPE STANDARD TABLE. IF i_ovs_data-m_ovs_callback_object->selection IS NOT BOUND. ******** TODO exception handling ENDIF. 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>-estat INTO TABLE <lt_sel_opt_result>. * or * I_OVS_DATA-m_ovs_callback_object->context_element->set_static_attributes( * static_attributes = <ls_selection> ). ENDIF. ENDCASE. ENDMETHOD.
WDA基礎十:OVS搜索幫助的使用