创建一个简单BP的实例

原创 2016年05月31日 12:16:12

  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的代码。





版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

SAP S4 BP事务代码的业务伙伴和供应商,客户之间的表关系

sap

S4 HANA 1511的BP角色创建及供应商数据的创建方法

S4 HANA 1511的BP角色创建及供应商数据的创建方法

SAP S/4 Hana On-premise Edition 1511做了哪些简化

目前SAP推出的版本是1511,1511版做了哪些简化呢?本篇简明介绍相关内容。

SAP供应商和客户的创建

进来遇到一个创建供应商的需求,由于在系统中关于供应商和客户的创建比较特殊,且没有相关函数进行创建, 找到一个类和方法来创建,类名:VMD_EI_API  方法名:MAINTAIN_DIRECT_IN...
  • lyb_yt
  • lyb_yt
  • 2014年01月07日 16:51
  • 6465

客户/供应商主数据批导

cmd_ei_api=>maintain_bapi和VMD_EI_API

SAP S/4HANA 1610后勤之变

SAP S/4HANA,on-premise edition 1610(2016年10月31日)自动集成EWM,APO和BPC及Fiori 2.0。 寻源和采购 利用各种新...

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

SAP ABAP常用增强记录文档

在sap的开发中,如果遇到了标准系统实现不了的需要定制的功能。那么就需要用增强enhancement来实现。 这是一些常用的增强例子。有BADI,有修改。以供修改用。 BADI-ADDRE...
  • budaha
  • budaha
  • 2016年08月03日 10:39
  • 3316

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:创建一个简单BP的实例
举报原因:
原因补充:

(最多只允许输入30个字)