Requires Free Membership to View
When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.
Hannah Smalltree, Editorial DirectorAnyway, 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.
|
||||
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:
set handler zcl_myclass=>tx_finished.
In my ABAP class, I define the Static Handler method tx_finished. This method, when triggered, calls additional processing for the maintenance of Characteristics.
class zcl_myclass definition.
public section.
Class-methods: tx_finished for event transaction_finished
of cl_system_transaction_state
importing kind, ...
" further methods for handling the Singleton and the application
endclass. " z_clmyclass DEFINITION
class zcl_myclass implementation.
method tx_finished.
" Switch off the handler
set handler post_commit_handler=>trans_finished activation false.
" check value of importing parameter "kind"
if kind ne cl_system_transaction_state=>commit_work. " successful commit
exit.
endif.
" do the additional application processing using the singleton
zcl_myclass=>r_singleton->maintain_chars( ).
endmethod. " tx_finished
" implementation of remaining methods
endclass. " z_clmyclass IMPLEMENTATION
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. This was first published in October 2009