Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to register to an AFTER_COMMIT event ?

Former Member
0 Kudos

Dear community members,

within a transactional framework, developped in ABAP-OO (SAP NM 7.0), I would like several methods, mainly clean-up methods, to run after a 'commit work' has been triggered. The transacational framework, however, does not trigger the 'commit work' itsself, but has to listen on the 'commit work' event and to execute the clean-up methods.

Does anybodya of you know, how such a 'listener' class could look, or how one could react on the 'COMMIT WORK'-event 'or even an 'AFTER COMMIT'-event in an ABAP-OO context?

Thanks and best regards

Stefan

4 REPLIES 4

matt
Active Contributor

Define a global class (or using your class, define methods):

class post_commit_handler definition.
  public section.
    class-methods trans_finished for event transaction_finished
    of cl_system_transaction_state
    importing kind.
endclass.                    "post_commit_handler DEFINITION

class post_commit_handler implementation.
  method trans_finished.
    set handler post_commit_handler=>trans_finished activation false.
    "  clean up
  endmethod.                    "trans_finished
endclass.                    "post_commit_handler IMPLEMENTATION

In the code just before you trigger the commit:

set handler post_commit_handler=>trans_finished.

matt

Former Member
0 Kudos

Thanks a lot

0 Kudos

Hi, i tried to use this approach to call functionality that does some side effects on the systems... (e.g: calling a BAPI).

The issue is that you cannot commit work inside the method implementation for the event 'transactions_finished'.

If you do, you get the following 'Dump':


The only solution I found is to 'wait up to...' in order to achieve an implicit commit and persist the functionality called in the method.

What do you think about this approach? Can you recommend a better solution?

Thank you

matt
Active Contributor

Create a function module to do the work. Set it so that it runs in the update task - V2. Call it from your method. CALL FUNCTION ... IN UPDATE TASK.

Alternatively, mark it as RFC enabled, and call it from your method as CALL FUNCTION ... STARTING NEW TASK.