{"audience":"SAP security administrators, HR operations teams, IT audit and compliance units.","authorization_objects":[{"note":"Read authorization for infotypes 0000, 0001 and 0105 (job user)","object":"P_ORGIN"},{"note":"Lock and change authorization by user group (job user)","object":"S_USER_GRP"}],"components":[],"countries":[],"effort_days_max":8,"effort_days_min":5,"effort_size":"M","faq":[{"a":"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.","q":"Why is the user only locked, not deleted?"},{"a":"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.","q":"What if the employee is rehired on the same day?"},{"a":"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.","q":"What if there are several SAP systems?"}],"features":[{"code":"background","label":"Runs as a background job","note":"Scheduled as a nightly job."},{"code":"test_run","label":"Test mode (check without posting)","note":""},{"code":"log","label":"Line-by-line result and error log","note":""},{"code":"email","label":"Send the result by email","note":"The result list is sent to the security team after every run."},{"code":"alv","label":"ALV list (sort, filter, subtotals)","note":""}],"functions":[{"name":"BAPI_USER_LOCK","role":"Locks the leaving employee's user"},{"name":"BAPI_USER_CHANGE","role":"Sets the user's validity end to the leaving date"},{"name":"SO_DOCUMENT_SEND_API1","role":"Emails the result list to the security team"}],"gap":"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.","id":"hcm-leaver-sap-user-lock-job","industries":[],"input_columns":[],"kind":"program","language":"en","lastmod":"2026-11-17","logic":"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.\n2. 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.\n3. 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.\n4. 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.\n5. 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.","module":"HCM","object_type":"batch_job","output_columns":[{"calculated":false,"formula":"","label":"Personnel no.","source_field":"PERNR","source_table":"PA0000"},{"calculated":false,"formula":"","label":"Name","source_field":"ENAME","source_table":"PA0001"},{"calculated":false,"formula":"","label":"Action type","source_field":"MASSN","source_table":"PA0000"},{"calculated":false,"formula":"","label":"Leaving date","source_field":"BEGDA","source_table":"PA0000"},{"calculated":false,"formula":"","label":"SAP user","source_field":"USRID","source_table":"PA0105"},{"calculated":false,"formula":"","label":"User type","source_field":"USTYP","source_table":"USR02"},{"calculated":false,"formula":"","label":"Last logon","source_field":"TRDAT","source_table":"USR02"},{"calculated":false,"formula":"","label":"Previous lock status","source_field":"UFLAG","source_table":"USR02"},{"calculated":false,"formula":"","label":"New validity end","source_field":"GLTGB","source_table":"USR02"},{"calculated":true,"formula":"Locked, already locked, validity set, no user or error","label":"Result","source_field":null,"source_table":null},{"calculated":true,"formula":"Return message from BAPI_USER_LOCK / BAPI_USER_CHANGE","label":"Message","source_field":null,"source_table":null}],"parameters":[{"example":"10","kind":"select_option","label":"Leaving action types","name":"S_MASSN","ref_field":"PA0000-MASSN","required":true},{"example":"7","kind":"parameter","label":"Look-back window (days)","name":"P_DAYS","ref_field":"","required":false},{"example":"1000","kind":"select_option","label":"Company code","name":"S_BUKRS","ref_field":"PA0001-BUKRS","required":false},{"example":"A","kind":"select_option","label":"User types to process","name":"S_USTYP","ref_field":"USR02-USTYP","required":false},{"example":"X","kind":"checkbox","label":"Set validity end for future-dated leavers","name":"P_FUTURE","ref_field":"","required":false},{"example":"sap-guvenlik@ornek.com.tr","kind":"parameter","label":"Result email address or distribution list","name":"P_MAIL","ref_field":"","required":false},{"example":"X","kind":"checkbox","label":"Test mode (list without locking)","name":"P_TEST","ref_field":"","required":false}],"part_of":["basis-audit-compliance-pack"],"performance":"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.","quote_url":"https://nekuhub.com/en/request-a-quote/?report=hcm-leaver-sap-user-lock-job","related":["hcm-employee-business-partner-link-check","hcm-headcount-movement-turnover"],"releases":[],"source":"custom","standard_alternatives":[{"note":"Locks users in bulk; does not know which user belongs to a leaving employee.","tcode":"SU10"},{"note":"Records the leaving action; does not lock the SAP user.","tcode":"PA40"}],"summary":"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.","tables":[{"access":"read","join_on":"","role":"Leaving action and date (driving table)","table":"PA0000","variant":"both"},{"access":"read","join_on":"PA0001-PERNR = PA0000-PERNR","role":"Name and company code","table":"PA0001","variant":"both"},{"access":"read","join_on":"PA0105-PERNR = PA0000-PERNR AND PA0105-SUBTY = '0001'","role":"Subtype 0001: the employee's SAP user name","table":"PA0105","variant":"both"},{"access":"read","join_on":"USR02-BNAME = PA0105-USRID","role":"User type, lock status, validity and last logon (updated via BAPI)","table":"USR02","variant":"both"}],"title":"Automatic SAP User Lock Job for Leaving Employees","url":"https://nekuhub.com/en/programs/lock-sap-users-of-leaving-employees-automatically/","vendor_id":"nekudos"}