Old news: save to database regardless of rollback
Perform on rollback
If you know “perform on rollback”, stop reading. But I experienced that a lot of people do not know about “perform on rollback”
The situation was that I had to add some functionality to a process which “provides” me with a rollback, but I had to store the information that I at least attempted to do something…so either change the complete framework or perform on rollback
Unfortunately perform-on-rollback can not have any parameters and therfore I did the following:
- create one class with a static class method which actually does what I want to be done: save data to dataase, e.g. CL_STORAGE=>SAVE and
- create one class method which provides the data to the SAVE method, e.g. CL_STORAGE=>SET_DATA.
- Also create a method which you have to call once to “register” the SAVE-method to be called regardless of the rollback/commit.
- Then create a form routine which calls the CL_STORAGE=>SAVE method and
- create one form routine which does the perform-on-rollback.
This will somehow look like:
*.form execute_regardless. perform store_my_data on ROLLBACK. perform store_my_data on COMMIT.endform.".*.FORM store_my_data. CL_STORAGE=>SAVE( ). CL_STORAGE=>CLEANUP( ).ENDFORM.".
And the class methods:
METHOD register. PERFORM execute_regardless IN PROGRAM blahblubb.ENDMETHOD.
You can imagine the rest…