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.