2

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);
            }
        }
    }
}
    
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Mysterious288
  • 365
  • 5
  • 24
  • Which part of SAP does your SAP expert know very well? ;-) If you look at NCO documentation, there's nothing about "transaction management". Maybe bgRfc with type RfcUnitType.TRANSACTIONAL? (basically, nothing changes, it's still transactional as your example) Better send an email to your SAP expert. – Sandra Rossi Nov 24 '21 at 15:17
  • Hi @SandraRossi It is not in NCO but it might be an SAP concept that we need to design differently. – Mysterious288 Nov 25 '21 at 03:19
  • Unfortunately, with only the 2 words "transaction management", and if you only use very general tags like SAP and NCO, it's difficult to target the right persons to answer your question. I add the tag "saprfc", let's see if it works better for you... – Sandra Rossi Nov 25 '21 at 11:18
  • Thanks @SandraRossi, I also need knowledge on IDOC, tRFC client and server using NCO, do you have any documentation link and code reference, I have a requirement using IDoc over tRFC. – Mysterious288 Nov 25 '21 at 11:22
  • The NCO documentation is provided with NCO software download. Concerning IDoc, I think you should use the IDoc RFC-enabled functions, you may get some help in SAP Community for obtaining the names of the functions, or ask a separate question here if you prefer. – Sandra Rossi Nov 25 '21 at 11:25
  • Hi @SandraRossi I got the information regarding Transaction Management, here it means to store the transaction Ids in the database for each tRFC operation, so, in this case if the transaction fails, we can get id from the database and try again, but if you see the above tRFC code how to have retry mechanism effectively? – Mysterious288 Nov 26 '21 at 03:21
  • You get the transaction ID (`trans.Tid.TID`) as soon as you start tRFC. It seems you handle it correctly. I don't know how to restart a tRFC at the place it failed, from NCO program. Don't you see any method in the documentation? By the way, could you add an "edit" section to your question, so that to focus on the "retry" part, and make it more legible for future visitors? – Sandra Rossi Nov 26 '21 at 06:43
  • I quickly looked at the documentation, I don't find any "restart" feature. As a workaround, in the ABAP server, it's possible to log in via SAP GUI and manage/restart/debug/delete the failed transactions with the transaction code `SM58` (or indirectly from `SMQR`/`SMQ2`). – Sandra Rossi Nov 26 '21 at 08:02
  • @SandraRossi I have edited the question, thanks for the suggestion and for helping me over here. – Mysterious288 Nov 26 '21 at 12:57
  • Even I 'm looking for a solution, please let me too .net code for tRFC – harshu288 Nov 27 '21 at 17:52

2 Answers2

0

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

Mysterious288
  • 365
  • 5
  • 24
0

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.

Trixx
  • 1,796
  • 1
  • 15
  • 18