WDA学习:OVS Help in WDA

Posted tangtoms

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WDA学习:OVS Help in WDA相关的知识,希望对你有一定的参考价值。

1.8.OVS Help in WDA

       OVS(Object Value Selector)对象值选择器,通过Component Usage使用。对应Web Dynpro Component:WDR_OVS。

1.创建Web Dynpro Component。

 技术图片

Component Usage:WDR_OVS

 技术图片

2.设置MAIN视图组件。

Context页签,创建上下文

 技术图片

技术图片

设置Context的CARRID字段使用OVS

Input Help Mode设置为Object Value Selector;

OVS Component Usage:设置为OVS;

 技术图片

Layout页签:

创建Table视图控件,Create Binding,绑定上下文;

 技术图片

Properties页签

设置MAIN视图组件Used Contorller/Components

 技术图片

Methods页签

创建ON_OVS方法,类型为Event Handler,事件回调函数,Event栏位点击帮助小方块,选择Event:OVS

技术图片

 技术图片

默认生成Method:ON_OVS代码,但是需要修改:

技术图片
method ON_OVS .
* declare data structures for the fields to be displayed and
* for the table columns of the selection list, if necessary
  types:
    begin of lty_stru_input,
      "自定义查询字段search input
      carrid type SFLIGHT-CARRID,
      connid TYPE SFLIGHT-CONNID,
      fldate TYPE SFLIGHT-FLDATE,
    end of lty_stru_input.
  types:
    begin of lty_stru_list,
      "自定义显示查询结果selection list
      carrid type SFLIGHT-CARRID,
      connid TYPE SFLIGHT-CONNID,
      fldate TYPE SFLIGHT-FLDATE,
      currency TYPE SFLIGHT-CURRENCY,
    end of lty_stru_list.

  data: ls_search_input  type lty_stru_input,
        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  type string,
        lv_table_header  type string.

  DATA: gs_where TYPE C LENGTH 72.
  DATA: gt_where LIKE TABLE OF gs_where.
  DATA: l_line TYPE I.

  field-symbols: <ls_query_params> type lty_stru_input,
                 <ls_selection>    type lty_stru_list.

  case 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:结果表头
    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 = `CARRID`.  "must match a field name of search
      ls_text-value = `Airline Code`.
      insert ls_text into table lt_label_texts.
      ls_text-name = `CONNID`.  "must match a field name of search
      ls_text-value = `Flight Number`.
      insert ls_text into table lt_label_texts.
      ls_text-name = `FLDATE`.  "must match a field name of search
      ls_text-value = `Flight Date`.
      insert ls_text into table lt_label_texts.

      ls_text-name = `CARRID`.  "must match a field in list structure
      ls_text-value = `Airline Code`.
      insert ls_text into table lt_column_texts.
      ls_text-name = `CONNID`.  "must match a field in list structure
      ls_text-value = `Flight Number`.
      insert ls_text into table lt_column_texts.
      ls_text-name = `FLDATE`.  "must match a field in list structure
      ls_text-value = `Flight Date`.
      insert ls_text into table lt_column_texts.
      ls_text-name = `CURRENCY`.  "must match a field in list structure
      ls_text-value = `Currency of Flight`.
      insert ls_text into table lt_column_texts.

      lv_window_title = window title.
      lv_table_header = table header.

      ovs_callback_object->set_configuration(
                label_texts  = lt_label_texts
                column_texts = lt_column_texts
                window_title = lv_window_title
                table_header = lv_table_header
                table_multi_select = abap_false ).


    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.

      ovs_callback_object->context_element->get_static_attributes(
          importing static_attributes = ls_search_input ).
*     pass the values to the OVS component
      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 ovs_callback_object->query_parameters is not bound.
******** TODO exception handling
      endif.
      assign ovs_callback_object->query_parameters->* to <ls_query_params>.
      if not <ls_query_params> is assigned.
******** TODO exception handling
      endif.
*     call business logic for a table of possible values
      "根据用户筛选条件,筛选结果
      IF <ls_query_params>-carrid IS NOT INITIAL.
        gs_where = CARRID =  &&  ‘‘‘ && <ls_query_params>-carrid && ‘‘‘‘.
        APPEND gs_where TO gt_where.
        gs_where =  AND.
        APPEND gs_where TO gt_where.
      ENDIF.
      IF <ls_query_params>-connid IS NOT INITIAL.
        gs_where = CONNID =  &&  ‘‘‘ && <ls_query_params>-connid && ‘‘‘‘.
        APPEND gs_where TO gt_where.
        gs_where =  AND.
        APPEND gs_where TO gt_where.
      ENDIF.
      IF <ls_query_params>-fldate IS NOT INITIAL.
        gs_where = CONNID =  &&  ‘‘‘ && <ls_query_params>-fldate && ‘‘‘‘.
        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_select_list WHERE (gt_where).
      "设置查询到数据
      ovs_callback_object->set_output_table( output = lt_select_list ).

    when if_wd_ovs=>co_phase_3.
*   apply result
      if ovs_callback_object->selection is not bound.
******** TODO exception handling
      endif.

      assign ovs_callback_object->selection->* to <ls_selection>.
      if <ls_selection> is assigned.
        ovs_callback_object->context_element->set_attribute(
                               name  = `CARRID`
                               value = <ls_selection>-carrid ).
*        ovs_callback_object->context_element->set_static_attributes(
*                               static_attributes = <ls_selection> ).
      endif.
  endcase.

endmethod.
View Code

OVS组件回调会有四个阶段:

第一阶段:设置OVS帮助组件弹出框的标题,帮助的查询筛选字段,设置结果表栏位等;

第二阶段:设置OVS帮助组件弹出框,初始化输入筛选条件;

第三阶段:根据用户输入条件,筛选出结果;

第四阶段:用户选择筛选出的记录,将所需栏位设置到帮助触发页面;

3.创建Web Dynpro Application,运行应用。

 技术图片

输入筛选条件

 技术图片

选择筛选出来的数据

 技术图片

 将所选记录所需栏位值设置到触发帮助的栏位

技术图片

 

以上是关于WDA学习:OVS Help in WDA的主要内容,如果未能解决你的问题,请参考以下文章

WDA基础十:OVS搜索帮助的使用

WDA学习:Application Configuration

WDA学习:Application Configuration

WDA学习:Component Usage(Select Options)

WDA学习:Component Usage(Select Options)

Mac + Python3.6 + facebook-wda之IOS自动化:安装facebook-wda库并编写简易自动化测试脚本