1.9 Select Options && OVS
本实例展示如何使用Select Options结合OVS(Object Value Selector)使用。
1.创建Web Dynpro Component
Name:Z_TEST_WDA3
Window Name:Z_TEST_WDA3
View Name:MAIN
2.Component Usage使用Select Options
选择Web Dynpro Comp.添加Component Use
3.设置MAIN视图组件
Layout页签:
创建Group类型视图控件Group1,设置CAPTION的text属性;
创建ViewContainerUIElement类型视图控件View1,用来显示Select Options的容器;
Properties页签:
创建Select Options使用组件参数。
Attributes页签:
创建参数M_HANDLER,类型IF_WD_SELECT_OPTIONS
创建参数M_WD_SELECT_OPTIONS,类型IWCI_WDR_SELECT_OPTIONS
Methods页签:
创建Event Handler,响应OVS事件;
重写WDDONINIT方法,初始化Select Options
method WDDOINIT. DATA:LT_RANGE_TABLE TYPE REF TO DATA. DATA:LR_VALUE TYPE REF TO DATA. FIELD-SYMBOLS: <FS_DATE> TYPE SFLIGHT-FLDATE. "Component Usage对应接口 DATA:L_REF_CMP_USAGE TYPE REF TO IF_WD_COMPONENT_USAGE. * create the used component L_REF_CMP_USAGE = WD_THIS->WD_CPUSE_SELECT_OPTIONS( ). IF L_REF_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) IS INITIAL. L_REF_CMP_USAGE->CREATE_COMPONENT( ). ENDIF. "select Options接口 WD_THIS->M_WD_SELECT_OPTIONS = WD_THIS->WD_CPIFC_SELECT_OPTIONS( ). "init the select screen WD_THIS->M_HANDLER = WD_THIS->M_WD_SELECT_OPTIONS->INIT_SELECTION_SCREEN( ). "Set the Global options "是否显示cancel,check,reset,execute按钮 WD_THIS->M_HANDLER->SET_GLOBAL_OPTIONS( I_DISPLAY_BTN_CANCEL = ABAP_FALSE I_DISPLAY_BTN_CHECK = ABAP_FALSE I_DISPLAY_BTN_RESET = ABAP_FALSE I_DISPLAY_BTN_EXECUTE = ABAP_FALSE ). "设置select option字段 "1.创建对应range table;2.将range table设置到select option; "调用CREATE_RANGE_TABLE方法,创建range table LT_RANGE_TABLE = WD_THIS->M_HANDLER->CREATE_RANGE_TABLE( I_TYPENAME = 'S_CARR_ID' ). "add a new field to the selection "ADD_SELECTION_FIELD方法添加字段到select option "I_VALUE_HELP_STRUCTURE,I_VALUE_HELP_STRUCTURE_FIELD,设置对应数据库表,字段 "I_ID = 'S_CARR_ID' 设置字段对应id "I_READ_ONLY设置字段是否只读 abap_boolean "IT_RESULT 设置select option字段对应内表 "I_OBLIGATORY 设置是否必输abap_boolean "I_DESCRIPTION 设置描述 WD_THIS->M_HANDLER->ADD_SELECTION_FIELD( I_ID = 'S_CARR_ID' I_VALUE_HELP_STRUCTURE = 'SFLIGHT' I_VALUE_HELP_STRUCTURE_FIELD = 'CARRID' IT_RESULT = LT_RANGE_TABLE I_READ_ONLY = abap_false ). "plane type使用ovs帮助方式 "创建range table LT_RANGE_TABLE = WD_THIS->M_HANDLER->CREATE_RANGE_TABLE( I_TYPENAME = 'S_PLANETYE' ). "将字段加入select option "I_VALUE_HELP_TYPE 指定IF_WD_VALUE_HELP_HANDLER=>CO_PREFIX_OVS "使用ovs帮助 WD_THIS->M_HANDLER->ADD_SELECTION_FIELD( I_ID = 'S_PLANETYE' I_VALUE_HELP_TYPE = IF_WD_VALUE_HELP_HANDLER=>CO_PREFIX_OVS IT_RESULT = LT_RANGE_TABLE I_READ_ONLY = abap_false ). "ADD_PARAMETER_FIELD方法创建单个输入参数 CREATE DATA LR_VALUE TYPE SFLIGHT-FLDATE. WD_THIS->M_HANDLER->ADD_PARAMETER_FIELD( I_ID = 'DATE' I_DESCRIPTION = 'select date' I_VALUE_HELP_STRUCTURE = 'SFLIGHT' I_VALUE_HELP_STRUCTURE_FIELD = 'FLDATE' I_OBLIGATORY = ABAP_TRUE I_VALUE = LR_VALUE ). endmethod.
实现ON_OVSSEL方法:
method ON_OVSSEL . TYPES:T_FLIGHT TYPE TABLE OF SFLIGHT. DATA:LT_SFLIGHT TYPE TABLE OF SFLIGHT, WA_SFLIGHT LIKE LINE OF LT_SFLIGHT. DATA:gs_where TYPE C LENGTH 72. DATA:gt_where LIKE TABLE OF gs_where. DATA:l_line TYPE I. FIELD-SYMBOLS:<LT_OVS_RESULT> TYPE T_FLIGHT, <WA_OVS_RESULT> LIKE LINE OF <LT_OVS_RESULT>, <WA_QUERY> LIKE LINE OF <LT_OVS_RESULT>, <LT_SEL_OPT_RESULT> TYPE STANDARD TABLE, <FIELD> TYPE DATA. "ovs帮助,回调方法,ovs组件会多次触发回调方法 IF I_OVS_DATA-M_SELECTION_FIELD_ID = 'S_PLANETYE'. CASE I_OVS_DATA-M_OVS_CALLBACK_OBJECT->PHASE_INDICATOR. "阶段0:配置ovs组件. "M_OVS_CALLBACK_OBJECT是IF_WD_OVS接口对象 "提供SET_CONFIGURATION方法 "TABLE_MULTI_SELECT:设置是否多行选择,abap_boolean "WINDOW_TITLE:设置窗口标题 "LABEL_TEXTS:文本标签,WDR_NAME_VALUE_LIST "COLUMN_TEXTS:列文本,WDR_NAME_VALUE_LIST "TABLE_HEADER:结果table头 WHEN IF_WD_OVS=>CO_PHASE_0. I_OVS_DATA-M_OVS_CALLBACK_OBJECT->SET_CONFIGURATION( TABLE_MULTI_SELECT = ABAP_TRUE ). "阶段1:the structure of the selection fields to be displayed must be defined in this phase "使用SET_INPUT_STRUCTURE方法 "INPUT,定义selection的表结构 "LABEL_TEXTS,文本标签,WDR_NAME_VALUE_LIST "WINDOW_TITLE:设置窗口标题 WHEN IF_WD_OVS=>CO_PHASE_1. I_OVS_DATA-M_OVS_CALLBACK_OBJECT->SET_INPUT_STRUCTURE( INPUT = WA_SFLIGHT ). "阶段2:获取帮助table值 "使用参数QUERY_PARAMETERS,获取用户筛选条件 "使用SET_OUTPUT_TABLE设置显示筛选结果 WHEN IF_WD_OVS=>CO_PHASE_2. "根据用户筛选条件,筛选结果 ASSIGN I_OVS_DATA-M_OVS_CALLBACK_OBJECT->QUERY_PARAMETERS->* TO <WA_QUERY>. IF <WA_QUERY>-carrid IS NOT INITIAL. gs_where = 'CARRID = ' && ' ''' && <WA_QUERY>-carrid && ''''. APPEND gs_where TO gt_where. gs_where = ' AND'. APPEND gs_where TO gt_where. ENDIF. IF <WA_QUERY>-connid IS NOT INITIAL. gs_where = 'CONNID = ' && ' ''' && <WA_QUERY>-connid && ''''. APPEND gs_where TO gt_where. gs_where = ' AND'. APPEND gs_where TO gt_where. ENDIF. "去掉最后一条and记录 DESCRIBE TABLE gt_where LINES l_line. LOOP AT gt_where INTO gs_where. IF sy-tabix = l_line AND gs_where = ' AND'. DELETE gt_where INDEX l_line. ENDIF. ENDLOOP. "根据条件动态查询 SELECT * FROM SFLIGHT INTO CORRESPONDING FIELDS OF TABLE LT_SFLIGHT WHERE (gt_where). I_OVS_DATA-M_OVS_CALLBACK_OBJECT->SET_OUTPUT_TABLE( OUTPUT = LT_SFLIGHT ). "阶段3:The result of the search was displayed in the results view of the OVS component. "SELECTION参数获取选择的结果集 WHEN IF_WD_OVS=>CO_PHASE_3. "获取选择结果 ASSIGN I_OVS_DATA-M_OVS_CALLBACK_OBJECT->SELECTION->* TO <LT_OVS_RESULT>. "mt_selected_values,保存选择后数据,显示在Select Options页面 ASSIGN I_OVS_DATA-MT_SELECTED_VALUES->* TO <LT_SEL_OPT_RESULT>. "处理选择结果 LOOP AT <LT_OVS_RESULT> ASSIGNING <WA_OVS_RESULT>. ASSIGN COMPONENT 'PLANETYPE' OF STRUCTURE <WA_OVS_RESULT> TO <FIELD>. INSERT <FIELD> INTO TABLE <LT_SEL_OPT_RESULT>. ENDLOOP. ENDCASE. ENDIF. endmethod.
4.设置Window窗口
嵌入视图组件,选择VIEW1->右键->Embed
5.创建Web Dynpro Application,运行。
点击f4帮助
弹出OVS(Object Value Selector),对应ON_OVSSEL回调阶段0,阶段1。
输入筛选条件,点击Start Search,查找符合条件数据,对应ON_OVSSEL回调阶段2。
选择一条或多条查询出记录,选择OK,自动将需要的字段带到Select Option页面,对应ON_OVSSEL回调阶段3。
可以看到Plane Type,有一个空值带出,因为选择记录的Plane Type为空值