Automatic SAP User Lock Job for Leaving Employees
Short answer: A background job that, on the leaving date, automatically locks the SAP users stored in infotype 0105 for employees with a recorded leaving action and sets the user's validity end to the leaving date. Locked users and leavers without a user found are reported to the security team by email.
- Estimated effort
- M · 5–8 working days
- System
- ECC and S/4HANA
- Tables
- 4
- Scope
- Global
- Built by
- NeKuDos Teknoloji
- Last updated
Why is the standard not enough?
The PA40 leaving action updates HR records but does not touch the SAP user; SU10 locks users in bulk but does not know which users belong to leaving employees. When locking is done by hand from HR emails it is delayed, and audits report "active user of a leaver" findings.
Who uses it? SAP security administrators, HR operations teams, IT audit and compliance units.
Closest standard alternatives
Tables used
The tables the program reads and updates. ECC and S/4HANA differences are marked separately.
| Table | Role | Access | System |
|---|---|---|---|
| PA0000HR Master Record: Infotype 0000 (Actions) | Leaving action and date (driving table) | Read | ECC + S/4 |
| PA0001HR Master Record: Infotype 0001 (Organizational Assignment) | Name and company code | Read | ECC + S/4 |
| PA0105HR Master Record: Infotype 0105 (Communications) | Subtype 0001: the employee's SAP user name | Read | ECC + S/4 |
| USR02User Logon Data | User type, lock status, validity and last logon (updated via BAPI) | Read | ECC + S/4 |
BAPIs and functions used
- BAPI_USER_LOCKLock User. Locks the leaving employee's user
- BAPI_USER_CHANGEChange User. Sets the user's validity end to the leaving date
- SO_DOCUMENT_SEND_API1SAPoffice: Send Document with Attachments. Emails the result list to the security team
Selection screen parameters
| Parameter | Description | Type | Reference field | Required | Example |
|---|---|---|---|---|---|
| S_MASSN | Leaving action types | Range / multiple | PA0000-MASSN | Yes | 10 |
| P_DAYS | Look-back window (days) | Single value | — | No | 7 |
| S_BUKRS | Company code | Range / multiple | PA0001-BUKRS | No | 1000 |
| S_USTYP | User types to process | Range / multiple | USR02-USTYP | No | A |
| P_FUTURE | Set validity end for future-dated leavers | Checkbox | — | No | X |
| P_MAIL | Result email address or distribution list | Single value | — | No | [email protected] |
| P_TEST | Test mode (list without locking) | Checkbox | — | No | X |
Result list columns
| # | Column | Source |
|---|---|---|
| 1 | Personnel no. | PA0000-PERNR |
| 2 | Name | PA0001-ENAME |
| 3 | Action type | PA0000-MASSN |
| 4 | Leaving date | PA0000-BEGDA |
| 5 | SAP user | PA0105-USRID |
| 6 | User type | USR02-USTYP |
| 7 | Last logon | USR02-TRDAT |
| 8 | Previous lock status | USR02-UFLAG |
| 9 | New validity end | USR02-GLTGB |
| 10 | Result | Calculated Locked, already locked, validity set, no user or error |
| 11 | Message | Calculated Return message from BAPI_USER_LOCK / BAPI_USER_CHANGE |
Sample result list
| Personnel no. | Name | Action type | Leaving date | SAP user | User type | Last logon | Previous lock status | New validity end | Result | Message |
|---|---|---|---|---|---|---|---|---|---|---|
| 00009874 | Hakan Sarıgöl | 10 | 11/15/2026 | HSARIGOL | A | 11/14/2026 | 0 | 11/15/2026 | Locked | User HSARIGOL locked |
| 00011452 | Nihan Yöndemli | 10 | 11/30/2026 | NYONDEMLI | A | 11/16/2026 | 0 | 11/30/2026 | Validity set | Leaving date in the future; validity set to 30.11.2026 |
| 00010388 | Oğuz Kalender | 10 | 11/12/2026 | No user | No infotype 0105 subtype 0001 record found |
How does the program work?
- Records with employment status left (STAT2 = 0) for the selected leaving action types (MASSN) and a start date in the selected window (e.g. today and the last 7 days) are read from PA0000; leaving date = start date of the record.
- Name and company code come from PA0001, and the subtype 0001 (SAP system user) record from PA0105, taken from the last record valid before the leaving date.
- User type, current lock status (UFLAG), validity end and last logon date are read from USR02; service and system users are skipped depending on the selection screen.
- When the leaving date has been reached, the user is locked with BAPI_USER_LOCK and the validity end is set to the leaving date with BAPI_USER_CHANGE. When the leaving date is in the future, only the validity end is set.
- In test mode nothing is changed. Results are written to the log, and the list of locked, already locked and user-not-found employees is emailed to the security team.
Performance notes
The job is designed to run once or twice a day and reads only leaving records in the window; volume is small. With central user administration (CUA), the lock is applied in the central system and distributed to child systems; this is checked at installation.
Features
- Runs as a background job Scheduled as a nightly job.
- Test mode (check without posting)
- Line-by-line result and error log
- Send the result by email The result list is sent to the security team after every run.
- ALV list (sort, filter, subtotals)
Authorization objects
- P_ORGINRead authorization for infotypes 0000, 0001 and 0105 (job user)
- S_USER_GRPLock and change authorization by user group (job user)
Frequently asked questions
Why is the user only locked, not deleted?
Locking and a validity end keep the audit trail: the user's past transactions and change documents stay visible under the user name. Deletion should be a separate process after the retention period ends.
What if the employee is rehired on the same day?
If the job finds a valid hiring or rehire action after the leaving record, it does not lock the user and shows the case as a warning in the log.
What if there are several SAP systems?
With central user administration, the lock is applied in the central system and distributed to the others. Without it, the job can be extended to call the same BAPIs in each system over a remote connection; this increases the effort range.
Packages that include this solution
SAP Access and Payment Risk Audit Pack
A six-component pack that brings together the controls asked most often in the yearly IT and finance audit: users with critical authorizations, …
Related reports
Employee to Business Partner and Vendor Link Check Report (S/4HANA Readiness)
A report that checks for every employee the business partner link required in S/4HANA (central person and business partner relationship, personnel …
Headcount Movement and Turnover Report by Department
A custom ALV report that gives, for the selected period and per organizational unit, opening headcount, hires, transfers between units, voluntary and …
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.