2
votes

in my ABAP program I'm updating field X in table tab1 at the beginning and in the last step if everything goes OK, I'm reversing this update. It's important that during execution of program the field X has correct value.

However when I exit the transaction with close button not SAP cancel button (F12), program terminates and it doesn't go to the end of program, thus not reversing the update made at the beginning.

enter image description here

Is there a way that I can execute some code after closing the report?

2

2 Answers

5
votes

The "close window" button cannot be controlled by program (this is true for the "external modes" i.e. the full-screen windows, which seems to be your question, but not for the popups, whose close button can be controlled).

Because of that, SAP programmed its Dynpro applications this way:

  • SAP update the database at the end of the whole application, when you save
  • and eventually, if some parts of the screens are handled by "external" applications SAP record intermediate updates via the "update task" (i.e. they are delayed until the COMMIT WORK is done at the end of the application). Note that SAP also frequently use the update task at the end only, but it's only for getting a better dialog response time.

Custom applications should follow the same principle.

0
votes

I think you are trying to add lock mechanism. ABAP has own lock mechanism for objects. If user logout, close report or session terminated, system automatically unlocking it. I prefer use locking mechanism, example.

If you working different scenario; add new column for user and lock time to same table, and check user is online, otherwise remove lock.

If you want to not remove lock with user action, you can start new background job for 5 minutes with updating record. This job can check user and record, if user logout from report (t-code SM04), job removing record, otherwise reschedule it self.