2

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?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
user3463645
  • 126
  • 1
  • 10

2 Answers2

5

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.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • This is z program and I can't allow two users to acess the same document at the same time. So I change the flag in table immedietly after someone opens the document and this way doc. won't be visible for other users. That's why I cannot wait to the end of transaction to update table, becaouse someone else could open this document in the meantime. – user3463645 Sep 28 '18 at 10:55
  • @user3463645 Your point is different from the initial question. Please ask it as a new question so that people can answer. – Sandra Rossi Sep 28 '18 at 11:28
  • No, this is the same problem. I set the flag at the beginning of program to block document from other users. But when someone exits transaction by closing the window, the flag is not geting reversed and the document is not visible for anyone. – user3463645 Sep 28 '18 at 11:32
  • Your initial question is about how to react when the close button is pressed. There's absolutely no mention of concurrent users (you just mention "updating field X in table tab1", whose goal is not explained). Although your issue is clear to you, the words you used in your question are not sufficient to understand your real problem. – Sandra Rossi Sep 28 '18 at 12:37
  • I get your point, It may sound confusing. The goal is to restring access to document for only one user, and I did it by updating flag in the table and checking the value of the flag on the beggining of execution. However it doens't work when user closes window with application (flag is not reversed), that's why I asked how to do it. – user3463645 Sep 28 '18 at 16:19
  • 1
    So, to stick to your real case, you should just lock/unlock by using the SAP Lock objects, no need to have a dedicated column in the table, no need to update the table, no need to create a recovery program. – Sandra Rossi Sep 28 '18 at 17:43
0

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.

mkysoft
  • 5,392
  • 1
  • 21
  • 30
  • Thanks, these are really good suggestions and I probably will go with 2 or 3 option, as there is probably no mechanizm like even before program exit. – user3463645 Sep 28 '18 at 07:45
  • If user connection lost, there is no way to trigger something on user client. On server side, I think you need to add a lot of code to user exits (user logout, program dump, session timeout, user kick, etc) if exist. I prefer change your application flow for fitting lock mechanism. – mkysoft Sep 28 '18 at 08:26
  • Dynpro applications should update the database at the end, when the user saves. I describe more in details in a separate answer. The locking mechanism, the way it's described here, should not be the first answer to this general question. – Sandra Rossi Sep 28 '18 at 08:50