• WDA基础十二:FREE PROGRAM SH (WDA TREE)


    一个需要用TREE展示搜索帮助的需求:

    1.创建WDA程序:ZCATEGORY

    2.Component Controller中添加节点:

    (说明,此节点仅在搜索帮助程序中使用,可以不用interface node)

    3.传入参数结构:

    4.传出参数结构:

    (取tree结构中的部分字段)

    5.在Implemented Interfaces 中加入IWD_VALUE_HELP 窗口:WD_VALUE_HELP

    激活全部程序。

    6.在Component Controller属性中加入:

    VALUE_HELP_LISTENER  public ref to  IF_WD_VALUE_HELP_LISTENER

    方法SET_VALUE_HELP_LISTENER中实现获取传入参数

    METHOD set_value_help_listener .
      DATA:gs_attr TYPE wdr_context_attribute_info.
      DATA:lr_attr TYPE REF TO if_wd_context_element,
           gv_name TYPE string.
      DATA lo_nd_attr TYPE REF TO if_wd_context_node.
      DATA lo_el_attr TYPE REF TO if_wd_context_element.
      DATA ls_attr TYPE wd_this->element_attr.
      DATA:lr_node   TYPE REF TO if_wd_context_node,
           lr_father TYPE REF TO if_wd_context_element.
      wd_this->value_help_listener = listener.
      gs_attr = listener->f4_attribute_info.
      lr_attr ?= listener->f4_context_element.
      CLEAR:ls_attr.
    
      CASE gs_attr-name.
        WHEN 'ZZSYMP_CODE'.
          ls_attr-katalogart = 'Z1'.
          gv_name = 'ZZSYMP_GROU'.
          lr_attr->get_attribute(
            EXPORTING
              name   = 'NUMBER_INT'
            IMPORTING
              value  = wd_this->flag ).
          lr_node = lr_attr->get_node( ).
          CHECK lr_node IS BOUND.
          lr_father = lr_node->get_parent_element( ).
          CHECK lr_father IS BOUND.
          lr_father->get_attribute(
            EXPORTING
              name   = 'SALES_ORG'
            IMPORTING
              value  = ls_attr-sales_org ).
        WHEN 'SYMPTOMS_CODE' .
          ls_attr-katalogart = 'Z1'.
          gv_name = 'SYMPTOMS_CODE_G'.
          lr_attr->get_attribute(
        EXPORTING
          name   = 'SALES_ORG'
        IMPORTING
          value  = ls_attr-sales_org ).
        WHEN 'ZZZSYMPTOMSCODE'.
          ls_attr-katalogart = 'Z1'.
          gv_name = 'ZZZSYMPTOMSGROUP'.
    
          ls_attr-sales_org = zcl_otr=>gv_sales_org.
        WHEN 'DEFECT_CODE'.
          ls_attr-katalogart = 'Z2'.
          gv_name = 'SYMPTOMS_CODE_G'.
          lr_attr->get_attribute(
        EXPORTING
          name   = 'SALES_ORG'
        IMPORTING
          value  = ls_attr-sales_org ).
        WHEN 'REPAIR_CODE'.
          ls_attr-katalogart = 'Z3'.
          gv_name = 'SYMPTOMS_CODE_G'.
          lr_attr->get_attribute(
        EXPORTING
          name   = 'SALES_ORG'
        IMPORTING
          value  = ls_attr-sales_org ).
        WHEN 'ZZSECTIONCODE'.
          ls_attr-katalogart = 'Z5'.
          gv_name = 'SYMPTOMS_CODE_G'.
          lr_attr->get_attribute(
        EXPORTING
          name   = 'SALES_ORG'
        IMPORTING
          value  = ls_attr-sales_org ).
        WHEN 'ZZAFLD00002V'.
          ls_attr-katalogart = 'Z6'.
          gv_name = 'SYMPTOMS_CODE_G'.
          lr_attr->get_attribute(
        EXPORTING
          name   = 'SALES_ORG'
        IMPORTING
          value  = ls_attr-sales_org ).
        WHEN OTHERS.
          EXIT.
      ENDCASE.
    
      lr_attr->get_attribute(
        EXPORTING
          name   = gv_name
        IMPORTING
          value  = ls_attr-codegr ).
    
      lo_nd_attr = wd_context->get_child_node( name = wd_this->wdctx_attr ).
      lo_el_attr = lo_nd_attr->get_element( ).
      lo_el_attr->set_static_attributes(
         static_attributes = ls_attr ).
    
    ENDMETHOD.

    READ_FOLDER

    ZGRTREE Importing ZGRTREE
    RESULT Returning ZGRTREET

    METHOD read_folder.
      DATA lo_nd_attr TYPE REF TO if_wd_context_node.
      DATA lo_el_cate TYPE REF TO if_wd_context_element.
      DATA lt_cate TYPE wd_this->elements_cate.
      DATA ls_cate TYPE wd_this->element_cate.
      DATA:gt_zgrtext TYPE TABLE OF zgrtext,
           gw_zgrtext LIKE LINE OF gt_zgrtext.
    
    
      SELECT a~sales_org
             a~zcode_catalog
             a~zprod_category
             a~zscode_id AS code
             b~kurztext
              INTO CORRESPONDING FIELDS OF TABLE gt_zgrtext
              FROM ziriscode_config AS a
              INNER JOIN qpct AS b
              ON a~zcode_catalog = b~katalogart
              AND a~zprod_category = b~codegruppe
              AND a~zscode_id = b~code
              WHERE a~sales_org = zgrtree-sales_org
              AND   a~zcode_catalog = zgrtree-zcode_catalog
              AND   a~zprod_category = zgrtree-zprod_category
              AND   a~zfcode_id      = zgrtree-name
              AND   b~sprache = sy-langu.
    
      SORT gt_zgrtext.
      DELETE ADJACENT DUPLICATES FROM gt_zgrtext COMPARING ALL FIELDS.
      LOOP AT gt_zgrtext INTO gw_zgrtext.
        ls_cate-name = gw_zgrtext-code.
        ls_cate-path = zgrtree-name && '/' && gw_zgrtext-code.
        ls_cate-PARENT_PATH = zgrtree-name.
        ls_cate-text = gw_zgrtext-kurztext.
        ls_cate-is_expanded = abap_false.
        ls_cate-is_leaf = abap_true.
        ls_cate-sales_org = gw_zgrtext-sales_org.
        ls_cate-zcode_catalog = gw_zgrtext-zcode_catalog.
        ls_cate-zprod_category = gw_zgrtext-zprod_category.
        APPEND ls_cate TO lt_cate.
      ENDLOOP.
    
      RESULT = lt_cate.
    
    ENDMETHOD.

    BROWSER ->TREE_BY_KEY_COL.CATE

                       onSelect->SELECT

    MIME_TYPE->TREE_BY_KEY_COL.CATE.TEXT

    BROWSER_NAME->childrenLoaded

                                 ->expanded

                                 ->isLeaf

                                 ->parentKey->TREE_BY_KEY_COL.CATE.PARENT_PATH

                                 ->rowKey    ->TREE_BY_KEY_COL.CATE.PATH

    onLoadChildren->LOAD_FOLDER

    BROWSER_NAME_INPUT->TREE_BY_KEY_COL.CATE.NAME

    WDDOINIT:

    METHOD wddoinit .
      DATA lo_nd_cate TYPE REF TO if_wd_context_node.
      DATA lt_cate TYPE wd_this->elements_cate.
      DATA ls_cate TYPE wd_this->element_cate.
      DATA:gt_zgrtext TYPE TABLE OF zgrtext,
           gw_zgrtext LIKE LINE OF gt_zgrtext.
      lo_nd_cate = wd_context->get_child_node( name = wd_this->wdctx_cate ).
      DATA lo_nd_attr TYPE REF TO if_wd_context_node.
      DATA lo_el_attr TYPE REF TO if_wd_context_element.
      DATA ls_attr TYPE wd_this->element_attr.
    
      lo_nd_attr = wd_context->get_child_node( name = wd_this->wdctx_attr ).
      lo_el_attr = lo_nd_attr->get_element( ).
      lo_el_attr->get_static_attributes(
        IMPORTING
          static_attributes = ls_attr ).
    
      SELECT a~zfcode_id AS codegr
                 a~sales_org
                 a~zcode_catalog
                 a~zprod_category
                 b~kurztext AS kurztext
             INTO CORRESPONDING FIELDS OF TABLE gt_zgrtext
             FROM ziriscode_config AS a
            INNER JOIN qpct AS b
            ON a~zcode_catalog = b~katalogart
            AND a~zprod_category = b~codegruppe
            AND a~zfcode_id = b~code
            WHERE a~sales_org = ls_attr-sales_org
            AND   a~zcode_catalog = ls_attr-katalogart
            AND   a~zprod_category = ls_attr-codegr
            AND   b~sprache = sy-langu.
      SORT gt_zgrtext.
      DELETE ADJACENT DUPLICATES FROM gt_zgrtext COMPARING ALL FIELDS.
      LOOP AT gt_zgrtext INTO gw_zgrtext.
        ls_cate-name = gw_zgrtext-codegr.
        ls_cate-path = gw_zgrtext-codegr.
        ls_cate-text = gw_zgrtext-kurztext.
        ls_cate-is_expanded = abap_false.
        ls_cate-is_leaf = abap_false.
        ls_cate-sales_org = gw_zgrtext-sales_org.
        ls_cate-zcode_catalog = gw_zgrtext-zcode_catalog.
        ls_cate-zprod_category = gw_zgrtext-zprod_category.
        APPEND ls_cate TO lt_cate.
      ENDLOOP.
      lo_nd_cate->bind_table( new_items = lt_cate set_initial_elements = abap_true ).
    
    
    ENDMETHOD.
    METHOD onactionselect .
      DATA:lr_context TYPE REF TO if_wd_context_element.
      DATA lo_nd_grcode TYPE REF TO if_wd_context_node.
      DATA lo_el_grcode TYPE REF TO if_wd_context_element.
      DATA ls_grcode TYPE wd_this->element_grcode.
      DATA:gw_code TYPE zgrtree.
    
      CLEAR:ls_grcode,gw_code.
    
      lr_context = wdevent->get_context_element( name = 'NEW_LEAD_SELECTION' ).
      lr_context->get_static_attributes(
        IMPORTING
          static_attributes = gw_code ).
    
      lo_nd_grcode = wd_context->get_child_node( name = wd_this->wdctx_grcode ).
      lo_el_grcode = lo_nd_grcode->get_element( ).
      ls_grcode-sales_org = gw_code-sales_org.
      ls_grcode-zcode_catalog = gw_code-zcode_catalog.
      ls_grcode-zprod_category = gw_code-zprod_category.
      ls_grcode-code = gw_code-name.
      ls_grcode-kurztext = gw_code-text.
    
      IF wd_comp_controller->flag <> ''.
        ls_grcode-kurztext = wd_comp_controller->flag.
        ls_grcode-zcode_catalog = '11'.
      ENDIF.
    
      lo_el_grcode->set_static_attributes(
         static_attributes = ls_grcode ).
    
    
      wd_comp_controller->fire_vh_data_selected_evt( ).
      wd_comp_controller->value_help_listener->close_window( ).
    ENDMETHOD.
    METHOD onactionload_folder.
      DATA componentcontroller_ref TYPE REF TO ig_componentcontroller.
    *  data folder_entries          type wdr_example_mime_entry_tab.
      DATA folder_entries          TYPE TABLE OF zgrtree.
      DATA url_path                TYPE string.
      DATA element                 TYPE REF TO if_wd_context_element.
      DATA context_node            TYPE REF TO if_wd_context_node.
      DATA:gs_node TYPE zgrtree.
    
    * Get URL Path of folder to read
      element = wd_context->path_get_element( path ).
      element->get_attribute( EXPORTING name = 'PATH'
                              IMPORTING value = url_path ).
      element->set_attribute( EXPORTING name = 'CHILDREN_LOADED'
                                        value = abap_true ).
    
      element->get_static_attributes(
        IMPORTING
          static_attributes = gs_node ).
    
    
    * Read folder by calling method of the component controller
      context_node = wd_context->get_child_node( 'CATE' ).
      componentcontroller_ref = wd_this->get_componentcontroller_ctr( ).
    
      folder_entries = componentcontroller_ref->read_folder( gs_node ).
    
    * Append new lines
      context_node->bind_table( new_items = folder_entries
                                set_initial_elements = abap_false ).
    
    ENDMETHOD.

    在使用组件的程序中,添加组件:CODE ZCATEGORY Table with Tree

    在Component Controller中添加程序的组件引用

    定义属性:

    VALUE_HELP_LISTENER   ref to IF_WD_VALUE_HELP_LISTENER

    新建方法:

    CODE 1 Event Handler                                                             VH_DATA_SELECTED INTERFACECONTROLLER CODE   

    方法中对传出参数处理:

    METHOD code .
      DATA lo_nd_grcode TYPE REF TO if_wd_context_node.
      DATA lo_el_grcode TYPE REF TO if_wd_context_element.
      DATA ls_grcode TYPE wd_this->element_grcode.
      DATA lo_nd_l_so_header_n TYPE REF TO if_wd_context_node.
      DATA lo_el_l_so_header_n TYPE REF TO if_wd_context_element.
      DATA ls_l_so_header_n TYPE wd_this->element_l_so_header_n.
      DATA lv_symptoms_code TYPE wd_this->element_l_so_header_n-symptoms_code.
      DATA lo_nd_t_so_item_n TYPE REF TO if_wd_context_node.
      DATA lt_t_so_item_n TYPE wd_this->elements_t_so_item_n.
      DATA ls_t_so_item_n TYPE wd_this->element_t_so_item_n.
      DATA:lv_name TYPE string,
           lv_no   TYPE I.
    
    *   navigate from <CONTEXT> to <GRCODE> via lead selection
      lo_nd_grcode = wd_context->get_child_node( name = wd_this->wdctx_grcode ).
      lo_el_grcode = lo_nd_grcode->get_element( ).
    
      lo_el_grcode->get_static_attributes(
        IMPORTING
          static_attributes = ls_grcode ).
    
      "动态确定返回参数赋值
      CASE ls_grcode-zcode_catalog.
        WHEN 'Z1'.
          lv_name = `SYMPTOMS_CODE`.
        WHEN 'Z2'.
          lv_name = `DEFECT_CODE`.
        WHEN 'Z3'.
          lv_name = `REPAIR_CODE`.
        WHEN 'Z5'.
          lv_name = `ZZSECTIONCODE`.
        WHEN 'Z6'.
          lv_name = `ZZAFLD00002V`.
        WHEN '11'."项目
          SHIFT ls_grcode-kurztext LEFT DELETING LEADING '0'.
          lv_no = ls_grcode-kurztext.
        WHEN OTHERS.
      ENDCASE.
    
      IF ls_grcode-zcode_catalog <> '11'.
        lo_nd_l_so_header_n = wd_context->get_child_node( name = wd_this->wdctx_l_so_header_n ).
        lo_el_l_so_header_n = lo_nd_l_so_header_n->get_element( ).
        lo_el_l_so_header_n->set_attribute(
          name =  lv_name"`SYMPTOMS_CODE`
          value = ls_grcode-code ).
      ELSE.
        lo_nd_t_so_item_n = wd_context->path_get_node( path = `L_SO_HEADER_N.T_SO_ITEM_N` ).
        lo_nd_t_so_item_n->get_static_attributes_table( IMPORTING table = lt_t_so_item_n ).
        LOOP AT lt_t_so_item_n INTO ls_t_so_item_n WHERE number_int = lv_no.
          ls_t_so_item_n-zzsymp_code = ls_grcode-code.
          MODIFY lt_t_so_item_n FROM ls_t_so_item_n.
        ENDLOOP.
    
        lo_nd_t_so_item_n->bind_table( new_items = lt_t_so_item_n set_initial_elements = abap_true ).
    
      ENDIF.
    
    
    ENDMETHOD.

    给节点确定搜索帮助

    如果是select option:

    DATA lo_so_api        TYPE REF TO if_wd_controller.
      DATA lo_so_cmp        TYPE REF TO if_wd_component.
      DATA lo_so_cmp_usg_tc TYPE REF TO if_wd_component_usage_group.
      DATA lo_so_cmp_usg_emp TYPE REF TO if_wd_component_usage_group.
    lo_so_api = wd_this->m_wd_select_options->wd_get_api( ).
        lo_so_cmp = lo_so_api->get_component( ).
        "门店搜索帮助
        lo_so_cmp->remove_cmp_usage_group( 'GROUP' ).
        lo_so_cmp_usg_tc = lo_so_cmp->create_cmp_usage_group(
            name           = 'GROUP'
            used_component = 'ZGROUP' ).
        lt_range_table =
        wd_this->m_handler->create_range_table(
        i_typename = 'ZSO_SYMPTOMS_CODE' ).
    * add a new field to the selection
        wd_this->m_handler->add_selection_field(
                                i_id = 'SYMPTOMS_CODE'
                                i_description = zcl_otr=>get_text( 'ZCRM/SYMCODE' )"lv_value
                                i_value_help_type = 'APPLDEV'
                                i_value_help_id = 'GROUP'
    *                          i_within_block = 'SELS'
                                it_result = lt_range_table
                                i_read_only = read_only ).

    GROUP是程序添加的组件

    效果:

  • 相关阅读:
    原型模式
    浅复制和深复制
    适配器模式
    外观模式
    模板方法
    建造者模式
    代理模式
    Centos7重新安装yum
    关于mongodb创建索引的一些经验总结(转)
    MongoDB查询语句(转)
  • 原文地址:https://www.cnblogs.com/sapSB/p/7641022.html
Copyright © 2020-2023  润新知