HCM Program Custom development Background program

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

  • SU10 User Mass Maintenance. Locks users in bulk; does not know which user belongs to a leaving employee.
  • PA40 Personnel Actions. Records the leaving action; does not lock the SAP user.

Tables used

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

TableRoleAccessSystem
PA0000HR Master Record: Infotype 0000 (Actions)Leaving action and date (driving table)ReadECC + S/4
PA0001HR Master Record: Infotype 0001 (Organizational Assignment)Name and company codeReadECC + S/4
PA0105HR Master Record: Infotype 0105 (Communications)Subtype 0001: the employee's SAP user nameReadECC + S/4
USR02User Logon DataUser type, lock status, validity and last logon (updated via BAPI)ReadECC + 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

ParameterDescriptionTypeReference fieldRequiredExample
S_MASSNLeaving action typesRange / multiplePA0000-MASSNYes10
P_DAYSLook-back window (days)Single value—No7
S_BUKRSCompany codeRange / multiplePA0001-BUKRSNo1000
S_USTYPUser types to processRange / multipleUSR02-USTYPNoA
P_FUTURESet validity end for future-dated leaversCheckbox—NoX
P_MAILResult email address or distribution listSingle value—No[email protected]
P_TESTTest mode (list without locking)Checkbox—NoX

Result list columns

#ColumnSource
1Personnel no.PA0000-PERNR
2NamePA0001-ENAME
3Action typePA0000-MASSN
4Leaving datePA0000-BEGDA
5SAP userPA0105-USRID
6User typeUSR02-USTYP
7Last logonUSR02-TRDAT
8Previous lock statusUSR02-UFLAG
9New validity endUSR02-GLTGB
10ResultCalculated Locked, already locked, validity set, no user or error
11MessageCalculated Return message from BAPI_USER_LOCK / BAPI_USER_CHANGE

Sample result list

Personnel no.NameAction typeLeaving dateSAP userUser typeLast logonPrevious lock statusNew validity endResultMessage
00009874Hakan Sarıgöl1011/15/2026HSARIGOLA11/14/2026011/15/2026LockedUser HSARIGOL locked
00011452Nihan Yöndemli1011/30/2026NYONDEMLIA11/16/2026011/30/2026Validity setLeaving date in the future; validity set to 30.11.2026
00010388Oğuz Kalender1011/12/2026No userNo infotype 0105 subtype 0001 record found
A view built with fictional sample data; not real system data.

How does the program work?

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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

BASIS Package Custom

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, …

6 components · v1.0

Related reports

HCM Report Custom ALV report

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 …

PA0000 · PA0001 · T529T · T527X

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 SAP User Lock Job for Leaving Employees