I'm using .Net NCo 3.0 library and I tried one example of tRFC wherein I see the transaction ID is created and associated with the RFC function and then invoked, after a successful transaction, the transaction ID is deleted, here we maintain the Transaction details in database for each tRFC operation, so, in this case, if the transaction fails, we can get the ID from the database and we can try again, I would like to know the code implementation of retry mechanism, there is a possibility that the SAP server is down, so when and how to restart and make sure that the transaction initiated is executed only once, no loss of data and no duplication.
TidStore tidStore = new TidStore("clientTidStore", false);
static RfcTransaction CreateTransaction(TidStore tidStore, out string data)
{
RfcTransaction trans = new RfcTransaction(); // This creates a fresh TID.;
Console.Write("Please enter some input data: ");
data = Console.ReadLine();
FileStream dataFile = new FileStream(trans.Tid.TID, FileMode.Create, FileAccess.ReadWrite);
byte[] utf8Data = Encoding.UTF8.GetBytes(data);
dataFile.Write(utf8Data, 0, utf8Data.Length);
dataFile.Close();
tidStore.CreateEntry(trans.Tid.TID);
return trans;
}
private void SubmitTransaction(RfcTransaction trans, TidStore tidStore, String data)
{
try
{
IRfcTable dataTable = stfc_write_to_tcpic.GetTable("TCPICDAT");
dataTable.Append();
dataTable.SetValue(0, data);
// Insert the function module into the transaction:
trans.AddFunction(stfc_write_to_tcpic);
stfc_write_to_tcpic = (IRfcFunction)stfc_write_to_tcpic.Clone();
dataTable = stfc_write_to_tcpic.GetTable("TCPICDAT");
dataTable.SetValue(0, data + " -- data of the second function module");
trans.AddFunction(stfc_write_to_tcpic);
trans.Commit(_ECCsystem);
tidStore.SetStatus(trans.Tid.TID, TidStatus.Committed, null);
File.Delete(trans.Tid.TID);
_ECCsystem.ConfirmTransactionID(trans.Tid);
tidStore.DeleteEntry(trans.Tid.TID);
}
catch (Exception e)
{
tidStore.SetStatus(trans.Tid.TID, TidStatus.RolledBack, e.Message);
}
}
}
}