WD_SELECT_OPTIONS_20新加了很多好玩的东西,尤其是里面的保存搜索条件和使用保存的搜索条件。因为这个比较想WEB UI,所以兴趣比较高一点,WEB UI里是把参数拼成XML存起来的,我这里就不使用这种方法了,看起来就很烦。。。
1.接前一篇,修改SELECT OPTIONS的初始化方法,使用save search和初始化save search下拉。
METHOD init_select . DATA lo_cmp_usage TYPE REF TO if_wd_component_usage. DATA lo_interfacecontroller TYPE REF TO iwci_wd_select_options_20. DATA:visiable TYPE wdr_so_s_general_visibility. DATA gt_search TYPE wdr_context_attr_value_list. DATA gw_search TYPE wdr_context_attr_value. DATA saved_searches_admin TYPE wdr_so_t_searches. SELECT nameid AS value nameid AS text INTO TABLE gt_search FROM zdyndata WHERE parname = 'ZLYTEST_SELECT' AND usnam = sy-uname. APPEND INITIAL LINE TO gt_search. "创建selec option组件对象 lo_cmp_usage = wd_this->wd_cpuse_select_option( ). IF lo_cmp_usage->has_active_component( ) IS INITIAL. lo_cmp_usage->create_component( ). ENDIF. "取到当前的select option 对象 lo_interfacecontroller = wd_this->wd_cpifc_select_option( ). "设置select option全局参数 visiable-show_saved_searches = 'X'. visiable-location_saved_searches = ''. visiable-show_saving_searches = 'X'. * visiable-SHOW_HIDE_SEARCH_FIELDS = * visiable-SHOW_MAX_NR_ROWS visiable-show_button_search = 'X'. visiable-show_button_clear = 'X'. visiable-show_button_reset = 'X'. * visiable-show_label = 'X'. * wd_comp_controller->mo_select_option = lo_interfacecontroller->init_select_options( wd_this->mo_select_option = lo_interfacecontroller->init_select_options( * general_texts = ls_general_texts " wdso_general_texts general_visibility = visiable " wdso_general_visibility * global_options = ls_global_options " wdso_global_options saved_searches = gt_search " wdso_tt_value_set * personalization = ls_pers actual_search = '' ). "初始化select option的字段 DATA gt_select_attr TYPE wdr_so_t_attributes. DATA gw_select_attr TYPE wdr_so_s_attributes. DATA gt_value_set TYPE wdr_context_attr_value_list. DATA gw_value_set TYPE wdr_context_attr_value. DATA select_init TYPE wdr_so_t_values. gw_select_attr-attribute = 'OBJECT_ID'. gw_select_attr-attr_type = 'ID'. gw_select_attr-text = 'OBJECT ID'. gw_select_attr-dataelement = 'CRMT_OBJECT_ID'. gw_select_attr-value_set = gt_value_set[]. APPEND gw_select_attr TO gt_select_attr. CLEAR:gw_select_attr. gw_select_attr-attribute = 'PROCESS_TYPE'. gw_select_attr-attr_type = 'ID'. gw_select_attr-text = 'Transaction Type'. gw_select_attr-dataelement = 'CRMT_PROCESS_TYPE_DB'. APPEND gw_select_attr TO gt_select_attr. CLEAR:gw_select_attr. gw_select_attr-attribute = 'PORTAL'. gw_select_attr-attr_type = 'CK'. gw_select_attr-text = 'PORTAL FLAG'. gw_select_attr-dataelement = 'ZE_PORTAL_FLAG'. APPEND gw_select_attr TO gt_select_attr. wd_this->mo_select_option->add_attributes( EXPORTING attributes = gt_select_attr * initial_data = initial_data * var_date_attributes = var_date_attributes * render_only_initial_data = render_only_initial_data * IMPORTING * proposed_rows = proposed_rows ). *SET_SEARCH( ). ENDMETHOD.
这里面把新组件标准的搜索清空重置放出来了,但是我没有实现。。。因为可以调我之前写好的,也可以复制进去,这里就不写了。
2.参数表如下:用来存储用户存储的search data
3.实例化SAVE SEARCH方法:
在视图中添加SAVE_SEARCH方法
事件中绑定到SELECT OPTIONS的SAVE SEARCH事件。
METHOD save_search . DATA include_unvaluated_rows TYPE wdy_boolean. DATA gt_values TYPE wdr_so_t_values. DATA gw_values TYPE wdr_so_s_values. DATA max_nr_of_results TYPE i. DATA max_nr_of_results_is_null TYPE wdy_boolean. DATA select_all TYPE wdy_boolean. TYPES:BEGIN OF ty_id, parname TYPE wdy_component_name, usnam TYPE usnam, nameid TYPE char20, END OF ty_id. DATA:gw_id TYPE ty_id. DATA:gw_log TYPE zdyndata. DATA:gw_tab TYPE zly_so_s_values, gt_tab TYPE TABLE OF zly_so_s_values. wd_this->mo_select_option->get_input_complete( EXPORTING include_unvaluated_rows = abap_false IMPORTING values = gt_values max_nr_of_results = max_nr_of_results max_nr_of_results_is_null = max_nr_of_results_is_null select_all = select_all ). gw_id-parname = 'ZLYTEST_SELECT'. gw_id-usnam = sy-uname. gw_id-nameid = search_name. MOVE-CORRESPONDING gw_id TO gw_log. LOOP AT gt_values INTO gw_values. MOVE-CORRESPONDING gw_values TO gw_tab. APPEND gw_tab TO gt_tab. ENDLOOP. EXPORT test = gt_tab[] TO DATABASE zdyndata(FL) FROM gw_log ID gw_id. CHECK 1 = 1. ENDMETHOD.
4.实例化load search方法:
在视图中添加LOAD_SEARCH方法:
METHOD load_search . TYPES:BEGIN OF ty_id, parname TYPE wdy_component_name, usnam TYPE usnam, nameid TYPE char20, END OF ty_id. DATA gt_values TYPE wdr_so_t_values. DATA gw_values TYPE wdr_so_s_values. DATA:gw_id TYPE ty_id. DATA:gw_log TYPE zdyndata. DATA:gw_tab TYPE zly_so_s_values, gt_tab TYPE TABLE OF zly_so_s_values. SELECT SINGLE * INTO gw_log FROM zdyndata WHERE parname = 'ZLYTEST_SELECT' AND usnam = sy-uname AND nameid = search_id. IF sy-subrc = 0. MOVE-CORRESPONDING gw_log TO gw_id. IMPORT test = gt_tab[] FROM DATABASE zdyndata(fl) ID gw_id IGNORING CONVERSION ERRORS . IF sy-subrc = 0. LOOP AT gt_tab INTO gw_tab. MOVE-CORRESPONDING gw_tab TO gw_values. APPEND gw_values TO gt_values. ENDLOOP. wd_this->mo_select_option->reset( EXPORTING initial_data = gt_values render_only_initial_data = 'X' * IMPORTING * proposed_rows = proposed_rows ). ENDIF. ENDIF. ENDMETHOD.
应该还少了一部分,SAVE SEARCH的时候更新search的下拉和默认上当前的搜索。。。后面再补吧^_^