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.
Showing results for 
Search instead for 
Did you mean: 

Close session in ABAP Program Control

Former Member
0 Kudos

Hi all,

To avoid the users can run some transactions during the batch window, we have developed an ABAP program to lock these transactions before the start of batch period in background mode. After batch window we unlock it.

The problem is that the users that are in transactions before the lock process is execute, can use use without problem. Therefore we need to close all sessions that are in these transactions in background mode near the lock proccess.

Any idea?

Thanks a lot.


Active Contributor
0 Kudos

Hi Filipe,

I saw several times customers use SM04 in batch input, or use TH_WPINFO + TH_DELETE_USER (to be run on each application server).



0 Kudos

We do something like this in month ends.

Rough logic for you.

Use AL08, find all users on all servers.

Send Mail to them, asking to log off.

After delay,

Loop thru App Servers,

log users out

Load message in SM01.


Does this help you?

Active Contributor
0 Kudos

It seems that deleting single foreign modes (as opposed to a full logoff) under program control is not possible, there is no appropriate task handler function module and debugging SM04 does not reveal how SAP does it:

I would assume a "secret" combination of parameters for the 'ThUsrInfo' call might do it.

Please let us know once you found the formula.


0 Kudos

Hi Thomas,

I guess what you call foreign modes are the external modes.

I don't know for ThUsrInfo, but there's a workaround : It's possible to do a batch input on SM04 and you are able to select the line(s) you want by adding a little trick to determine which external sessions run which transaction codes :

1) duplicate dynpro rsm04000_alv 2000 (the one which displays the external modes) into a Z dynpro, and inside the PBO step loop, save MODUS table work area (that you declare with TABLES), it contains first 36 characters of transaction code texts (as what you see with SM04).

2) fill out "TID" SET/GET parameter with the "Terminal ID" corresponding to the user session (you get it from the additional fields in the SM04 list of user sessions).

3) call the screen a first time with SUPPRESS DIALOG so that to determine which line(s) correspond to which transaction codes

4) call the screen in batch input mode without SUPPRESS DIALOG and with a SET CURSOR with the line determined previously and delete the mode

Note that you have to create 2 programs (one which prepares the BDC data, the other which calls the screen) and a dummy transaction (for the batch input, so that to call the second program) so that everything works.


0 Kudos

Many thanks for sharing this.

With foreign modes I meant those by users other than the logged on user. There are (all unreleased) TH-functions for logging off others users completely, for creating a new mode for other users, for deleting modes of the logged on user, but there is none for deleting certain modes of other users, for whatever reason. SAP decided to hide that part of the SM04 functionality (screen 2000) in SYST-* modules that are implemented in the kernel, as far as I know.

Maybe Felipe can use your workaround though.


Former Member
0 Kudos

hello sir

you can close through sm35 there you can end it.

Former Member
0 Kudos


I have found the way to get all modes openned by an user with function TH_LONG_USR_INFO. The problem is that this function doesn't return the field TID of the mode and the input parameter for function TH_DELETE_USER is TID. I don't need to close all user modes, i need close only the modes of some transactions.

In may case the batch input is not really a good way, i need to do it in a ABAP Program.

Do you know how to close just one mode of an user with functions TH*?


0 Kudos

Do you know how to close just one mode of an user with functions TH*?

There's no TH_* for that

Former Member

I believe I have a solution for this. The following code will delete all the other sessions except the current one. I use it to clean up my desktop after a debugging session is done. It can easily be adapted to look for a specific t-code or even a specific user.

data: lv_mode like sy-tabix,
         lv_keep like sy-tabix,
         lv_time like sy-uzeit.

   data: lt_info like uinfo2 occurs 0 with header line.

   call function 'TH_LONG_USR_INFO'
       user_info = lt_info.

   delete lt_info where client <> sy-mandt.

   "Find the current mode by looking for the one with the latest time
   lv_time = '00:00:00'.
   loop at lt_info.
     if lt_info-time > lv_time.
       lv_keep = lt_info-mode.
       lv_time = lt_info-time.

   "SAP counts from 0 <- Important otherwise you accidentally delete the current mode
   lv_keep = lv_keep - 1.

   "delete all the other modes
   lv_mode = 7.
   do 7 times.
     lv_mode = lv_mode - 1.
     if lv_mode = lv_keep.

     call function 'TH_DELETE_MODE'
         mode = lv_mode.