Escolar Documentos
Profissional Documentos
Cultura Documentos
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Applies to:
SAP CRM 5.0 on Web AS 700 (SAP_ABA 700, SAP_BASIS 700, BBPCRM 500)
Summary
This article is based on a customer specific requirement which I have undertaken on a project. It describes a scenario where CRM Business Partner Master Data and Relationship Data is distributed to an External NonSAP System called Centrix. The interface setup was done through a combination of CRM XIF adapter setup, BADI enhancement (for populating custom fields) and IDoc Technology to distribute the data. This article explains how the interface was configured in SAP CRM step by step. Author(s): Aditya S Palekar Company: SAP Global Delivery Centre, India Created on: 08 January 2007
Author Bio
Aditya Palekar is an SAP Development Consultant working for SAP Global Delivery Centre at Bangalore, India. He has 5 years of ABAP programming experience which includes programming on SAP ECC. He has undertaken projects for customers based in India, UK and USA and has played the role of a developer and development lead
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Table of Contents
Applies to: ........................................................................................................................................ 1 Summary.......................................................................................................................................... 1 Author Bio ........................................................................................................................................ 1 Preface............................................................................................................................................. 3 Project Requirement ........................................................................................................................ 4 The Approach .................................................................................................................................. 4 Technical System Landscape.......................................................................................................... 5 SAP CRM 5.0 ........................................................................................................................... 6 Magma...................................................................................................................................... 6 Centrix ...................................................................................................................................... 6 Configuration of the Interface Scenario ........................................................................................... 7 Extension to the CRM XIF Complex Structure ............................................................................ 7 Generation of Custom Message Type from the ALE Interface .................................................... 8 BADI Enhancement Implementation for the Outbound Messages .............................................. 9 Filtering the Business Partners per Business Partner Category .............................................. 9 Populating Custom Fields for the BP Relationship in the outbound message....................... 11 ALE Setup .................................................................................................................................. 15 Logical System setup ............................................................................................................. 15 RFC Destination setup ........................................................................................................... 15 ALE Port ................................................................................................................................. 17 ALE Partner Profile................................................................................................................. 17 Customer Distribution Model .................................................................................................. 19 External Interface Adapter (XIF) Setup...................................................................................... 20 Create new Site ...................................................................................................................... 20 Create new Subscription(s) .................................................................................................... 20 Assign Site ID to Interface Type ............................................................................................. 21 Running the Interface .................................................................................................................... 21 Debugging the BADI Enhancement while running the Interface ................................................... 24 Related Content............................................................................................................................. 27 Copyright........................................................................................................................................ 28
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Preface
This article is based on a customer specific requirement which I have undertaken on a project. It describes a scenario where we had to interface CRM Business Partner Master Data and Relationship Data to an external system called Centrix. Centrix is based on a SQL Server Database platform and required the master data from CRM to perform subsequent processes such as Billing to the customer. The challenge here was to interface SAP CRM and Centrix without a powerful middleware such as SAP XI. The customer eventually decided to implement XI but that was several months later in the Project. For the interfacing between SAP CRM and Centrix we used a system called Magma from Cindercone Solutions Ltd, UK. After thoroughly evaluating the technical capabilities we found that we can use Magma to listen to incoming IDocs from SAP CRM via HTTP, map them to the structures in Centrix and update the tables through SQL Insert commands. Magma contained ODBC drivers to connect to the Centrix database and perform SQL Insert operations. For transferring the Relationship data from SAP CRM, we had to introduce custom structures with additional fields as the standard IDoc in CRM did not contain all the data we needed. So BADI enhancements had to be implemented to populate these custom structures. Separate setup was required on Magma to listen to the incoming requests from SAP CRM. Separate database tables were setup on Centrix system to store the records coming from SAP CRM via Magma. This document does not discuss the details about the technical setup of Magma and Centrix. It focuses mainly on delivering the master data from SAP CRM to Magma and setup required from SAP specific to the requirement Now I am aware that there is standard documentation on CRM XIF function modules, but this specific case uses a combination of XIF, BADI enhancement, ALE/IDoc all working together. I found this mix of technology to be quite interesting and I am writing this article which would benefit other developers on similar requirements in the future as they would know more about the capabilities of the CRM XIF interface through this example
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Project Requirement
Business Partners created or changed in CRM should be distributed to an external system Centrix Business Partners in specific BP roles would be created / changed in SAP CRM and must be distributed to the external system. These roles are: o o o o Sold-To Party Ship-To Party Payer Bill-To Party
Business Partners in CRM would be linked together by means of Business Partner relationships When a new BP relationship is added or an existing BP relationship is deleted from a Business Partner, the relationships need to be distributed to the external system so the linkage is maintained there as well For each relationship that is created / deleted, the other logically linked business partners should be sent out in the same message The interface between SAP CRM and the external system should be in Real-Time
The Approach
Refer to the diagram below: -
SAP CRM contains a component called the External Interface Adapter (XIF) which allows you to interface between SAP CRM and external systems The interaction between the different layers is as follows: CRM Server: Business Partner master data / relationship data is created or changed CRM Middleware: A messaging BDoc (mBDoc) is generated: BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 4
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
o o
BDoc message of type BUPA_MAIN is generated whenever Business Partner Master Data is created or changed BDoc message of type BUPA_REL is generated whenever a Business Partner Relationship is created or modified Manipulate the data in outbound as well as inbound messages Populate data in custom structures in outbound and inbound messages Reject / Filter out messages that do not match your criteria Manipulations made to the outbound message are reflected in the IDoc / SOAP-XML stream SOAP/XML ALE/Idoc The message is dispatched as a SOAP-XML Message The message is mapped to an IDoc and dispatched
External Interface (XIF) Adapter: Contains BADI enhancements which can be used for: o o o o
In our example we shall dispatch the outbound message using the ALE/IDoc approach
The systems in the landscape are: SAP CRM 5.0 Magma Centrix
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
SAP CRM 5.0 This is the source of all Business Partner Master Data and Business Partner Relationship data Business Partner Master and Relationship Data is sent to Magma as an IDoc in XML format over HTTP protocol Three clients were provided in our SAP CRM development system as follows: 200 210 220 Master Config Client Sandpit Client Unit Testing Client
Please Note: For our requirement, we shall perform all configuration/setup in Client 200 and test in Client 210 Magma Listens to incoming HTTP requests from SAP CRM Maps the incoming IDoc (in XML format over HTTP protocol) to the target structures in Centrix Updates the Centrix database tables through SQL INSERT statements
Centrix This is the receiving system in the entire integration Receives the Business Partner Master and Relationship data from Magma (which in turn comes from SAP CRM)
Please Note: From an SAP CRM view point, Magma is the receiving system So all XIF and ALE configuration in SAP CRM is done with respect to Magma
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Table Type to hold multiple records of the Structure Create a new Table Type ZDB1_CENTRIX_INTERFACE_T Table Type for CRM to Centrix Interface Structure with line type as ZDB1_CENTRIX_INTERFACE structure Append Structure for Create a new Append Structure ZDB1_CENTRIX_APPEND structure BURS_EI_RELATION_DATA as follows: Component ZZCENTRIXDATA Component Type ZDB1_CENTRIX_INTERFACE_T Centrix Interface Data Structure for the
Set the Enhancement Category to Can be enhanced (Deep) Structure BURS_EI_RELATION_DATA is the data type for the component CENTRAL_DATA of the CRM Relationship complex structure CRMXIF_PARTNER_REL_COMPLEX It is under this level that we are attaching the append structure with the custom fields These fields will be reflected in the Hierarchical structure of IDoc Type as we will create a custom message type from this extended Complex Structure Generation of Custom Message Type from the ALE Interface Create a new Function Group ZDB1_BUPARELALE and activate the same Function Group ZDB1_BUPARELALE Description BP Relationship - External Interface
Start Transaction BDFG Enter Function Module as CRMXIF_PARTNER_REL_SAVE and press Enter. The corresponding Business Object and relevant Message Types are displayed From the menu choose Interface Create Enter the parameters as shown below for Outbound Processing. Leave the Inbound Processing parameters unpopulated
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Press the Continue button to proceed Once the Interface is generated, choose the menu option Interface Check to see if all components have been created and activated successfully Go to Transaction WE30, enter IDoc Type ZCRMXIF_BUPAREL_EXT01 and choose the menu option Development Object Check. All the non-released segments are highlighted in the check Set the Release for all the non-released Segment Types through Transaction WE31
BADI Enhancement Implementation for the Outbound Messages Filtering the Business Partners per Business Partner Category Create a BADI implementation and activate the same as follows: BADI Definition BADI Implementation BADI Implementation Description
SAP DEVELOPER NETWORK | sdn.sap.com 2006 SAP AG
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Implement the method IF_EX_CRMXIF_PARTNER_MAP~CHANGE_MAPPED_DATA_OUT. In this method, if we delete a line from internal table CS_DATA_MAPPED which does not meet our criteria, we can prevent the IDoc from being generated subsequently. In this way we can filter the master data that is distributed The code below shows how we can validate and filter out the Business Partner data per Business Partner Category
METHOD if_ex_crmxif_partner_map~change_mapped_data_out. ************************************************************************ * METHOD: IF_EX_CRMXIF_PARTNER_MAP~CHANGE_MAPPED_DATA_OUT * * TITLE: CRM Customer Master to Centrix Interface * * AUTHOR: Aditya Palekar (SAP GDC) * * DESCRIPTION: This method is called by the CRM XIF adapter framework * * * * * * * * when an outbound message is generated on Creating or Changing Business Partner main data This method contains a check to ensure that Business Partners of category '2' (Organisation) are sent to external system The method is triggered after the mBDoc of type BUPA_MAIN is created DATE: 20.12.2006 * * * * * * * * * * * * * * *
*** MAIN PROCESSING ***** LOOP AT cs_data_mapped INTO ls_data_mapped. * Store the index of this internal table record in a variable CLEAR lv_tabix. MOVE sy-tabix TO lv_tabix.
* Proceed only if Business Partner belongs to BP Category '2' (Organisation) IF ls_data_mapped-central_data-common-data-bp_control-category <> c_bp_category_org.
SAP DEVELOPER NETWORK | sdn.sap.com 2006 SAP AG BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 10
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Populating Custom Fields for the BP Relationship in the outbound message Create a BADI implementation and activate the same as follows: BADI Definition BADI Implementation BADI Implementation Description CRMXIF_PARTNER_R_MAP ZDB1_CRMXIF_BPRELMAP BP Relationship External Enhancement (BUPA_REL) Interface
*----------------------------------------------------------------------* * This method is used to populate the additional custom fields of the * Relationship Complex Structure while sending the data outbound from * SAP CRM. * The fields populated here are passed on to the outbound IDoc which is * sent to Centrix. *----------------------------------------------------------------------* DATA lv_tabix TYPE sytabix. DATA lv_relat_cat TYPE bu_reltyp.
*** MAIN PROCESSING ***** LOOP AT cs_data_mapped INTO ls_data_mapped. * Store the index of this internal table record in a variable CLEAR lv_tabix. lv_tabix = sy-tabix.
* Proceed only if any one of the following relations were assigned: SAP DEVELOPER NETWORK | sdn.sap.com 2006 SAP AG BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 11
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
* Ship-To Party (Relationship Category --> CRMH02) * Payer (Relationship Category --> CRMH03)
* Bill-To Party (Relationship Category --> CRMH04) CLEAR lv_relat_cat. lv_relat_cat = ls_data_mapped-header-object_instance-relat_category.
* Process only those relationships which have been newly created * or deleted during reassignment of relationships CHECK ls_data_mapped-header-object_task = c_task_insert OR ls_data_mapped-header-object_task = c_task_delete.
CASE lv_relat_cat. *----------------------------------------------------------------------* * RELATIONSHIP CATEGORY 'CRMH02' (HAS A SHIP-TO PARTY/RECIPIENT) * EXISTS BETWEEN THE BUSINESS PARTNERS *----------------------------------------------------------------------* WHEN c_relcat_shipto. CALL METHOD zcl_im_db1_crmxif_bprelmap=>process_ship_to CHANGING cs_bp_rel_data = ls_data_mapped. ENDCASE. " END OF PROCESSING FOR ALL RELATIONSHIP CATEGORIES
* Update the Complex Structure Internal Table with the modified * Centrix Structure data MODIFY cs_data_mapped FROM ls_data_mapped INDEX lv_tabix TRANSPORTING central_data-zzcentrixdata.
ENDLOOP. ENDMETHOD.
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
DATA lv_sold_to_party TYPE bu_partner. DATA lv_bill_to_party TYPE bu_partner. DATA lv_payer TYPE bu_partner. DATA lv_ship_to_party TYPE bu_partner.
DATA lt_return TYPE bapiret2_t. DATA lt_relationships_ship TYPE TABLE OF bapibus1006_relations. DATA lt_relationships_sold TYPE TABLE OF bapibus1006_relations.
* Initialise all relevant variables CLEAR lv_sold_to_party. CLEAR lv_ship_to_party. CLEAR lv_bill_to_party. CLEAR lv_payer.
* Get all Relationships of Sold-To Party REFRESH lt_relationships_sold. REFRESH lt_return. CALL FUNCTION 'BAPI_BUPA_RELATIONSHIPS_GET' EXPORTING businesspartner = lv_sold_to_party
SAP DEVELOPER NETWORK | sdn.sap.com 2006 SAP AG BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 13
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
* Finding the Bill-To Party CLEAR ls_relationship. READ TABLE lt_relationships_ship WITH KEY partner1 = lv_ship_to_party relationshipcategory = c_relcat_billto INTO ls_relationship.
* Finding the Payer CLEAR ls_relationship. READ TABLE lt_relationships_ship WITH KEY partner1 = lv_ship_to_party relationshipcategory = c_relcat_payer INTO ls_relationship.
* If the Payer is attached to the Ship-to Party * ( **** SCENARIO 1: REGIONAL BILL & PAYMENT **** ) IF sy-subrc = 0. * Payer Selected ************ lv_payer = ls_relationship-partner2. ENDIF.
* At this point, all the relevant Business Partners have been determined * Include all the relevant BP Numbers into the Centrix * Interface Structure CLEAR ls_centrix. ls_centrix-zzsapcrm_pay_id ls_centrix-zzsapcrm_bill_id ls_centrix-zzsapcrm_soldto_id
SAP DEVELOPER NETWORK | sdn.sap.com 2006 SAP AG
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
ls_centrix-zzsapcrm_del_id ls_centrix-zzmethod
= lv_ship_to_party. = cs_bp_rel_data-header-object_task.
APPEND ls_centrix TO cs_bp_rel_data-central_data-zzcentrixdata. ENDMETHOD. ALE Setup Logical System setup Start Transaction BD54 Enter a new Logical System as follows: Logical System EX1CENTRIX Description External Interface to CENTRIX
Also ensure that an entry for Logical System CD1CLNT200 exists. This logical system must be assigned to CRM Client 200 (see Transaction SCC4)
RFC Destination setup Start Transaction SM59 Create a new RFC Destination of Type G (HTTP Connections to External Server) In our case, the external system Magma has an application listening on a specified port. The details to be entered for our RFC destination are: -
* The path prefix denotes the exact location of the application which is listening to the IDoc from CRM
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
ALE Port Start Transaction WE21 Create a new ALE Port EX1MAGMA of type XML-HTTP Enter the RFC Destination EXT_MAGMA Choose the content type as Application/x-idoc
ALE Partner Profile Start Transaction WE20 Create a Partner Profile EX1CENTRIX of Type LS (Logical System) Enter the message types CRMXIF_PARTNER_SAVE_M, ZCRMXIF_BUPAREL_EXT and SYNCH
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Please Note: Message Type SYNCH with IDoc Type SYNCHRON is added to the Partner Profile as well Customer Distribution Model Start Transaction BD64 Create a Distribution Model as follows: Sending System Receiving System Message Type(s): CRMXIF_PARTNER_SAVE_M ZCRMXIF_BUPAREL_EXT Perform a Technical Consistency Check for the model in Transaction BDM5. Switch off the crosssystem checking when performing this check CD1CLNT200 EX1CENTRIX
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
External Interface Adapter (XIF) Setup Create new Site Start Transaction SMOEAC Administration Console
Create a new site ZSITE01 of type External Interface for IDOCs as shown in the diagram below In the Site Attributes enter the ALE Partner profile EX1CENTRIX created earlier Hence we have linked the XIF site with the ALE partner profile
Create new Subscription(s) In the same transaction SMOEAC you need to create 2 new subscriptions Subscription Publication Assign to Site ZSUB_BUPA_MAIN All Business Partners (MESG) ZSITE01
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Assign Site ID to Interface Type Start Transaction CRMXIF_C1 Enter 2 new entries in the table as shown in the diagram
This table links the mBDoc Type to the respective External Interface (XIF) Function Module
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
An IDoc of message type CRMXIF_PARTNER_SAVE_M is generated with Status 03 (Data Passed to Port OK)
Similarly, 3 more Business Partners are created as follows: BP Number 13666 13667 13668 BP Role ZCRM03 ZCRM04 ZBUP02 BP Role Description Payer Bill-To Party Sold-To Party
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Now select the Business Partner 13668 (sold-To Party) and create the following Business Partner relationships as shown in the diagram
BP Relationship Description
Category
Save the Transaction An IDoc of message type ZCRMXIF_BUPAREL_EXT is generated The custom segment Z101DB1_CENTRIX_INTERFACE is visible in the IDoc with all the relevant Business Partners which are populated by the method CHANGE_MAPPED_DATA_OUT of BADI implementation ZDB1_CRMXIF_BPRELMAP
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Start Transaction BP Enter the Business Partner details in the respective fields Before you save the transaction, activate the debug mode by typing /h in the command field on the top left and then press Save to save the Business Partner record In the debug mode, set a breakpoint on the method PROCESS_OUTBOUND of global class CL_SMW_MFLOW Once the debugger breaks inside the method PROCESS_OUTBOUND, continue to debug until you reach the point shown in the image below. Change the value of the parameter __DBGMODE to 'X' and then press the F8 (Continue) button to proceed
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Go to Transaction SMW01 and select all BDocs of type BUPA_MAIN. You will notice that the mBDoc message has status; To be processed (Debug).
Select the BDoc and choose the option Reprocess mBDoc message You might get a confirmation dialog box. Choose Yes The program pauses in debug mode inside the method CHANGE_MAPPED_DATA_OUT of the BADI implementation ZDB1_CRMXIF_BPMAP containing your code. From here you can debug the enhancement code
Related Content
For more details on CRM XIF Interface for Business Partners, see documentation of function modules CRMXIF_PARTNER_COMPLEX and CRMXIF_PARTNER_REL_COMPLEX Refer to SAP Note 448742 for General Notes on CRM XIF Interfaces
Distributing Business Partner Master Data from SAP CRM to an external system using the CRM XIF Adapter
Copyright
Copyright 2006 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, OpenPower and PowerPC are trademarks or registered trademarks of IBM Corporation. Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. These materials are provided as is without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages. Any software coding and/or code lines/strings (Code) included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.