# Automatic Lock of Inactive Users Program

> 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.

- Type: Program, Custom development, Background program
- Module: BASIS
- Estimated effort: S (3–4 working days)
- Last updated: 2026-11-17
- URL: https://nekuhub.com/en/programs/automatic-inactive-user-lock-program/


## 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.

### Closest standard alternatives

- SU10: Locks users in bulk; no automatic selection by inactivity, no warning email and no exclusion list.
- SUIM: Lists inactive users; it does not lock them.

## Tables used

| Table | Role | Access | Join | System |
|---|---|---|---|---|
| USR02 | User type, group, last logon and lock status; lock and validity are written through the BAPIs | Write | - | ECC + S/4 |
| USR21 | Person and address number of the user | Read | USR21-BNAME = USR02-BNAME | ECC + S/4 |
| ADR6 | Email address of the user for the warning | Read | ADR6-ADDRNUMBER = USR21-ADDRNUMBER AND ADR6-PERSNUMBER = USR21-PERSNUMBER | ECC + S/4 |
| AGR_USERS | Number of roles of the locked user (for the summary email) | Read | AGR_USERS-UNAME = USR02-BNAME | ECC + S/4 |

## BAPIs and functions used

- BAPI_USER_LOCK: Locks a user above the threshold with an administrator lock
- BAPI_USER_CHANGE: Optionally sets the validity end (GLTGB) to today
- SO_NEW_DOCUMENT_ATT_SEND_API1: Sends the warning to the user and the summary to the security team

## Selection screen parameters

| Parameter | Description | Type | Reference field | Required |
|---|---|---|---|---|
| S_UNAME | User (including exclusions) | Range / multiple | USR02-BNAME | No |
| S_CLASS | User group (exclude: technical, emergency) | Range / multiple | USR02-CLASS | No |
| S_USTYP | User type | Range / multiple | USR02-USTYP | No |
| P_DAYS | Lock threshold (days) | Single value | - | Yes |
| P_NEVER | Threshold for users who never logged on (days) | Single value | - | No |
| P_WARN | Warning before lock (days) | Single value | - | No |
| P_VALID | Set validity end to today | Checkbox | - | No |
| P_MAIL | Summary email recipient | Single value | - | No |
| P_TEST | Test mode (list without locking) | Checkbox | - | No |

## Result list columns

| Column | Source |
|---|---|
| User | USR02-BNAME |
| User group | USR02-CLASS |
| Last logon | USR02-TRDAT |
| Inactive days | Calculated: Today − USR02-TRDAT (no logon: − USR02-ERDAT) |
| Email | ADR6-SMTP_ADDR |
| Roles | Calculated: Number of valid AGR_USERS entries |
| Action | Calculated: Warned, locked, skipped (exclusion) or test |
| Message | Calculated: BAPI return message or email send result |

## How does the program work?

1. 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.
2. Inactive days = today − last logon date (TRDAT); for users who never logged on, the creation date (ERDAT) is used with a separate threshold.
3. 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.
4. 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.
5. In test mode no BAPI is called and no email is sent; only the candidate list is produced.
6. The result per user is written to the application log; a summary of locked and warned users is emailed to the security team.

## Authorization objects

- S_USER_GRP: Lock (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.

---
Let us build this program for your system: https://nekuhub.com/en/request-a-quote/?report=basis-inactive-user-auto-lock-job
