cancel
Showing results for 
Search instead for 
Did you mean: 

Lock users out of the system with a SQL server 2005 script

Former Member
0 Kudos

I need to lock users out of the system before I start up SAP. If the below script unlocks users can someone tell me how to lock all users?

update <sid>.USR02 set UFLAG=0 where BNAME='users' and MANDT=<client number>

And with an exception to keep some users unlocked.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Chris,

I would suggest you to first lock all users and then unlock the needed users;

To lock:

update <sid>.USR02 set UFLAG=128 where BNAME='users' and MANDT=<client number>

The above query will lock all users, then run a separate query to unlock the BASIS or required users.

You can put both the queries in a script.

Regards,

SBK

Former Member
0 Kudos

So if I want to lock all users I just have to enter BNAME='users' and if I want to unlock an individual I enter there username in BNAME='csoden' for example?

update <sid>.USR02 set UFLAG=128 where BNAME='users' and MANDT=<client number>

I found this somewhere else can someone confirm its correct for me-

0 Not Locked

32 Locked Globally By Administrator

64 Locked Locally By Administrator

128 Locked Due To Incorrect Logons (Limited Term)

Former Member
0 Kudos

Thanks for your help

To lock or unlock users:-

To lock individual users-

update <sid>.USR02 set UFLAG=64 where BNAME='USERNAME' and MANDT=<CLIENT NUMBER>

To lock all users-

update <sid>.USR02 set UFLAG=64 where MANDT=<CLIENT NUMBER>

To unlock users change the UFLAG value to 0 in either script.

UFLAG values-

0 Not Locked

32 Locked Globally By Administrator

64 Locked Locally By Administrator

128 Locked Due To Incorrect Logons (Limited Term)

In some cases when running the script it will throw an error about sr1.USR02. This is either due to the SID/Schema needing to be in uppercase ie; SR1.USR02 or not being needed at all ie; USR02

Former Member
0 Kudos

Hi Chris,

Yes you are absolutely right. Lock all users by not including bname field in the query.

update <schema>.usr02 set uflag=64/128 where mandt='client no';

Then you can unlock individual users by setting uflag='0' and specifing the users in the bname field

update <schema>.usr02 set uflag=0 where bname ='DDIC' and mandt='client no';

Regards,

SBK