Automatic Lock of Inactive Users Program
Short answer: A custom background program that first warns dialog users who have not logged on for a given period by email, locks them with an administrator lock when the period is over and optionally sets their validity end to today. Emergency and technical users are excluded, and the result of each run is sent to the security team as a summary.
- Estimated effort
- S · 3–4 working days
- System
- ECC and S/4HANA
- Tables
- 4
- Scope
- Global
- Built by
- NeKuDos Teknoloji
- Last updated
Why is the standard not enough?
SU10 can lock users in bulk, but someone has to choose who gets locked; there is no automatic selection by last logon, no warning email in advance and no exclusion list. Logon rules set through profile parameters only govern password and logon behavior; they do not lock inactive users in an audit-friendly way. The audit question "are users inactive for 90 days locked?" is therefore answered manually in most companies.
Who uses it? SAP authorization administrators, IT security teams and internal audit responsible for user lifecycle controls.
Closest standard alternatives
Tables used
The tables the program reads and updates. ECC and S/4HANA differences are marked separately.
| Table | Role | Access | System |
|---|---|---|---|
| USR02User Logon Data | User type, group, last logon and lock status; lock and validity are written through the BAPIs | Write | ECC + S/4 |
| USR21User Name to Address Key Assignment | Person and address number of the user | Read | ECC + S/4 |
| ADR6E-Mail Addresses (Business Address Services) | Email address of the user for the warning | Read | ECC + S/4 |
| AGR_USERSAssignment of Roles to Users | Number of roles of the locked user (for the summary email) | Read | ECC + S/4 |
BAPIs and functions used
- BAPI_USER_LOCKLock User. Locks a user above the threshold with an administrator lock
- BAPI_USER_CHANGEChange User. Optionally sets the validity end (GLTGB) to today
- SO_NEW_DOCUMENT_ATT_SEND_API1SAPoffice: Send New Document with Attachments. Sends the warning to the user and the summary to the security team
Selection screen parameters
| Parameter | Description | Type | Reference field | Required | Example |
|---|---|---|---|---|---|
| S_UNAME | User (including exclusions) | Range / multiple | USR02-BNAME | No | * hariç FIREFIGHTER* |
| S_CLASS | User group (exclude: technical, emergency) | Range / multiple | USR02-CLASS | No | ≠ SUPER, EMERG |
| S_USTYP | User type | Range / multiple | USR02-USTYP | No | A |
| P_DAYS | Lock threshold (days) | Single value | — | Yes | 90 |
| P_NEVER | Threshold for users who never logged on (days) | Single value | — | No | 30 |
| P_WARN | Warning before lock (days) | Single value | — | No | 7 |
| P_VALID | Set validity end to today | Checkbox | — | No | — |
| P_MAIL | Summary email recipient | Single value | — | No | [email protected] |
| P_TEST | Test mode (list without locking) | Checkbox | — | No | X |
Result list columns
| # | Column | Source |
|---|---|---|
| 1 | User | USR02-BNAME |
| 2 | User group | USR02-CLASS |
| 3 | Last logon | USR02-TRDAT |
| 4 | Inactive days | Calculated Today − USR02-TRDAT (no logon: − USR02-ERDAT) |
| 5 | ADR6-SMTP_ADDR | |
| 6 | Roles | Calculated Number of valid AGR_USERS entries |
| 7 | Action | Calculated Warned, locked, skipped (exclusion) or test |
| 8 | Message | Calculated BAPI return message or email send result |
Sample result list
| User | User group | Last logon | Inactive days | Roles | Action | Message | |
|---|---|---|---|---|---|---|---|
| SOZTURK | PUR | 06/02/2026 | 168 | [email protected] | 7 | Locked | User SOZTURK locked |
| TAYDIN | LOG | 08/21/2026 | 88 | [email protected] | 3 | Warned | Warning email sent |
| CKOC | FIN | 41 | [email protected] | 3 | Locked | Never logged on; user locked | |
| FIREFIGHTER01 | EMERG | 03/10/2026 | 252 | 1 | Skipped | Excluded user group |
How does the program work?
- Dialog users (USTYP = A) in the selection are read from USR02; locked users (UFLAG ≠ 0), excluded user groups (CLASS) and the exclusion list of users are skipped.
- Inactive days = today − last logon date (TRDAT); for users who never logged on, the creation date (ERDAT) is used with a separate threshold.
- Warning stage: users whose inactive days reach the lock threshold minus the warning days receive an information email at the address from USR21 and ADR6, sent with SO_NEW_DOCUMENT_ATT_SEND_API1.
- Lock stage: for users above the threshold, BAPI_USER_LOCK is called (administrator lock). With “Set validity end” selected, LOGONDATA-GLTGB is set to today through BAPI_USER_CHANGE. The program never touches passwords or password fields.
- In test mode no BAPI is called and no email is sent; only the candidate list is produced.
- The result per user is written to the application log; a summary of locked and warned users is emailed to the security team.
Performance notes
Run the program every night as a background job. Even with several thousand users the USR02 read is fast; send the emails in one batch at the end of the run rather than one by one.
Features
- Runs as a background job
- Test mode (check without posting)
- Line-by-line result and error log
- Send the result by email Users receive a warning and the security team receives a run summary.
- ALV list (sort, filter, subtotals)
Authorization objects
- S_USER_GRPLock (activity 05) and change authorization by user group; granted to the background user
Frequently asked questions
Does the program change or read passwords?
No. The program only sets a lock with BAPI_USER_LOCK and optionally changes the validity end with BAPI_USER_CHANGE. Passwords, password hashes or password change data are neither read nor written.
How is a locked user unlocked again?
The administrator lock is removed in SU01 or SU10. When the user logs on again, the last logon date is updated and the counter starts from zero.
Are RFC and background users affected?
The default selection only takes dialog users (type A). System, communication and service users are not locked unless they are added to the selection; emergency users are excluded by user group.
Related reports
Segregation of Duties (SoD) Conflict Report by User
A custom ALV report that lists users who can run conflicting activities together (for example changing vendor master data and running the payment …
User License Type and Last Logon Report (Inactive Users)
A custom ALV report that shows each user's license type, last logon date, number of valid roles and department in one list. Users who have not logged …
Let us build this program for your system
Briefly describe your system and expectations. We will clarify the scope and come back with an effort and price quote.