为了省代码。。。为了方便管理WDA的查询条件。。。
首先建配置表:
说明:
上面的KEY基本都是维护的维度,可以根据销售组织,根据用户组,根据组件,根据SELECT OPTION的不同。。。等等,可以根据情况而定。
COMPONENT_NAME:wda组件名,不同的组件配置不同。
SELOPTION:SELECT OPTION名,不同的SELECT不同配置。
ATTRIBUTE:字段名,这里按照表字段名来处理的,方便后面做动态SQL。
TABNAME:表名,需要查的字段对应的数据库表,也是方便后面动态SQL。
DATAELEMENT:数据元素,创建OPTION的对象。
TEXT:字段标签,可以是OTR翻译文本,也可以是固定文本。
DISP_INDEX:SELECT条件的位置。
VISIABLE:查询条件是否可见。
MANDATORY:查询条件是否必填。
NO_EXTENSION:没有扩展选项
NO_INTERVALS:没有范围选择
AS_CHECKBOX:查询条件是CHECK BOX
AS_DROPDOWN:查询条件是下拉
SELECT OPTION初始化:
METHOD init_select_options . DATA: lt_range_table TYPE REF TO data, read_only TYPE abap_bool. 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. DATA:gt_zcrmt0888 TYPE TABLE OF zcrmt0888, gw_zcrmt0888 LIKE LINE OF gt_zcrmt0888. FIELD-SYMBOLS:<tab> TYPE table. * create the used component l_ref_cmp_usage = wd_this->wd_cpuse_select_option( ). 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_select_option( ). * init the select screen wd_this->m_handler = wd_this->m_wd_select_options->init_selection_screen( ). SELECT * INTO TABLE gt_zcrmt0888 FROM zcrmt0888. SORT gt_zcrmt0888 BY disp_index ASCENDING. LOOP AT gt_zcrmt0888 INTO gw_zcrmt0888. DATA:v_type TYPE string, v_id TYPE string, v_text TYPE string. REFRESH:gt_value_set. v_type = gw_zcrmt0888-dataelement."赋值数据元素类型 v_id = gw_zcrmt0888-attribute."赋值字段ID v_text = gw_zcrmt0888-text. IF gw_zcrmt0888-text CS 'ZCRM'."处理描述 v_text = zcl_otr=>get_text( v_text ). ENDIF. lt_range_table = wd_this->m_handler->create_range_table( i_typename = v_type ). IF gw_zcrmt0888-attribute = 'PROCESS_TYPE'. IF wd_comp_controller->bp_current_sales_org = 'O 50000005'. SELECT * INTO TABLE gt_type FROM crmc_proc_type_t WHERE process_type IN ('ZSO2','ZSO5') AND langu = sy-langu. ELSE. SELECT * INTO TABLE gt_type FROM crmc_proc_type_t WHERE process_type IN ('ZSO2','ZSO3','ZSO5') AND langu = sy-langu. ENDIF. 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. ELSEIF gw_zcrmt0888-attribute = 'DELIVERD'. ASSIGN lt_range_table->* TO <tab>. ls_stat-low = 'A'. ls_stat-high = 'B'. ls_stat-sign = 'I'. ls_stat-option = 'BT'. APPEND ls_stat TO <tab>. ENDIF. wd_this->m_handler->add_selection_field( i_id = v_id i_obligatory = gw_zcrmt0888-mandatory i_no_extension = gw_zcrmt0888-no_extension i_no_intervals = gw_zcrmt0888-no_intervals i_as_checkbox = gw_zcrmt0888-as_checkbox i_as_dropdown = gw_zcrmt0888-as_dropdown i_description = v_text it_result = lt_range_table it_value_set = gt_value_set i_read_only = read_only ). ENDLOOP. REFRESH:gt_zcrmt0888. * 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.
SEARCH里处理:(部分)
DATA: rt_object_id TYPE REF TO data. FIELD-SYMBOLS: <table> TYPE table, <any> TYPE any. DATA: gt_zcrmt0888 TYPE TABLE OF zcrmt0888, gw_zcrmt0888 LIKE LINE OF gt_zcrmt0888, lv_id TYPE string. lo_api_controller ?= wd_this->wd_get_api( ). lo_message_manager = lo_api_controller->get_message_manager( ). lo_nd_so_search = wd_context->get_child_node( name = wd_this->wdctx_so_search ). DATA:gt_range TYPE rsds_trange, gw_range LIKE LINE OF gt_range, gt_field TYPE TABLE OF zsfrange, gw_field LIKE LINE OF gt_field, gw_selec TYPE rsdsselopt, gt_where TYPE TABLE OF crmt_where. SELECT * INTO TABLE gt_zcrmt0888 FROM zcrmt0888 WHERE visiable = 'X'. LOOP AT gt_zcrmt0888 INTO gw_zcrmt0888. lv_id = gw_zcrmt0888-attribute. rt_object_id = wd_this->m_handler->get_range_table_of_sel_field( i_id = lv_id ). ASSIGN rt_object_id->* TO <table>. LOOP AT <table> ASSIGNING <any>. MOVE-CORRESPONDING <any> TO gw_selec. APPEND gw_selec TO gw_field-selopt_t. ENDLOOP. UNASSIGN:<any>,<sales_org>. gw_field-fieldname = gw_zcrmt0888-attribute. APPEND gw_field TO gw_range-frange_t. CLEAR:gw_field. ENDLOOP. APPEND gw_range TO gt_range. CLEAR:gw_range. CALL FUNCTION 'FREE_SELECTIONS_RANGE_2_WHERE' EXPORTING field_ranges = gt_range IMPORTING where_clauses = gt_where.
。。。
看看效果:
输入查询条件,看处理结果:
这里没配TABLENAME,都是默认的:
可以根据TABLENAME分到不同的动态SQL里,然后加到常规SQL中。
^_^很多人都把资料锁进了note里,以后还怎么百度呢^_^