.Net SAP Transaction restart from client

360 Views Asked by At

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);
            }
        }
    }
}
    
2

There are 2 best solutions below

0
Mysterious288 On

You need to create your own function with a time interval to check which TID's are not yet processed.

0
Trixx On

With regard to deal with and to implement SAP transaction handling at external program side, there are some general explanations in the SAP NetWeaver RFC SDK 7.50 Programming Guide which are quite helpful, I think. Please see chapters 4.3, 4.4 and 5.5. It is more detailed than what is explained in the SAP .NET Connector 3.0 Programming Guide and it can easily be adapted to the NCo programming APIs as well.