感谢肖总的提示,不然还不知道wda的新select option。。。
使用前提:SE24类:CL_WDR_SELECT_OPTIONS_20
核对了多个版本,ERP系统版本要S4 1701往上,CRM系统7 EHP3及以上,没有怎么管这个,不对也别怪我。。。
SE80,查看SELECT OPTION的组件:WD_SELECT_OPTIONS_20是否存在,如果不存在则不能使用。
1.新建WDA组件ZLYTEST_SELECT,并激活
2.双击WDA添加SELECT OPTION组件和ALV组件。
3。双击COMPONENTCONTROLLER,添加查询结果节点。结构预先定义。
4.双击V_MAIN视图,将ALV组件和SELECT OPTION添加到视图中。布局中添加两个UI element
5.初始化alv和select option对象
METHOD init_alv . DATA: lr_comp_alv TYPE REF TO if_wd_component_usage, lr_comp_if_alv TYPE REF TO iwci_salv_wd_table. DATA:gt_zcrmt0060 TYPE TABLE OF zcrmt0060, gw_zcrmt0060 LIKE LINE OF gt_zcrmt0060, gv_string TYPE string. DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings, lr_column TYPE REF TO cl_salv_wd_column, lr_column_header TYPE REF TO cl_salv_wd_column_header. DATA: lt_column TYPE salv_wd_t_column_ref, ls_column TYPE salv_wd_s_column_ref. **** DATA: lr_input_field TYPE REF TO cl_salv_wd_uie_input_field, lr_checkbox TYPE REF TO cl_salv_wd_uie_checkbox, lr_image TYPE REF TO cl_salv_wd_uie_image, lr_dropdown_by_key TYPE REF TO cl_salv_wd_uie_dropdown_by_key. DATA lr_column_id TYPE string. **** DATA: lr_field_amnt TYPE REF TO cl_salv_wd_field . DATA: lv_aggr_rule TYPE REF TO cl_salv_wd_aggr_rule, lr_sort_rule TYPE REF TO cl_salv_wd_sort_rule. lr_comp_alv = wd_this->wd_cpuse_alv( ) . IF lr_comp_alv->has_active_component( ) IS INITIAL. lr_comp_alv->create_component( ). ENDIF. DATA lr_config TYPE REF TO cl_salv_wd_config_table. DATA:lr_func_config TYPE REF TO cl_salv_wd_config_table. lr_comp_if_alv = wd_this->wd_cpifc_alv( ). lr_config = lr_comp_if_alv->get_model( ). lr_func_config = lr_comp_if_alv->get_model( ). lr_column_settings ?= lr_config . lt_column = lr_column_settings->get_columns( ). SELECT * INTO TABLE gt_zcrmt0060 FROM zcrmt0060 WHERE sales_org = 'O 50000297' AND component_name = 'ZHSCRM_DEALER_RET' AND alv = 'ALV'. SORT gt_zcrmt0060 BY posit ASCENDING. *========================================================= DATA: l_value TYPE REF TO cl_salv_wd_config_table. l_value = lr_comp_if_alv->get_model( ). l_value->if_salv_wd_table_settings~set_fixed_table_layout( abap_false ). "使列宽不可自动调节 l_value->if_salv_wd_table_settings~set_width( '100%' ) . "设置宽度 l_value->if_salv_wd_table_settings~set_visible_row_count( '15' ). "显示的行数 l_value->if_salv_wd_table_settings~set_scrollable_col_count( '15' ). l_value->if_salv_wd_table_settings~set_read_only( abap_true ). l_value->if_salv_wd_table_settings~set_display_empty_rows( abap_false ). l_value->if_salv_wd_table_settings~set_selection_mode( cl_wd_table=>e_selection_mode-multi_no_lead ). l_value->if_salv_wd_function_settings~set_enabled( abap_true ) . * l_value->if_salv_wd_std_functions~set_display_as_allowed( abap_false ) . * l_value->if_salv_wd_std_functions~set_sort_headerclick_allowed( abap_false ) . l_value->if_salv_wd_std_functions~set_edit_check_available( abap_false ) . l_value->if_salv_wd_std_functions~set_edit_insert_row_allowed( abap_false ) . * l_value->if_salv_wd_std_functions~set_export_allowed( abap_true ) . * l_value->if_salv_wd_std_functions~set_view_list_allowed( abap_false ). l_value->if_salv_wd_std_functions~set_pdf_allowed( abap_false ) . l_value->if_salv_wd_std_functions~set_edit_append_row_allowed( abap_false ) . l_value->if_salv_wd_std_functions~set_edit_delete_row_allowed( abap_false ) . l_value->if_salv_wd_std_functions~set_filter_filterline_allowed( abap_true ). l_value->if_salv_wd_std_functions~set_filter_complex_allowed( abap_true ). * l_value->if_salv_wd_std_functions~set_dialog_settings_allowed( abap_true ). DATA: lr_table_settings TYPE REF TO if_salv_wd_table_settings. lr_table_settings ?= l_value. lr_table_settings->set_data_check( '01' ). lr_table_settings->set_read_only( abap_false ). LOOP AT lt_column INTO ls_column. lr_column_id = ls_column-id. lr_column = ls_column-r_column. lr_column->set_resizable( value = 'X' ). lr_column->set_width( value = '100' ). READ TABLE gt_zcrmt0060 INTO gw_zcrmt0060 WITH KEY field = ls_column-id. IF sy-subrc = 0. IF gw_zcrmt0060-visiable = 'X'. lr_column_header = ls_column-r_column->create_header( ). ls_column-r_column->set_position( gw_zcrmt0060-posit ). IF gw_zcrmt0060-text CS 'CRM/'. gv_string = gw_zcrmt0060-text. lr_column_header->set_text( zcl_otr=>get_text( gv_string ) ). ELSE. IF gw_zcrmt0060-text IS NOT INITIAL. gv_string = gw_zcrmt0060-text. lr_column_header->set_text( gv_string ). ENDIF. ENDIF. ELSE. ls_column-r_column->set_position( gw_zcrmt0060-posit ). lr_column = lr_column_settings->get_column( ls_column-id ). lr_column->set_visible( if_wdl_core=>visibility_none ). ENDIF. ELSE. ls_column-r_column->set_position( gw_zcrmt0060-posit ). lr_column = lr_column_settings->get_column( ls_column-id ). lr_column->set_visible( if_wdl_core=>visibility_none ). ENDIF. "使用配置表替代原来的case逻辑 ENDLOOP. ENDMETHOD.
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. "创建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全局参数 * 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 = ls_general_visibility " wdso_general_visibility * global_options = ls_global_options " wdso_global_options * saved_searches = lt_saved_searches " wdso_tt_value_set * personalization = ls_pers actual_search = 'C' ). "初始化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. * DATA VAR_DATE_ATTRIBUTES TYPE WDR_SO_T_OPDEP_VALUESET. * DATA RENDER_ONLY_INITIAL_DATA TYPE WDY_BOOLEAN. * DATA PROPOSED_ROWS 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 ). ENDMETHOD.
将ALV和select option初始化的方法加到WDA视图的WDDOINIT里
6.在WINDOW里绑定视图下面的UI对象和组件
7.将ALV数据对象绑定COMPONENTCONTROLLER结果节点
8.创建application,并测试。结果如下:
9.SELECT OPTION的查询参数处理和结果绑定
METHOD onactionsearch . DATA rt_range TYPE wdr_so_t_range_ref. DATA rs_range TYPE wdr_so_s_range_ref. DATA max_nr_of_results TYPE i. DATA max_nr_of_results_is_null TYPE wdy_boolean. DATA select_all TYPE wdy_boolean. DATA lo_nd_retab TYPE REF TO if_wd_context_node. DATA lt_retab TYPE wd_this->elements_retab. FIELD-SYMBOLS: <fs_object_id> TYPE table, <fs_flag> TYPE table, <fs_type> TYPE table. wd_this->mo_select_option->get_input_complete_as_range( IMPORTING range_ref = rt_range max_nr_of_results = max_nr_of_results max_nr_of_results_is_null = max_nr_of_results_is_null select_all = select_all ). LOOP AT rt_range INTO rs_range. CASE rs_range-attribute. WHEN 'OBJECT_ID'. ASSIGN rs_range-range->* TO <fs_object_id>. WHEN 'PORTAL'. ASSIGN rs_range-range->* TO <fs_flag>. WHEN 'PROCESS_TYPE'. ASSIGN rs_range-range->* TO <fs_type>. WHEN OTHERS. ENDCASE. ENDLOOP. SELECT guid object_id posting_date po_number_ship AS po_number_sold retailer zzzmodeno shipto AS ship_to stat_user AS stat INTO CORRESPONDING FIELDS OF TABLE lt_retab FROM zhsb_order_index WHERE object_id IN <fs_object_id> AND process_type IN <fs_type>. lo_nd_retab = wd_context->get_child_node( name = wd_this->wdctx_retab ). lo_nd_retab->bind_table( new_items = lt_retab set_initial_elements = abap_true ). ENDMETHOD.
^_^很多人都把资料锁进了note里,以后还怎么百度呢^_^