在使用的元件中添加元件對象
Outbound Plug中添加外向連接配接:OP_PRODUCT
METHOD op_product.
DATA: lv_title TYPE string,
lr_context TYPE REF TO cl_bsp_wd_context_node,
lr_qs TYPE REF TO cl_crm_bol_dquery_service,
lr_current TYPE REF TO cl_crm_bol_entity,
ls_general TYPE zcorder_general,
lv_low TYPE string,
lr_col TYPE REF TO if_bol_bo_col,
lv_col TYPE REF TO if_bol_bo_col,
lr_param TYPE REF TO if_bol_bo_property_access,
lr_iterator TYPE REF TO if_bol_bo_col_iterator,
ls_selection TYPE genilt_selection_parameter,
lv_country TYPE land1,
lv_bp_guid TYPE bu_partner_guid,
lv_sales_org TYPE crmt_sales_org.
IF gr_product_vh_popup IS NOT BOUND.
lv_title = cl_wd_utilities=>get_otr_text_by_alias( 'CRM_UIU_BT/PRODUCT_SEARCH' ).
gr_product_vh_popup = comp_controller->window_manager->create_popup(
iv_interface_view_name = 'SearchHelpWindow'
iv_usage_name = 'CUProductValueHelp'
iv_title = lv_title ).
ENDIF.
gr_product_vh_popup->set_display_mode( if_bsp_wd_popup=>c_display_mode_surrounded ).
gr_product_vh_popup->set_on_close_event( iv_view = me iv_event_name = 'SELECTPRODUCT' ).
gr_product_vh_popup->open( iv_inbound_plug = 'CLEAR_ALL'
iv_collection = lv_col ).
lr_context = gr_product_vh_popup->get_context_node( 'SEARCH' ).
CHECK lr_context IS BOUND.
* Get DQuery object to add search parameter
lr_qs ?= lr_context->collection_wrapper->get_current( ).
* lr_qs = cl_crm_bol_dquery_service=>get_instance( 'ProdAdvSearchRgProducts' ).
lr_current ?= me->typed_context->zcorder->collection_wrapper->get_current( ).
lr_current->get_properties( IMPORTING es_attributes = ls_general ).
lv_low = ls_general-sales_org.
lr_col = lr_qs->get_selection_params( ).
lr_iterator = lr_col->get_iterator( ).
lr_param = lr_iterator->get_first( ).
WHILE lr_param IS BOUND.
lr_param->get_properties( IMPORTING es_attributes = ls_selection ).
IF ls_selection-attr_name = 'SALES_ORG' .
lr_col->remove( lr_param ).
EXIT.
ENDIF.
IF ls_general-country EQ 'JP'.
IF ls_selection-attr_name = 'ZZ0016' .
lr_col->remove( lr_param ).
EXIT.
ENDIF.
ENDIF.
lr_param = lr_iterator->get_next( ).
ENDWHILE.
IF lv_low IS INITIAL.
CALL FUNCTION 'BP_CENTRALPERSON_GET'
EXPORTING
iv_username = sy-uname
IMPORTING
ev_bu_partner_guid = lv_bp_guid
EXCEPTIONS
no_central_person = 1
no_business_partner = 2
no_id = 3
OTHERS = 4.
IF sy-subrc = 0.
SELECT SINGLE b~country
FROM but000 AS a INNER JOIN but020 AS c
ON a~partner = c~partner
INNER JOIN adrc AS b
ON c~addrnumber = b~addrnumber
INTO lv_country
WHERE a~partner_guid = lv_bp_guid.
SELECT SINGLE sales_org
INTO lv_sales_org
FROM zbp_sales
WHERE bu_group IN ('Z001','Z021')
AND country = lv_country.
lv_low = lv_sales_org.
ENDIF.
ENDIF.
lr_qs->add_selection_param( iv_attr_name = 'SALES_ORG'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = lv_low ).
lr_qs->add_selection_param( iv_attr_name = 'CATEGORY_ID'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = 'MAT_FERT' ).
IF ls_general-country EQ 'JP'.
lv_low = ls_general-zzzmodeno.
lr_qs->add_selection_param( iv_attr_name = 'ZZ0016'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = lv_low ).
ENDIF.
lr_col = lr_qs->get_selection_params( ).
lr_iterator = lr_col->get_iterator( ).
lr_param = lr_iterator->get_first( ).
WHILE lr_param IS BOUND.
lr_param->get_properties( IMPORTING es_attributes = ls_selection ).
IF ls_selection-attr_name = 'SALES_ORG' AND ls_selection-low IS INITIAL.
lr_col->remove( lr_param ).
ENDIF.
IF ls_general-country EQ 'JP'.
IF ls_selection-attr_name = 'ZZ0016' AND ls_selection-low IS INITIAL.
lr_col->remove( lr_param ).
ENDIF.
IF ls_selection-attr_name = 'CATEGORY_ID' AND ls_selection-low IS INITIAL.
lr_col->remove( lr_param ).
ENDIF.
ENDIF.
lr_param = lr_iterator->get_next( ).
ENDWHILE.
IF ls_general-country EQ 'JP'.
gr_product_vh_popup->open( iv_inbound_plug = 'CLEAR_ALL'
iv_collection = lr_col ).
ELSE.
gr_product_vh_popup->open( iv_inbound_plug = 'SEARCHPRODANDOBJECTS'
iv_collection = lr_col ).
ENDIF.
ENDMETHOD.
重定義PRODUCT的GET_V方法:
METHOD get_v_product_id.
CREATE OBJECT rv_valuehelp_descriptor
TYPE
cl_bsp_wd_valuehelp_navdescr
EXPORTING
iv_outbound_plug = 'OP_PRODUCT'.
ENDMETHOD.
建立SELECTPRODUCT事件,将傳回的搜尋結果帶回界面:
METHOD eh_onselectproduct.
DATA lv_outbound_plug TYPE seocmpname.
DATA lr_context_node TYPE REF TO cl_bsp_wd_context_node.
DATA lr_col_wrapper TYPE REF TO cl_bsp_wd_collection_wrapper.
DATA lr_current TYPE REF TO if_bol_bo_property_access.
DATA lr_iobject_id TYPE REF TO data.
DATA lr_product_guid TYPE REF TO data.
DATA lr_product_id TYPE REF TO if_bol_bo_property_access.
DATA lr_ent TYPE REF TO cl_crm_bol_entity.
DATA l_prd_desc TYPE comt_prshtextx.
DATA l_prd_guid TYPE comt_product_guid.
FIELD-SYMBOLS <lv_product_id> TYPE any.
FIELD-SYMBOLS <lv_product_guid> TYPE any.
lr_context_node = gr_product_vh_popup->get_context_node( iv_cnode_name = 'PRD' ).
lr_col_wrapper = lr_context_node->collection_wrapper.
lr_current ?= lr_col_wrapper->get_current( ).
IF lr_current IS BOUND.
* check outbound plug
lv_outbound_plug = gr_product_vh_popup->get_fired_outbound_plug( ).
CHECK lv_outbound_plug = 'RETURNRESULT'.
lr_iobject_id ?= lr_current->get_property( iv_attr_name = 'PRODUCT_ID' ).
lr_current->get_property_as_value( EXPORTING iv_attr_name = 'PRODUCT_GUID'
IMPORTING ev_result = l_prd_guid ).
ASSIGN lr_iobject_id->* TO <lv_product_id>.
* Get Product Description
SELECT SINGLE short_text
INTO l_prd_desc
FROM comm_prshtext
WHERE product_guid = l_prd_guid
AND langu = sy-langu.
* lr_product_guid ?= lr_current->get_property( iv_attr_name = 'PRODUCT_GUID' ).
* ASSIGN lr_product_guid->* TO <lv_product_guid>.
* lr_ent = get_main_ref_object( ).
DATA:
lr_cn TYPE REF TO cl_bsp_wd_context_node.
FIELD-SYMBOLS:
<lr_cn> TYPE any.
* ASSIGN me->context->('') TO <lr_cn>.
* IF <lr_cn> IS ASSIGNED.
* lr_cn ?= <lr_cn>.
lr_ent ?= me->typed_context->zcorder->collection_wrapper->get_current( ).
* ENDIF.
lr_ent->set_property( iv_attr_name = 'PRODUCT_ID' iv_value = <lv_product_id> ).
lr_ent->set_property( iv_attr_name = 'PRODUCT_ID_DES' iv_value = l_prd_desc ).
* lr_ent->set_property( iv_attr_name = 'GUID_OBJECT' iv_value = <lv_product_guid> ).
ENDIF.
ENDMETHOD.