在ECC和CRM的数据交互中,同步分为 初始下载,增量下载和请求下载。如果CRM中发现某个BP的数据和ECC的数据不一致,一般都会在CRM中启动请求下载来同步数据,在ECC中抽取数据,生成BAPIMTCS,到CRM中解析成BDOC。那么可以主动在ECC中,推送这个BP的信息到CRM中吗?答案是肯定的,因为原理是一样的,下面就是实现这个功能的函数yx_crm_bupa_send。
TYPES: BEGIN OF ty_partner,
partner TYPE bu_partner,
partner_guid TYPE bu_partner_guid,
END OF ty_partner.
TYPES: BEGIN OF ty_rel,
dftval TYPE bu_dftval ,
partner1 TYPE bu_partner,
partner2 TYPE bu_partner,
date_to TYPE bu_datto ,
reltyp TYPE bu_reltyp ,
END OF ty_rel.
DATA lv_lines TYPE sytabix VALUE 0.
DATA gt_partners TYPE TABLE OF ty_partner.
CONSTANTS false type boole_d value ”.
*”———————————————————————-
*”*”Local interface:
*” IMPORTING
*” VALUE(PARTNER) TYPE BU_PARTNER
*” VALUE(SXI_SERVICE) TYPE SXI_SERVICE DEFAULT ’BS_CRM_ECC’
*” EXPORTING
*” VALUE(RETURN) LIKE BAPIRET2 STRUCTURE BAPIRET2
*” EXCEPTIONS
*” NO_DATA_SELECTED
*”———————————————————————-
* Select all partner numbers
SELECT partner partner_guid
FROM but000
INTO TABLE gt_partners
WHERE partner = partner.
DESCRIBE TABLE gt_partners LINES lv_lines.
IF lv_lines >= 1 .
PERFORM send_partners USING sxi_service CHANGING return.
ELSE .
CLEAR return .
return-type = ‘I’.
return-id = ‘BUPA_INTERFACE’.
return-number = ‘013′.
return-message = ‘未选择到数据’ .
RAISE no_data_selected.
ENDIF.
ENDFUNCTION.
CHANGING return LIKE bapiret2 .
DATA ls_partner TYPE ty_partner.
DATA ls_rel TYPE ty_rel.
DATA: lt_idlist TYPE TABLE OF bus_ei_instance.
DATA: ls_idlist TYPE bus_ei_instance .
DATA: lt_idlist_rel TYPE TABLE OF bus_bupr_instance .
DATA: ls_idlist_rel TYPE bus_bupr_instance .
DATA: lt_idblock TYPE TABLE OF bus_ei_instance.
DATA: ls_idblock TYPE bus_ei_instance .
DATA: lt_idblock_rel TYPE TABLE OF bus_bupr_instance .
DATA: ls_idblock_rel TYPE bus_bupr_instance .
DATA lv_lines TYPE sytabix.
DATA lv_lines2 TYPE sytabix.
DATA lv_von TYPE sytabix.
DATA lv_bis TYPE sytabix.
DATA lv_result_ok TYPE c VALUE ‘X’.
DATA : pa_bsize TYPE i .
DATA lv_bsize LIKE pa_bsize.
DATA: lv_outbound_active TYPE boolean.
DATA: lt_receiv TYPE sxi_addresses,
lv_receiv TYPE sxi_address .
IF sxi_service NE ”.
lv_receiv-service = sxi_service .
APPEND lv_receiv TO lt_receiv .
ENDIF.
REFRESH lt_idlist.
CLEAR ls_idlist .
lv_bsize = pa_bsize.
LOOP AT gt_partners INTO ls_partner.
ls_idlist-bpartner = ls_partner-partner.
ls_idlist-bpartnerguid = ls_partner-partner_guid.
APPEND ls_idlist TO lt_idlist.
ENDLOOP.
DESCRIBE TABLE lt_idlist LINES lv_lines.
**************************************
*Check that the BP outbound is active.
**************************************
CALL FUNCTION ‘BUPA_OUTBOUND_CHECK_ACTIVE’
IMPORTING
ev_active = lv_outbound_active.
IF lv_outbound_active EQ false.
CLEAR return .
return-type = ‘I’.
return-id = ‘BUPA_INTERFACE’.
return-number = ‘013′.
return-message = ‘未激活业务合作伙伴数据的分销’ .
RETURN.
ENDIF.
***********************************************************************
* work with blocksize
SORT gt_partners.
DESCRIBE TABLE gt_partners LINES lv_lines.
IF pa_bsize = 0.
pa_bsize = lv_lines.
ENDIF.
lv_von = 1.
lv_bis = pa_bsize.
IF lv_bis > lv_lines.
lv_bis = lv_lines.
ENDIF.
CLEAR ls_idblock .
WHILE lv_von <= lv_lines.
LOOP AT lt_idlist INTO ls_idblock FROM lv_von TO lv_bis.
APPEND ls_idblock TO lt_idblock.
ENDLOOP.
CALL FUNCTION ‘BUPA_OUTBOUND_SEND’
EXPORTING
it_idlist_main = lt_idblock
it_receiver_list = lt_receiv
EXCEPTIONS
no_data_selected = 1
OTHERS = 2.
IF sy-subrc <> 0.
lv_result_ok = ‘ ’.
RAISE no_data_selected.
CLEAR return .
return-type = sy-msgty.
return-id = sy-msgid.
return-number = sy-msgno.
return-message = sy-msgv1 .
ENDIF. “ sy-subrc
COMMIT WORK .
lv_von = lv_von + pa_bsize.
lv_bis = lv_bis + pa_bsize.
IF lv_bis > lv_lines.
lv_bis = lv_lines.
ENDIF.
REFRESH lt_idblock.
CLEAR ls_idblock .
REFRESH lt_idblock_rel.
CLEAR ls_idblock_rel .
COMMIT WORK .
ENDWHILE.
IF ( NOT lv_result_ok IS INITIAL ).
CLEAR return .
return-type = ‘S’.
return-id = ‘BUPA_INTERFACE’.
return-number = ‘004′.
return-message = ‘根据定制设置开始处理’ .
ENDIF.
ENDFORM. “ send_partners