Recently I needed a program that would display a screen for maintaining Characteristics and Classifications following an SAP COMMIT WORK statement when maintaining a few master data objects, i.e., after the "save" processing when the object is changed or created.
Anyway, I came across a not very well-known technique which helped me solve this real-life programming problem rather neatly. I won't go into the details of the application. What I want to focus on is how to have an action triggered following a successful COMMIT WORK in an SAP transaction.
For my master data object, there is an SAP BADI which runs immediately following a save, but before the COMMIT WORK. There I called a Static Factory Method, in an SAP ABAP class I had developed (ZCL_MYCLASS), which follows the Singleton pattern.
The master data fields I needed for my application, were passed in the parameters of this method, and set in the attributes of the Singleton instance. (You could use global variables in a Function Group with a few Function Modules to achieve the same results.) The last line of ABAP within the BADI is:
In my ABAP class, I define the Static Handler method tx_finished. This method, when triggered, calls additional processing for the maintenance of Characteristics...
To continue reading for free, register below or login
To read more you must become a member of SearchSAP.com
');
// -->

.
Following all the processing involved within COMMIT -- or ROLLBACK -- the system event CL_SYSTEM_TRANSACTION_STATE=>TRANSACTION_FINISHED is raised, which triggers any handler methods for that event. All of this happens within one session, so there is no danger of interference from other processes on the system.
To summarize: In the BADI, I pass relevant data to my class, and set a handler. Following the COMMIT WORK, the handler method runs in the same dialog task and the same memory space, launching my "post save" functionality, which can involve further screens and interaction with the user.
About the creator of this tip: Matthew Billingham is SearchSAP.com's application development expert. He has worked for companies such as Eurotunnel and Vodafone, served as development manager for Coats PLc, and as head of application development with Novartis Pharma in Switzerland, managing the development side of a global SAP rollout. He now runs his own SAP consultancy, providing guidance and designing solutions (particularly for intractable problems) for third parties. His expertise is in program design, troubleshooting and knowing just how SAP works; his clients describe him as "Consultant for everything." He is co-founder of SecureBI, delivering SAP security solutions.