• UI基础五:简单的OP组件POPUP搜索帮助


    需求:给一个配置表,需要根据配置表来弹出选择框,并将选择的数据添加到SALES ORDER的项目

    BSP_WD_CMPWB

    新建组件:ZHSI_JPMPG

    新建视图,适用VALUE NODE 参考表ZCRMT0057.(表视图,可配置,按钮)

    在节点的IF_BSP_MODEL~INIT中设置选择模式:多选:

      method IF_BSP_MODEL~INIT.
    
        TYPES: BEGIN OF ltype_attr_struct,
                 mandt        TYPE mandt,
                 zzzmodeno    TYPE zmodeno,
                 zpart_group  TYPE zpart_group,
                 product_id   TYPE comt_product_id,
                 zgroup_des   TYPE zgroup_des,
                 zproduct_des TYPE comt_prshtextx,
                 quantity     TYPE zcrm_quan,
    
               END OF ltype_attr_struct.
    
    
        super->if_bsp_model~init( id    = id
                                  owner = owner ).
    
        SELECTION_MODE = SELMODE_MULTI."多选
    
        DATA: lv_struct_ref TYPE REF TO ltype_attr_struct,
              lv_value_node TYPE REF TO cl_bsp_wd_value_node,
              lv_bo_coll    TYPE REF TO if_bol_bo_col.
    
        CREATE DATA lv_struct_ref.
        CREATE OBJECT lv_value_node
          EXPORTING
            iv_data_ref = lv_struct_ref.
        CREATE OBJECT lv_bo_coll TYPE cl_crm_bol_bo_col.
    
        lv_bo_coll->add( lv_value_node ).
    
        set_collection( lv_bo_coll ).
    
    
      endmethod.

    在组件控制器中添加参数节点:OPTION,值节点,字段参考ZCRMT0057中个别字段

    在组件控制器中添加返回结果节点:ZJPPJM,值节点,字段参考ZCRMT0057

    根据参数条件初始化查询结果TABLE:DO_INIT_CONTEXT

      METHOD do_init_context.
    **SUPER->DO_INIT_CONTEXT( ).
        DATA:gt_zcrmt0057 TYPE TABLE OF zcrmt0057,
             gw_zcrmt0057 LIKE LINE OF gt_zcrmt0057,
             lr_line      TYPE REF TO zcrmt0057,
             lr_valuenode TYPE REF TO cl_bsp_wd_value_node,
             lr_col       TYPE REF TO if_bol_bo_col,
             lr_comp      TYPE REF TO zl_zhsi_jpm_bspwdcomponen_impl,
             gr_cond      TYPE REF TO if_bol_bo_property_access,
             gw_cond      TYPE zmodeno.
    
        lr_comp ?= me->comp_controller.
        IF lr_comp IS BOUND.
          gr_cond = lr_comp->typed_context->option->collection_wrapper->get_current( ).
          IF gr_cond IS BOUND.
            gr_cond->get_property_as_value(
              EXPORTING
                iv_attr_name = 'ZZZMODENO'
              IMPORTING
                ev_result    = gw_cond ).
            SELECT * INTO TABLE gt_zcrmt0057 FROM zcrmt0057 WHERE zzzmodeno = gw_cond.
          ENDIF.
        ENDIF.
        CREATE OBJECT lr_col TYPE cl_crm_bol_bo_col.
        LOOP AT gt_zcrmt0057 INTO gw_zcrmt0057.
          CREATE DATA lr_line.
          CREATE OBJECT lr_valuenode
            EXPORTING
              iv_data_ref = lr_line.
          lr_valuenode->set_properties( gw_zcrmt0057 ).
          lr_col->add( lr_valuenode ).
        ENDLOOP.
    
        me->typed_context->zjppmj->collection_wrapper->set_collection( lr_col ).
      ENDMETHOD.

    重定义GET_LOCAL_TOOLBAR_BUTTONS方法,添加选择按钮(点击将选择结果返回到程序中)

      METHOD if_bsp_wd_dyn_btn_control~get_local_toolbar_buttons.
        DATA:gw_button TYPE crmt_thtmlb_button.
        rt_result = super->if_bsp_wd_dyn_btn_control~get_local_toolbar_buttons( ).
        gw_button-id = 'CHOOSE'.
        gw_button-type = cl_thtmlb_util=>gc_done.
        gw_button-text = '選択'.
        gw_button-on_click = 'ZCHOOSE'.
        gw_button-enabled = abap_true.
        APPEND gw_button TO rt_result.
      ENDMETHOD.

    重定义GET_NO_OF_VISIBLE_TOOLBAR_BTNS方法,修改显示的按钮数量

      METHOD if_bsp_wd_dyn_btn_control~get_no_of_visible_toolbar_btns.
        rv_result = super->if_bsp_wd_dyn_btn_control~get_no_of_visible_toolbar_btns( ).
        rv_result = 9.
      ENDMETHOD.

    在Event Handler中添加前面设置的ZCHOOSE:

    (将选择的结果添加到组件控制器的返回节点中)

      METHOD eh_onzchoose.
        DATA lr_context_node_tree      TYPE REF TO cl_bsp_wd_context_node_tree.
        DATA lr_node                   TYPE REF TO if_bsp_wd_tree_node.
        DATA lr_tree_event             TYPE REF TO cl_thtmlb_tree.
        DATA lr_choose               TYPE REF TO if_bol_bo_col_iterator.
        DATA:lr_bol TYPE REF TO if_bol_bo_col.
        DATA   lv_sel_index              TYPE int4.
        DATA :lv_row_index TYPE int4,
              lr_comp      TYPE REF TO zl_zhsi_jpm_bspwdcomponen_impl,
              lr_window    TYPE REF TO cl_bsp_wd_window.
    
        lr_choose = me->typed_context->zjppmj->collection_wrapper->get_iterator( ).
        lr_bol = lr_choose->get_marked( ).
    
        lr_comp ?= me->comp_controller.
        lr_comp->typed_context->zjppjm->collection_wrapper->clear_collection( ).
        lr_comp->typed_context->zjppjm->collection_wrapper->set_collection( lr_bol ).
        lr_window = me->view_manager->get_window_controller( ).
        lr_window->call_outbound_plug( iv_outbound_plug   = 'PRD_SELECT' ).
      ENDMETHOD.

    WINDOW中添加外向跳转对象:

      METHOD op_prd_select.
        me->fire_outbound_plug( iv_outbound_plug   = 'PRD_SELECT'
                                 iv_data_collection = iv_data_collection ).
      ENDMETHOD.

    将组件添加InterfaceView,将组件控制器的参数节点和返回结果节点添加:

    在使用的组件中添加ComponentUsage:

    以上将搜索帮助的查询和返回值处理完成,现在来使用位置调用组件并处理返回结果:

    在BT115IT_SLSO的中添加按钮:

      METHOD do_prepare_output.
        CALL METHOD super->do_prepare_output
          EXPORTING
            iv_first_time = abap_false.
    *    CHECK sy-uname = zcl_crm_attributes=>gc_chenguoguang.
    **********************************************************************20170501-Begin
    *ZSO1/ZSO2/ZSO5 放出product ID 字段,ITEM增加exploed view按钮
    ***数据定义
        DATA:
          ls_button            TYPE crmt_thtmlb_button,
          ls_crmt_orgman_wrk   TYPE crmt_orgman_wrk,
          ls_crmst_adminh_btil TYPE crmst_adminh_btil,
          lr_btitems           TYPE REF TO cl_crm_bol_entity,
          lr_btorder           TYPE REF TO cl_crm_bol_entity,
          lr_btadminh          TYPE REF TO cl_crm_bol_entity.
    ***数据准备
        lr_btitems ?= me->typed_context->btitems->collection_wrapper->get_current( ).
        IF lr_btitems IS BOUND.
          lr_btorder = lr_btitems->get_root( ).
        ENDIF.
        IF lr_btorder IS BOUND.
          lr_btadminh = lr_btorder->get_related_entity( iv_relation_name = 'BTOrderHeader' ).
        ENDIF.
        CHECK lr_btadminh IS BOUND.
        lr_btadminh->get_properties( IMPORTING  es_attributes = ls_crmst_adminh_btil ).
        CALL FUNCTION 'CRM_ORGMAN_READ_OW'
          EXPORTING
            iv_ref_guid          = ls_crmst_adminh_btil-guid
            iv_ref_kind          = 'A'
          IMPORTING
            es_orgman_wrk        = ls_crmt_orgman_wrk
          EXCEPTIONS
            entry_does_not_exist = 1
            OTHERS               = 2.
        IF sy-subrc <> 0.
    * Implement suitable error handling here
        ENDIF.
    
        zl_bt115it__items_impl=>gv_sales_org = ls_crmt_orgman_wrk-sales_org.
        ls_button-type     = cl_thtmlb_util=>gc_icon_goto..
        ls_button-on_click = 'ZEXPLODE'.
        ls_button-text = 'Explode view'.
        ls_button-enabled  = abap_true.
        APPEND ls_button TO gt_button_tib.
        "在ZSO5的行项目中增加“部品リスト選択”按钮,只针对日本分公司显示。在点击该按钮时,弹出对话框,显示字段如下:
        "ADD BY LY 20171031
        IF ls_crmt_orgman_wrk-sales_org = 'O 50000231' AND ls_crmst_adminh_btil-process_type = 'ZSO5'.
          ls_button-type     = cl_thtmlb_util=>gc_icon_add..
          ls_button-on_click = 'ZPDEX'.
          ls_button-text = '部品リスト選択'.
          ls_button-enabled  = abap_true.
          APPEND ls_button TO gt_button_tib.
        ENDIF.
    **********************************************************************20170501-End
        "日语登陆,默认带出日语的物料描述,如无则取英语描述
        "ADD BY LY 20170613
        DATA:
          lv_langu TYPE sy-langu,
          lv_text  TYPE abap_bool.
        DATA lr_item_iter TYPE REF TO if_bol_bo_col_iterator.
        DATA lr_admini TYPE REF TO cl_crm_bol_entity.
        DATA ls_admini TYPE crmst_admini_btil.
        DATA:lr_core   TYPE REF TO cl_crm_bol_core.
        CLEAR:lv_langu.
        IF sy-langu = 'J'"加的by 李渊 20170613
          OR sy-langu = 'F'."20170731 法国逻辑
          lv_langu = sy-langu.
        ENDIF.
    
        IF lv_langu IS NOT INITIAL.
          lr_item_iter = me->typed_context->btadmini->collection_wrapper->if_bol_bo_col~get_iterator( ).
          CHECK lr_item_iter IS BOUND.
          lr_admini ?= lr_item_iter->get_first( ).
          WHILE lr_admini IS BOUND.
            lr_admini->get_properties( IMPORTING es_attributes = ls_admini ).
            IF sy-langu = lv_langu."加的by 李渊 20170606
              SELECT SINGLE short_text INTO ls_admini-description
                FROM comm_prshtext
                WHERE product_guid = ls_admini-product
                AND   langu        = lv_langu.
              IF sy-subrc <> 0.
                SELECT SINGLE short_text INTO ls_admini-description
                 FROM comm_prshtext
                 WHERE product_guid = ls_admini-product
                 AND   langu        = 'E'.
              ENDIF.
            ENDIF.
            lr_admini->set_properties( EXPORTING is_attributes = ls_admini ).
            lr_admini ?= lr_item_iter->get_next( ).
          ENDWHILE.
          lr_core = cl_crm_bol_core=>get_instance( ).
          lr_core->modify( ).
        ENDIF.
    
      ENDMETHOD.

    事件控制器中添加处理事件:ZPDEX

      METHOD eh_onzpdex.
    * Added by wizard: Handler for event 'ZPDEX'
        OP_PRD_SELECT( ).
      ENDMETHOD.

    添加外向链接:PRD_SELECT

      METHOD op_prd_select.
    * Added by wizard: Outbound plug 'PRD_SELECT'
        TYPES:BEGIN OF ty_cond,
                product_id TYPE comt_product_id,
                zzzmodeno  TYPE zmodeno,
              END OF ty_cond.
        DATA:lr_entity              TYPE REF TO cl_crm_bol_entity,
             lv_interface_view_name TYPE string,
             lv_title               TYPE string,
             gw_cond                TYPE ty_cond,
             gr_cond                TYPE REF TO ty_cond,
             lr_valuenode           TYPE REF TO cl_bsp_wd_value_node,
             lr_context             TYPE REF TO cl_bsp_wd_context_node.
        DATA:ls_crmst_adminh_btil TYPE crmst_adminh_btil,
             lr_btitems           TYPE REF TO cl_crm_bol_entity,
             lr_btorder           TYPE REF TO cl_crm_bol_entity,
             lr_btadminh          TYPE REF TO cl_crm_bol_entity.
    ***数据准备
    ”not use begin lr_btitems ?= me->typed_context->btitems->collection_wrapper->get_current( ). IF lr_btitems IS BOUND. lr_btorder = lr_btitems->get_root( ). ENDIF. IF lr_btorder IS BOUND. lr_btadminh = lr_btorder->get_related_entity( iv_relation_name = 'BTOrderHeader' ). ENDIF. CHECK lr_btadminh IS BOUND. lr_btadminh->get_properties( IMPORTING es_attributes = ls_crmst_adminh_btil ). "not use end lv_interface_view_name = 'ZHSI_JPMPG/MainWindow'. lv_title = '部品リスト選択'. "弹出框的标题 comp_popup = comp_controller->window_manager->create_popup("实例化弹出框,search_belnr_popup iv_interface_view_name = lv_interface_view_name "对应的类型为IF_BSP_WD_POPUP为全局变量 iv_usage_name = 'PRD_SELECT ' iv_title = lv_title ). comp_popup->set_on_close_event( iv_view = me iv_event_name = 'ZJPP_CLOSE' ). "设置弹出窗口对应的关闭事件 ** set display mode "此事件用于接受对应的选中返回值 comp_popup->set_display_mode( if_bsp_wd_popup=>c_display_mode_surrounded ). ** Open the Popup comp_popup->set_window_width( 700 ). comp_popup->set_window_height( 500 ). DATA:lr_cond TYPE REF TO if_bol_bo_col. CREATE OBJECT lr_cond TYPE cl_crm_bol_bo_col. CREATE DATA gr_cond. CREATE OBJECT lr_valuenode EXPORTING iv_data_ref = gr_cond. gw_cond-zzzmodeno = ls_crmst_adminh_btil-zzzmodeno. lr_valuenode->set_properties( gw_cond ). lr_cond->add( lr_valuenode ). " Get Query Context node lr_context = comp_popup->get_context_node( 'OPTION' ). CHECK lr_context IS BOUND. lr_context->set_collection( collection = lr_cond ). comp_popup->open( iv_inbound_plug = 'PRD_SELECT' iv_collection = lr_cond ). ENDMETHOD.

    处理返回结果:新建事件:ZJPP_CLOSE

      METHOD eh_onzjpp_close.
    * Added by wizard: Handler for event 'ZJPP_CLOSE'
        DATA lr_item TYPE REF TO cl_crm_bol_entity.
        DATA:lr_schedext TYPE REF TO cl_crm_bol_entity,
             lr_schedlin TYPE REF TO cl_crm_bol_entity.
        DATA:lr_btitems                  TYPE REF TO cl_crm_bol_entity,
             lr_btorder                  TYPE REF TO cl_crm_bol_entity,
             lr_btadminh                 TYPE REF TO cl_crm_bol_entity,
             lr_context_node             TYPE REF TO cl_bsp_wd_context_node,
             lr_iterator                 TYPE REF TO if_bol_bo_col_iterator,
             lr_access                   TYPE REF TO if_bol_bo_property_access,
             ls_crmt0057                 TYPE zcrmt0057,
             gw_item                     TYPE crmst_admini_btil,
             gv_quantity                 TYPE crmt_schedlin_quan,
             ls_schedlin                 TYPE crmst_schedlin_btil,
             gv_string                   TYPE string,
             gr_cx_crm_genil_model_error TYPE REF TO cx_crm_genil_model_error.
    
        CHECK comp_popup IS BOUND.
        lr_context_node = comp_popup->get_context_node( iv_cnode_name = 'ZJPPJM' ).
        CHECK lr_context_node IS BOUND.
        lr_iterator = lr_context_node->collection_wrapper->get_iterator( ).
        IF lr_iterator->size( ) > 0.
          lr_btitems ?= me->typed_context->btitems->collection_wrapper->get_current( ).
          lr_access = lr_iterator->get_first( ).
          WHILE lr_access IS BOUND.
            CLEAR:gv_string.
            lr_access->get_properties( IMPORTING es_attributes = ls_crmt0057 ).
            TRY.
                lr_item ?= lr_btitems->create_related_entity( 'BTOrderItemAll' ).
              CATCH cx_crm_genil_model_error INTO gr_cx_crm_genil_model_error.
                gv_string = gr_cx_crm_genil_model_error->get_text( ).
            ENDTRY.
            IF lr_item IS BOUND.
              CLEAR:gw_item.
              lr_item->get_properties( IMPORTING es_attributes = gw_item ).
              IF gw_item-guid IS INITIAL.
                CALL FUNCTION 'CRM_GUID_CREATE'
                  IMPORTING
                    ev_guid = gw_item-guid.
              ENDIF.
              gw_item-ordered_prod = ls_crmt0057-product_id.
              lr_item->set_properties( EXPORTING  is_attributes = gw_item ).
              lr_schedext ?= lr_item->get_related_entity( 'BTItemSchedlinExt' ).
              IF lr_schedext IS NOT BOUND.
                lr_schedext ?= lr_item->create_related_entity( 'BTItemSchedlinExt' ).
              ENDIF.
              IF lr_schedext IS BOUND.
                lr_schedlin ?= lr_schedext->get_related_entity( 'BTSchedlinAll' ).
                IF lr_schedlin IS NOT BOUND.
                  lr_schedlin ?= lr_schedext->create_related_entity( 'BTSchedlinAll' ).
                ENDIF.
                IF lr_schedlin IS BOUND.
                  CLEAR:ls_schedlin.
                  ls_schedlin-quantity = ls_crmt0057-quantity.
                  lr_schedlin->if_bol_bo_property_access~set_properties( is_attributes = ls_schedlin ).
                ENDIF.
              ENDIF.
              typed_context->btitems->collection_wrapper->add( lr_item ).
            ENDIF.
            lr_access = lr_iterator->get_next( ).
          ENDWHILE.
        ENDIF.
    
      ENDMETHOD.

    效果:

  • 相关阅读:
    struts 提交问题
    struts spring整合出错
    hibernate.cfg.xml
    myeclipse copy问题
    myeclipse copy时出的问题
    mysql sql 语句
    Spring_Hibernate
    WebView
    Notification
    Handler(消息机制)
  • 原文地址:https://www.cnblogs.com/sapSB/p/7770645.html
Copyright © 2020-2023  润新知