BASIS Program Custom development Background program

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

  • SU10 User Mass Maintenance. Locks users in bulk; no automatic selection by inactivity, no warning email and no exclusion list.
  • SUIM User Information System. Lists inactive users; it does not lock them.

Tables used

The tables the program reads and updates. ECC and S/4HANA differences are marked separately.

TableRoleAccessSystem
USR02User Logon DataUser type, group, last logon and lock status; lock and validity are written through the BAPIsWriteECC + S/4
USR21User Name to Address Key AssignmentPerson and address number of the userReadECC + S/4
ADR6E-Mail Addresses (Business Address Services)Email address of the user for the warningReadECC + S/4
AGR_USERSAssignment of Roles to UsersNumber of roles of the locked user (for the summary email)ReadECC + 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

ParameterDescriptionTypeReference fieldRequiredExample
S_UNAMEUser (including exclusions)Range / multipleUSR02-BNAMENo* hariç FIREFIGHTER*
S_CLASSUser group (exclude: technical, emergency)Range / multipleUSR02-CLASSNo≠ SUPER, EMERG
S_USTYPUser typeRange / multipleUSR02-USTYPNoA
P_DAYSLock threshold (days)Single value—Yes90
P_NEVERThreshold for users who never logged on (days)Single value—No30
P_WARNWarning before lock (days)Single value—No7
P_VALIDSet validity end to todayCheckbox—No—
P_MAILSummary email recipientSingle value—No[email protected]
P_TESTTest mode (list without locking)Checkbox—NoX

Result list columns

#ColumnSource
1UserUSR02-BNAME
2User groupUSR02-CLASS
3Last logonUSR02-TRDAT
4Inactive daysCalculated Today − USR02-TRDAT (no logon: − USR02-ERDAT)
5EmailADR6-SMTP_ADDR
6RolesCalculated Number of valid AGR_USERS entries
7ActionCalculated Warned, locked, skipped (exclusion) or test
8MessageCalculated BAPI return message or email send result

Sample result list

UserUser groupLast logonInactive daysEmailRolesActionMessage
SOZTURKPUR06/02/2026168[email protected]7LockedUser SOZTURK locked
TAYDINLOG08/21/202688[email protected]3WarnedWarning email sent
CKOCFIN41[email protected]3LockedNever logged on; user locked
FIREFIGHTER01EMERG03/10/20262521SkippedExcluded user group
A view built with fictional sample data; not real system data.

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.

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

BASIS Report Custom ALV report

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 …

USR02 · AGR_USERS · AGR_1251 · TSTC

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.

Related report: Automatic Lock of Inactive Users Program