Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Transaction Rollback not working

Hi,

In the AP Invoice Before Add event (Event = FormDataEvent, Event Type = Add or Update, Before Action = True), I am starting a transaction.

Then in After Add event, I am deliberately creating a null pointer exception (to test rollback), and in the exception handler, I am rolling back the transaction.

  1. void SBO_Application_FormDataEvent(ref SAPbouiCOM.BusinessObjectInfo BusinessObjectInfo, out bool BubbleEvent) 
  2.     BubbleEvent = true; 
  3.     if (BusinessObjectInfo.FormTypeEx == "141" 
  4.         && (BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD || BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE) 
  5.         && BusinessObjectInfo.BeforeAction == true) 
  6.     { 
  7.         oCompany.StartTransaction(); 
  8.     } 
  9.     if (BusinessObjectInfo.FormTypeEx == "141" 
  10.         && (BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_ADD || BusinessObjectInfo.EventType == SAPbouiCOM.BoEventTypes.et_FORM_DATA_UPDATE) 
  11.         && BusinessObjectInfo.BeforeAction == false) 
  12.     { 
  13.         if (BusinessObjectInfo.ActionSuccess) 
  14.         { 
  15.             try 
  16.             { 
  17.                 string nullStr = null
  18.                 nullStr.Contains("ABCD"); 
  19.                 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit); 
  20.             } 
  21.             catch (Exception ex) 
  22.             { 
  23.                 oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack); 
  24.                 MessageBox.Show(ex.Message); 
  25.             } 
  26.         } 
  27.     } 

Still the AP Invoice gets saved in the database. What may be the issue?

Thanks.

I am trying this on 9.1 PL 00.

Can other experts try this code and let me know if they get similar results?

A lot of threads in this forum mention that starting a global transaction in the Before Action, and rolling back in the After Action is treated as a single transaction and should therefore work.

But some thread also suggests that it will not work.

This is urgent.

Not what you were looking for? View more on this topic or Ask a question