关闭

创建一个简单BP的实例

标签: SAPCRMBOLgenIL
2072人阅读 评论(0) 收藏 举报
分类:

  DATA lr_bol_core TYPE REF TO cl_crm_bol_core.
  DATA ls_query_parameter TYPE crmt_name_value_pair.
  DATA lt_query_params TYPE crmt_name_value_pair_tab.
  DATA lr_bpresult TYPE REF TO if_bol_entity_col.
  DATA lr_property_access TYPE REF TO if_bol_bo_property_access.
  DATA ls_bpresult TYPE crmst_header_object_buil.
  DATA lt_bpresult TYPE TABLE OF crmst_header_object_buil.
  DATA lv_partner TYPE bu_partner .
  DATA lr_root TYPE REF TO cl_crm_bol_entity.
  DATA lr_transaction TYPE REF TO if_bol_transaction_context.
  DATA lr_root_factory TYPE REF TO cl_crm_bol_entity_factory.
  DATA lr_head TYPE REF TO cl_crm_bol_entity.
  DATA lr_standardaddress TYPE REF TO cl_crm_bol_entity.
  DATA ls_standardaddress TYPE crmst_address_buil.
  DATA lr_role TYPE REF TO cl_crm_bol_entity.
  DATA ls_role TYPE crmt_bupa_il_roles.

*加载组件集
  lr_bol_core = cl_crm_bol_core=>get_instance( ).
  lr_bol_core->start_up('BTBP').

*查询BOL
  CLEAR ls_query_parameter.
  REFRESH lt_query_params.
  ls_query_parameter-name = 'TELEPHONE'.
  ls_query_parameter-value = tel.
  APPEND ls_query_parameter TO lt_query_params.
  ls_query_parameter-name = 'ROLECATEGORY'.
  ls_query_parameter-value = 'XXXXX'.
  APPEND ls_query_parameter TO lt_query_params.
  CALL METHOD lr_bol_core->query
    EXPORTING
      iv_query_name               = 'BuilHeaderSearch'
      it_query_params             = lt_query_params
      iv_view_name                = ''
*     iv_add_qresobj_2_bol_buffer = ABAP_FALSE
    RECEIVING
      rv_result                   = lr_bpresult.

***BOL集合转内表
  REFRESH lt_bpresult.
  CALL METHOD lr_bpresult->get_first
    RECEIVING
      rv_result = lr_property_access.
  WHILE lr_property_access IS BOUND.
    CLEAR ls_bpresult.
    lr_property_access->get_properties( IMPORTING es_attributes = ls_bpresult ).
    APPEND ls_bpresult TO lt_bpresult.
    CALL METHOD lr_bpresult->get_next
      RECEIVING
        rv_result = lr_property_access.
  ENDWHILE.

  IF lt_bpresult IS NOT INITIAL."有结果
    READ TABLE lt_bpresult INTO ls_bpresult WITH KEY partnertype = 'XXXX'.
    IF sy-subrc <> 0.
      SORT lt_bpresult BY bp_number DESCENDING.
      READ TABLE lt_bpresult INTO ls_bpresult INDEX 1.
      TRY.
          CALL METHOD lr_bol_core->get_root_entity"获取根对象
            EXPORTING
              iv_object_name = 'BuilHeader'
              iv_object_guid = ls_bpresult-bp_guid
            RECEIVING
              rv_result      = lr_root.
        CATCH cx_crm_genil_model_error .
      ENDTRY.
      IF lr_root IS BOUND ."赋值
        CALL METHOD lr_root->if_bol_bo_property_access~set_property
          EXPORTING
            iv_attr_name = 'PARTNERTYPE'
            iv_value     = 'YYYY'.
***保存并提交数据
        lr_bol_core->modify( ).
        lr_transaction = lr_bol_core->get_transaction( ).
        lr_transaction->save( ).
        lr_transaction->commit( ).
      ENDIF.
    ENDIF.
    bp = ls_bpresult-bp_number.
    EXIT.
  ENDIF.

***无结果则创建
***建立BOL的factory
  lr_root_factory = lr_bol_core->get_entity_factory( 'BuilHeader' ).
***建立根对象
  CLEAR ls_query_parameter.
  REFRESH lt_query_params.
  ls_query_parameter-name = 'BP_CATEGORY'.
  ls_query_parameter-value = '1'."个人
  APPEND ls_query_parameter TO lt_query_params.
  ls_query_parameter-name = 'BP_NUMBER'.
  ls_query_parameter-value = lv_partner.
  APPEND ls_query_parameter TO lt_query_params.
  ls_query_parameter-name = 'BP_GROUP'.
  ls_query_parameter-value = 'YYYY'.
  APPEND ls_query_parameter TO lt_query_params.
  ls_query_parameter-name = 'LASTNAME'.
  ls_query_parameter-value = name.
  APPEND ls_query_parameter TO lt_query_params.
  ls_query_parameter-name = 'BP_TYPE'.
  ls_query_parameter-value = 'ZZZZ'.
  APPEND ls_query_parameter TO lt_query_params.
*  ls_query_parameter-name = 'SEX'.
*  ls_query_parameter-value = '1'.
*  APPEND ls_query_parameter TO lt_query_params.
  ls_query_parameter-name = 'NATURAL_PERSON'.
  ls_query_parameter-value = 'X'.
  APPEND ls_query_parameter TO lt_query_params.
  lr_head = lr_root_factory->create( lt_query_params ).
***进一步维护数据
  IF lr_head IS BOUND.
***建立和维护关系
    lr_standardaddress = lr_head->create_related_entity( 'BuilStandardAddressRel' ).
    CLEAR ls_standardaddress.
    ls_standardaddress-standardaddress = 'X'.
    ls_standardaddress-telephonemob = tel.
    ls_standardaddress-r_3_usermob = '3'.
    ls_standardaddress-country = 'CN'.
    ls_standardaddress-countryiso = 'CN'.
    ls_standardaddress-time_zone = 'UTC+8'.
    lr_standardaddress->set_properties( EXPORTING is_attributes = ls_standardaddress ).

    lr_role = lr_head->create_related_entity( iv_relation_name = 'BuilRolesRel' ).
    CLEAR ls_role.
    ls_role-partnerrole = 'GGGGGGG'.
    ls_role-partnerrolecategory = 'GGGGGGG'.
    ls_role-valid_from = '00010101'.
    ls_role-valid_to  = '99991231'.
    lr_role->set_properties( EXPORTING  is_attributes = ls_role ).

***保存并提交数据
    lr_bol_core->modify( ).
    lr_transaction = lr_bol_core->get_transaction( ).
    lr_transaction->save( ).
    lr_transaction->commit( ).

    bp = lv_partner.

  ENDIF.

对于查询出的结果,由于是BOL对象,是可以直接修改并保存成功到数据库的,不一定非要走根据GUID再查HEADER的过程。


分配销售范围和关系

    lr_sales_area = lr_head->create_related_entity( iv_relation_name = 'BuilSalesArrangementRel' ).
    CLEAR ls_sales_area.
    ls_sales_area-sales_org = lv_sales_org.
    ls_sales_area-channel = '01'.
    lr_sales_area->set_properties( EXPORTING  is_attributes = ls_sales_area ).

    lr_pricingterm = lr_sales_area->create_related_entity( iv_relation_name = 'BuilPricingTermsRel' ).
    CLEAR ls_pricingterm.
    ls_pricingterm-cust_pric_proc = '1'.
    ls_pricingterm-currency = 'CNY'. 
    ls_pricingterm-owner  = 'X'.
    lr_pricingterm->set_properties( EXPORTING  is_attributes = ls_pricingterm ).

    lr_relation1 = lr_head->create_related_entity( iv_relation_name = 'BuilEmplResponsRel' ).
    CLEAR ls_relation.
    ls_relation-partner2 = bp.
    ls_relation-relationshipcategory = 'BUR011'.
    ls_relation-defaultrelationship = 'X'.
    lr_relation1->set_properties( EXPORTING  is_attributes = ls_relation ).

    lr_relation2 = lr_head->create_related_entity( iv_relation_name = 'BuilRelationshipRel' ).
    CLEAR ls_relation.
    ls_relation-partner2 = bp.
    ls_relation-relationshipcategory = 'ZXXXXX'.
    lr_relation2->set_properties( EXPORTING  is_attributes = ls_relation ).

注意关系里面用到的BP的类别,如果不对会加不了关系,具体可以看下事务代码【BUBA】。


多说一句,crm7.0默认是会根据登陆的账号自动创BUR011负责人的,具体可以看下BP_HEAD的代码。





0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:29195次
    • 积分:781
    • 等级:
    • 排名:千里之外
    • 原创:50篇
    • 转载:8篇
    • 译文:0篇
    • 评论:7条
    文章分类
    最新评论