Distributing Business Transaction Data from SAP CRM to an external system using the CRM XIF Adapter

 Distributing Business Transaction Data from SAP CRM to an external system using the CRM XIF

 Adapter Applies to: SAP CRM 7.0 on Web AS 700 (SAP_ABA 700, SAP_BASIS 700, BBPCRM 500)

 Summary:  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.


A scenario where we had to interface CRM Business transaction Data to an external system called ISAR,


The challenge here was to interface SAP CRM and ISAR with/without a powerful middleware such as SAP XI. For transferring 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. 

 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.


Requirement: 

1. When Orders are created or changed in CRM should be distributed to an external system i.e. 3rd Party System 

2. If you want to do any validations on field level in CRM should be distributed to an external system i.e. 3rd Party System 

 3. The interface between SAP CRM and the external system should be in Real-Time 

 Approach: 

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 transaction data is created or changed.

 • • CRM Middleware: A messaging BDoc (mBDoc) is generated: - 

 • BDoc message of type BUS_TRANS_MSG is generated whenever Business transaction data is created or changed.

 • • External Interface (XIF) Adapter: Contains BADI enhancements which can be used for: 

  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 • •

 Delivery of the message: This could happen in one of 2 ways: - 

  SOAP/XML - The message is dispatched as a SOAP-XML Message 

  ALE/Idoc - The message is mapped to an IDoc and dispatched 

 In our example we shall dispatch the outbound message using the ALE/IDoc approach



Please Note: - 

• From an SAP CRM view point, XI/other system is the receiving system 
• So all XIF and ALE configuration in SAP CRM is done with respect to XI/other system

Configuration of the Interface Scenario 

Extensions to the CRM XIF Complex Structure for Business Transaction Data

Please Note: - 

  Although the business transaction data is distributed using IDoc, the extension is not at the ALE Layer which means we are not using IDoc extension

We are extending the structure centrally at the XIF layer and controlling the custom fields there so they will be reflected in the subsequent outbound message (whether we choose IDoc or SOAP method for distribution) and this will applicable for CRM 5.0 system only

When we add any custom fields through AET i.e from SAP CRM(7.0) Web UI, custom fields will automatically reflect in the API structures.

In this section, we added custom fields to table CUSTOMER_H, CUSTOMER_I, through AET.

We will generate custom IDoc message type for the Business transaction data Interface which will contain the fields from the standard structure and the custom fields from the append structure. 

Later in this article, we will see how to populate the custom structure fields through a BADI enhancement which is called within the XIF framework before it passes to the ALE Layer.


Generation of Custom Message Type from the ALE Interface

Create a new Function Group ZFM and activate the same through BDFG transaction code

Start Transaction BDFG 
 Enter Function Module as CRMXIF_ORDER_SAVE and press Enter. 
The corresponding Business Object and relevant Message Types are displayed
 From the menu choose InterfaceCreate
 Enter the parameters as per requirement for Outbound Processing. 

 Note: You can enter Inbound Processing parameters also, if there are any validations needs to be done when receiving an IDoc to CRM System.

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 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 Inbound Messages 
Validating Business Transaction Data 
Create a BADI implementation and activate the same as follows: - 

 BADI Defination CRMXIF_ORDER_MAP BADI
 Implementation ZXX_XXXX_XXX 
BADI Implementation Description Business transaction Data External Interface
 Enhancement Implement the method IF_EX_CRMXIF_ORDER_MAP~CHANGE_MAPPED_DATA_IN. 

In this method, if we receive data into internal table IS_DATA , we can validate the data at this level and we can prevent the order creation at this level, if data validation fails. 

Once done with successful validation, if you want to populate the custom fields data, then populate the data at method PREPARE in BADI ORDER_SAVE.

After successful population of custom fields, Business transaction data (order) save will be done through ORDER_SAVE. Once Business Transaction Data or Order is created without any errors, result will get generated BDoc type BUS_TRANS_MSG and after successful process of Bdoc , triggers the BADI CRMXIF_ORDER_MAP, for outbound Idoc Generation.

BADI Enhancement Implementation for the Outbound Messages

Filtering Business Transaction Data

Create a BADI implementation and activate the same as follows: -

BADI Defination CRMXIF_ORDER_MAP 
BADI Implementation ZXX_XXXX_XXX 
BADI Implementation Description: Business transaction Data External Interface Enhancement 


Implement the method IF_EX_CRMXIF_ORDER_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.

ALE Setup Logical System setup 
  • Start Transaction BD54 
  • Enter a new Logical System and also ensure that an entry for Logical System XXCLNTXXX exists. 
This logical system must be assigned to CRM Client XXX (see Transaction SCC4) .


RFC Destination setup
  • Start Transaction SM59 
  • Create a new RFC Destination of Type ‘G’ (HTTP Connections to External Server) 

Note: Connection Type is on Customer Requirement

ALE Port 
  • Start Transaction WE21
 • Create a new ALE Port XXX of type XXX 
  • Enter the RFC Destination, which is created from above step 
 • Choose the content type as Application/x-idoc

ALE Partner Profile 
 • Start Transaction WE20 
 • Create a Partner Profile XXCLNTXXX of Type LS (Logical System) 
 • Enter the Inbound and Outbound parameters details with Message Types.

Perform a Technical Consistency Check for the model in Transaction BDM5. Switch off the cross-system checking when performing this check.

Distribution Model is creation is not necessary in my case. So it depends on requirement create the Model through BD64 and enter Source, Destination and message type details.

External Interface Adapter (XIF) Setup Create new Site 
 Start Transaction SMOEAC (Administration Console ) 
 Create a new site XXXX of type External Interface for IDOCs
 In the Site Attributes enter the ALE Partner profile XXCLNTXXX 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 by entering publication details and to which site we have to assign the subscription. 

Assign Site ID to Interface Type

 Start Transaction CRMXIF_C1 
 Enter new entries in the table Site ame, Site Type, Bdoc Type and Interface name is nothing but Function Module, which is used for creation of Idoc, Message Type and Outbound and Inbound FMs. 
 This table links the mBDoc Type to the respective External Interface (XIF) Function Module

If you want to send an IDOC to B2B or Web Methods, then create a custom method, to send Idoc to the respective partners. 

Where you can use FMs CRMXIF_IDOC_OUTB_FN_GET , ALE_CRMXIF_ORDER_SAVE_M .


Get corresponding Outbound Function Module Name CALL FUNCTION 'CRMXIF_IDOC_OUTB_FN_GET' 
EXPORTING 
iv_interface = 'CRMXIF_ORDER_SAVE' 
iv_rcvprn = ls_rcv-rcvprn 
iv_rcvprt = ls_rcv-rcvprt 
IMPORTING 
ev_aleout_fname = lv_ale_fname 
CHANGING 
ct_error_segments = ct_error_segments

IF lv_ale_fname IS INITIAL. 
* Call 'default' ALE outbound 
CALL FUNCTION 'ALE_CRMXIF_ORDER_SAVE_M' 
EXPORTING 
data = is_data_mapped 
receivers = lt_rcv. 
ELSE. 
* Call ALE outbound 
CALL FUNCTION lv_ale_fname 
EXPORTING 
data = is_data_
mapped receivers = lt_rcv. 
ENDIF


Running Interface: 
 Once Inbound Idoc is received, Order will create 
 Once Order is created, Bodc will generate successfully if there is no errors. 
 You can check the Bdocs at Tcode SMW01 
 From Bdoc, outbound Idoc will generate, you can find out the Inbound and Outbound Idocs at Tcode WE02







Comments

Popular posts from this blog

SAP CRM Access Control Engine Overview

SAP Cloud for Customer ( C4C) beginners Guide-Part 2