1. 程式人生 > 其它 >wda中使用OVS事件建立搜尋幫助

wda中使用OVS事件建立搜尋幫助

技術標籤:SAPabap

Webdynpro for ABAP中頁面上的的搜尋幫助,除了參考表字段外,也可以藉助WDR_OVS元件,實現像GUI裡面通過函式輸出自定義的搜尋幫助列表的做法。

方法:1、在COMPONENTCONTROLLER引用元件WDR_OVS
在這裡插入圖片描述
2、在COMPONENTCONTROLLER的方法裡新增Event Handle,Event引用WDR_OVS
在這裡插入圖片描述
3、編輯此方法,開啟時裡面已有部分程式碼,對程式碼進行修改即可

4、在需要新增F4的欄位所在的NODE上,屬性裡新增此搜尋幫助
在這裡插入圖片描述

method NAMEF4 .
* 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,
*   add fields for the display of your search input here
      BNAME type USR21-BNAME,   "使用者名稱
      PERSNUMBER type ADRP-PERSNUMBER,    "人員編號
      NAME_TEXT TYPE ADRP-NAME_TEXT,    "人員名稱
    end of lty_stru_input.
  types:
    begin of lty_stru_list,
*   add fields for the selection list here
      BNAME type USR21-BNAME,   "使用者名稱
      PERSNUMBER type ADRP-PERSNUMBER,    "人員編號
      NAME_TEXT TYPE ADRP-NAME_TEXT,    "人員名稱
    end of lty_stru_list.

  data: ls_search_input  type lty_stru_input,
        lt_select_list   type standard table of lty_stru_list,
        ls_select_list type 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.

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

  case ovs_callback_object->phase_indicator.

    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 = `BNAME`.  "must match a field name of search
      ls_text-value = `使用者ID`. "wd_assist->get_text( `001` ).
      insert ls_text into table lt_label_texts.

      ls_text-name = `PERSNUMBER`.  "must match a field name of search
      ls_text-value = `使用者編號`. "wd_assist->get_text( `001` ).
      insert ls_text into table lt_label_texts.

      ls_text-name = `NAME_TEXT`.  "must match a field name of search
      ls_text-value = `使用者名稱`. "wd_assist->get_text( `001` ).
      insert ls_text into table lt_label_texts.

      ls_text-name = `BNAME`.  "must match a field in list structure
      ls_text-value = `使用者ID`. "wd_assist->get_text( `002` ).
      insert ls_text into table lt_column_texts.

      ls_text-name = `PERSNUMBER`.  "must match a field in list structure
      ls_text-value = `PERSNUMBER`. "wd_assist->get_text( `002` ).
      insert ls_text into table lt_column_texts.

      ls_text-name = `NAME_TEXT`.  "must match a field in list structure
      ls_text-value = `使用者名稱`. "wd_assist->get_text( `002` ).
      insert ls_text into table lt_column_texts.

*      lv_window_title = wd_assist->get_text( `003` ).
*      lv_table_header = wd_assist->get_text( `004` ).

      ovs_callback_object->set_configuration(
                label_texts  = lt_label_texts
                column_texts = lt_column_texts
                group_header = '計劃員選擇'
                window_title = lv_window_title
                table_header = lv_table_header ).


    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
*     lt_select_list = ???
*--------------------------搜尋列表----------------------------------*
      data: lt_bname type range of USR21-BNAME,
            ls_bname like line of lt_bname,
            lt_name_text TYPE RANGE OF ADRP-NAME_TEXT,
            ls_name_text like line of lt_name_text,
            lt_USR21 type table of USR21,
            ls_USR21 type USR21,
            lt_adrp type table of adrp,
            ls_adrp type adrp.

      IF <ls_query_params>-BNAME IS NOT INITIAL.    "使用者ID
        ls_bname-sign = 'I'.
        ls_bname-option = 'EQ'.
        ls_bname-low = <ls_query_params>-bname.
        COLLECT ls_bname INTO lt_bname.
      ELSE.
        REFRESH lt_bname.
      ENDIF.

      IF <ls_query_params>-NAME_TEXT IS NOT INITIAL.    "使用者名稱
        ls_NAME_TEXT-sign = 'I'.
        ls_NAME_TEXT-option = 'EQ'.
        ls_NAME_TEXT-low = <ls_query_params>-NAME_TEXT.
        COLLECT ls_NAME_TEXT INTO lt_NAME_TEXT.
      ELSE.
        REFRESH lt_NAME_TEXT.
      ENDIF.

      select *
        from USR21
        into table lt_USR21
       where bname in lt_bname.

       IF not lt_name_text is initial.
        select *
          from adrp
          into table lt_adrp
         where name_text in lt_name_text.
       ENDIF.

      LOOP AT lt_USR21 into ls_USR21.
        clear ls_adrp.
        read table lt_adrp into ls_adrp with key PERSNUMBER = ls_USR21-PERSNUMBER.
        CLEAR ls_select_list.
        ls_select_list-bname = ls_USR21-bname.
        ls_select_list-name_text = ls_adrp-name_text.
        append ls_select_list to lt_select_list.
      ENDLOOP.
      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  = `ZUSER`
                               value = <ls_selection>-bname ).
*      or
*        ovs_callback_object->context_element->set_static_attributes(
*                               static_attributes = <ls_selection> ).

      endif.
  endcase.

endmethod.

PS:喜歡的同學可以關注微信公眾號
在這裡插入圖片描述