Geeks With Blogs

News
 
 
My Visual Identity
 
www.flickr.com
This is a Flickr badge showing photos in a set called Personal Favorites. Make your own badge here.

 
maina donaldson a pragmatist's blog

When you're working with BizTalk SAP adapter to call BAPIs or RFCs, you will find that any create/delete/update call requires you to make an additional BAPI call to BAPI_TRANSACTION_COMMIT or BAPI_TRANSACTION_ROLLBACK to commit the data into SAP. This does not, as one might expect, involve a distributed transaction (Atomic scope shape in orchestration), but it requires setting connection properties on the adapter to control the persistence of connections.  Here are the steps to commit or rollback a transaction using the BizTalk 2006 SAP adapter (yes, you will need an orchestration)

  1. In the orchestration project, add a reference to Microsoft.BizTalk.SAPAdapterProperties.dll, usually found in C:\Program Files\Microsoft BizTalk Adapter v2.0 for mySAP Business Suite\.
     
  2. Before sending the first (transaction initializing) message to SAP, a message construction shape is used to control port properties on the message.
    The above MessageAssignment shape above contains the following code:

         msgSAPRequest = msgPurchaseOrder;
         msgSAPRequest(SAPSend.ConnectionType) = "OPENREUSE";

    This sets up the SAP connection to remain open until it is explicitly closed. For BAPI calls to be committed, they need to be executed on the same connection.
    A decide shape is used to check for call success and branches into either commit or rollback calls.
     
  3. Any subsequent call to additional BAPIs should use the "REUSECONNECTION" attribute:
     
         msgAdditionalRequest(SAPSend.ConnectionType) = "REUSECONNECTION";
     
  4. The transaction commit message is constructed using a simple message construction / assignment combo


    Where, again, the MessageAssignment shape above contains the following code (the Commit bapi takes one parameter, WAIT, which expects a value of "X"):

         xmlDoc = new System.Xml.XmlDocument();
         xmlDoc.LoadXml("<ns0:BAPI_TRANSACTION_COMMIT_Request 
             xmlns:ns0='http://schemas.microsoft.com/BizTalk/2003'><WAIT>X</WAIT></ns0:BAPI_TRANSACTION_COMMIT_Request>");
         msgCommitRequest = xmlDoc;
         msgCommitRequest(SAPSend.ConnectionType) = "REUSECLOSECONNECTION";

    This re-uses and then closes the SAP connection. The same assignment should be used to construct the even simpler Rollback message.
     

 

Posted on Monday, October 29, 2007 5:21 PM BizTalk and SOA | Back to top


Comments on this post: Transactions with the BizTalk 2006 R2 SAP Adapter

# re: Transactions with the BizTalk 2006 R2 SAP Adapter
Requesting Gravatar...
Be very careful about trying to reuse a transactional connection when Biztalk is clustered. If the service instance is dehydrated and rehydrated to another server in the host between the 2 SAP calls, or even between a Send and Receive pair the transaction context is NOT transferred. The call to BAPI_TRANSACTION_COMMIT will fail, and the SAP Adapter may not handle the failure condition. Our experience is that the Receive shape is eternally waiting for a message that will never arrive.

The connection context is bound between the servers, not the service instance, this is imposed by the SAP .NET connector and is therefore incompatible with a clustered solution.

You cannot scale out a biztalk solution using the SAP adapter if you use OPENREUSE when you have a transaction. The ONLY way we solved this is to wrap ALL ( yes ALL ) SAP BAPIs that require a transaction commit with a custom written BAPI that invokes a COMMIT internally. If you need 2 transactional BAPIs as a unit of work, you need to wrap BOTH as a single call.

This effectively renders the SAP Adapter useless, you might as well use the SOAP Adapter, or a WCF adapter ( although I haven't validated that the SAP SOAP interface is compatible with WCF )
Left by Robert Slaney on Nov 20, 2007 2:18 PM

# re: Transactions with the BizTalk 2006 R2 SAP Adapter
Requesting Gravatar...
In your example you explained to set the property. Which value is correct "REUSECONNECTION" or "REUSECLOSECONNECTION". Or does both work. If both strings are accepted from SAP could you explain, how to use each.

Any subsequent call to additional BAPIs should use the "REUSECONNECTION" attribute:

msgAdditionalRequest(SAPSend.ConnectionType) = "REUSECLOSECONNECTION";

hx.bergen@freenet.de
Left by hbergen on Jul 26, 2008 5:00 AM

Your comment:
 (will show your gravatar)


Copyright © Maina Donaldson | Powered by: GeeksWithBlogs.net