Dynamic actions and Approval for ESS personal information records
This blog applies to SAP Netweaver 7.0, SAP HR EHP3(EA-HR 603) and above. For more information, visit the link.
Summary
In the current Employee self service(ESS), when the personal information is updated by the employee, it directly updates the record in the database. There are some organizations, where they want to validate the employee record before they actually get updated in SAP HR infotypes. This blog explains you in detail how the empolyee record is created with the locked status and HR administrators will remove the lock after validating the data. With this solution, dynamic action could also be acheived which is missing in the standard ESS solution.
Introduction
We faced the requirement from the client that all the personal information created/updated by employee through ESS should be validated by HR administrator before the record is actually written to HR infotypes.
To cater this requirement, whenever the employee enters the data through Personal Data in ESS, the record is created in locked mode and a workflow is triggered to the HR administrator. When the HR administrator approves the request, PA30 transaction is displayed with employee data, allowing the approver to unlock the particular employee record.
This blog will explain about in updating the Family dependent info type(PA0021).
Lock the record created/updated from ESS
This is based on the De-Coupled Framework. To find more on this, refer the following link.
Below picture will explain you at the high level. BADI plays an important role in mapping the screen structure of ESS with infotype record structure.
Implement the BADI HRPAD00INFTYUI in R/3 system and perform the following changes.
In one of the interface method INPUT_CONVERSION, perform the above changes. I have classified the record based on the structure name. You can simply validate based on the infotype name available in the structure pnnnn. Field sprps is the key field in creating the lock to the infotype record.
While saving the infotype record in locked mode, in parallel it’s important to trigger the workflow to the HR administrator.
Triggering Workflow to the HR administrators
While saving the infotype records, SAP standard calls the events entered through SWEHR2 and SWEHR3 transaction. SWEHR2 has the standard events while you can configure the custom events using SWEHR3 transaction.
Below is the configuration for Address infotype in transaction SWEHR3.
The function module ‘ZHR_EVENT_RULES_PA0021’ plays an important role in triggering the workflow to the HR administrators.
Function module to trigger the workflow
ZHR_EVENT_RULES_PA0021 is the copy of the standard function module HR_EVENT_RULES_PA0021.
This function module has the parameters such as
AFTER_IMAGE – > Changed record.
BEFORE_IMAGE – > Old record.
I have created a custom business object(ZFAMILYINT) which is the subtype of the standard business object FAMILYINT and used the after image key to trigger the workflow.
Code to trigger the Workflow using the Function module
FUNCTION zhr_event_rules_pa0021.
*”——————————————————————–
*”*”Local Interface:
*” IMPORTING
*” VALUE(AFTER_IMAGE) LIKE PRELP STRUCTURE PRELP
*” VALUE(BEFORE_IMAGE) LIKE PRELP STRUCTURE PRELP
*” VALUE(BUSINESSOBJECT) LIKE SWOTBASDAT-OBJTYPE
*” VALUE(OPERATION) LIKE T779W-WFOPR
*” EXPORTING
*” VALUE(EVENT) LIKE SWETYPECOU-EVENT
*” TABLES
*” EVENTS_PER_OPERATION STRUCTURE EVENTPOPER OPTIONAL
*”——————————————————————–
DATA: lt_lock_return TYPE bapireturn1,
real_event LIKE swetypecou-event,
real_workflow_id LIKE swetypecou-rectype,
wi_id LIKE swelog-recid,
key TYPE sweinstcou-objkey,
event_cont TYPE TABLE OF swcont,
lv_old_param TYPE bapip0006l,
lv_new_param TYPE bapip0006l.
*Generate the key of the old record
DATA: key_of_record LIKE pakey,
entity LIKE pspar-tclas,
lv_pa_key LIKE pakey.
DATA businessobjectkey LIKE sweinstcou-objkey.
DATA addressempkey LIKE bapipakey.
*Check for the Operation
IF businessobject CS ‘FAMILYINT’.
ELSE.
EXIT.
ENDIF.
IF sy-tcode CS ‘PA’.
EXIT.
ENDIF.
MOVE-CORRESPONDING after_image-pskey TO lv_pa_key.
CALL FUNCTION ‘HR_ASSEMBLE_OBJECTKEY’
EXPORTING
businessobject = ‘ZFAMILYINT’ “businessobject
key_of_record = lv_pa_key
entity = ‘A’
IMPORTING
businessobjectkey = businessobjectkey
EXCEPTIONS
OTHERS = 1.
real_event = ‘CREATED’.
real_workflow_id = ‘WS90000216’.
CALL FUNCTION ‘SWW_WI_CREATE_VIA_EVENT’
EXPORTING
event = real_event
rectype = real_workflow_id
objtype = ‘ZFAMILYINT’
objkey = businessobjectkey
* EXCEPTIONS_ALLOWED = ‘ ‘
IMPORTING
rec_id = wi_id
TABLES
event_container = event_cont
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Workflow high level design
In the workflow part, I’ve covered only the essential part which is to display the PA30 transaction with the locked record to the HR administrators.
Overview of Workflow:
I have designed the workflow in such a way that once the workflow is triggered, the workitem has to go to the Initiator of the workflow thus enabling the initiator to attach the documents required for the approval for his changed information in ESS.
In the next step of the workflow, I have launched the custom transaction that will have the following information in the workitem.
The approver will see the workitem with the following information.
Once they click the approve button, it will launch the PA30 transaction in change mode for the particular employee record. In the description area of the workitem, you can display the changed information of the employee record.
Display family info: Displays the changed record in display mode.
Upon approval, HR administrator will then see the record in changed mode as below.
Rejection of Workflow: It deletes the record upon rejecting the workitem.
Display/Approve/Rejection logic in the Workflow:
I have added the new method in the business object that launches the custom transaction.
Pass the input parameters of the function module and make it as a global parameters.
I have created the screen 9000, that has all the available buttons to the approvers.
In the PAI screen events, place your business logic.
REMOVE_LOCK:
FORM remove_lock .
IF gv_employeenumber IS NOT INITIAL.
DATA: address TYPE bapiaddr3,
return TYPE TABLE OF bapiret2.
DATA: lv_data TYPE TABLE OF seqg3,
lv_result TYPE sy-tabix.
DATA lv_rec TYPE pa0105.
SELECT SINGLE * FROM pa0105 INTO lv_rec WHERE pernr = gv_employeenumber AND
begda LE sy-datum AND
endda GE sy-datum AND
subty = ‘0001’.
IF sy-subrc EQ 0.
DATA: lv_name(12) TYPE C.
lv_name = lv_rec-usrid.
CALL FUNCTION ‘ENQUEUE_READ’
EXPORTING
gclient = sy-mandt
guname = lv_name
IMPORTING
number = lv_result
TABLES
enq = lv_data.
IF sy-subrc <> 0 OR lv_result GT 0.
MESSAGE e000(zess).
EXIT.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
APPROVE DEPENDENTS:
SET PARAMETER ID ‘ITP’ FIELD ‘0021’.“OBJECT-INFOTYPENUMBER.
SET PARAMETER ID ‘SUB’ FIELD GV_SUBTYPE .
SET PARAMETER ID ‘BEG’ FIELD GV_VALIDITYBEGIN.
SET PARAMETER ID ‘END’ FIELD GV_VALIDITYEND.
SET PARAMETER ID ‘PER’ FIELD GV_EMPLOYEENUMBER.
SET PARAMETER ID ‘FCD’ FIELD ‘MOD’.“DISPLAY.
SET PARAMETER ID ‘OPS’ FIELD GV_OBJECTID. “VAPP30K122770
SET PARAMETER ID ‘SPP’ FIELD GV_LOCKINDICATOR. “VAPP30K122770
SET PARAMETER ID ‘PSQ’ FIELD GV_RECORDNUMBER. “VAPP30K122770
SET PARAMETER ID ‘PAK’ FIELD ‘X’. “VAPP30K130205
CALL TRANSACTION ‘PA30’ AND SKIP FIRST SCREEN.
DISPLAY DEPENDENTS:
SET PARAMETER ID ‘ITP’ FIELD ‘0021’.“OBJECT-INFOTYPENUMBER.
SET PARAMETER ID ‘SUB’ FIELD GV_SUBTYPE .
SET PARAMETER ID ‘BEG’ FIELD GV_VALIDITYBEGIN.
SET PARAMETER ID ‘END’ FIELD GV_VALIDITYEND.
SET PARAMETER ID ‘PER’ FIELD GV_EMPLOYEENUMBER.
SET PARAMETER ID ‘FCD’ FIELD ‘DIS’.“DISPLAY.
SET PARAMETER ID ‘OPS’ FIELD GV_OBJECTID. “VAPP30K122770
SET PARAMETER ID ‘SPP’ FIELD GV_LOCKINDICATOR. “VAPP30K122770
SET PARAMETER ID ‘PSQ’ FIELD GV_RECORDNUMBER. “VAPP30K122770
SET PARAMETER ID ‘PAK’ FIELD ‘X’. “VAPP30K130205
CALL TRANSACTION ‘PA20’ AND SKIP FIRST SCREEN.
LEAVE_SCREEN:
form LEAVE_SCREEN .
SET SCREEN 0.
LEAVE SCREEN.
endform.
Information about Business Object ADDRESSEMP
I have used the method ChangeInteractive to edit the record in change mode. For rejection, I’ve used the method DeleteInteractive as shown
below.
Thanks,
S.Rajkumar.
Awesome work Rajkumar 🙂
Good work !
Keep posting !!
Hi Rajkumar,
I need a help from you regarding this topic.
I am developing a workflow of same type, but here the user is allowed for 30 days to submit the document and after that the HR admin will process personal info change.
I am able to trigger the workflow but after triggering the workflow the standard SAP program is called and it is updating the info types.
I dont want to update the DB before the HR approves the request.
Can you please give me some clues on the same?
Thanks
Bala
Hello Balaji !
One possible suggestion could be to create a custom screen for employee submission. The submitted details can be collected in internal table( to avoid redundancy)/custom table and thus can be passed to workflow.
If the approver approves, by calling CREATEINTERACTIVE method from FAMILYINT business object, standard table can be updated and the relevant entries in custom table can be deleted if required and internal table is not used.
Regards,
S.Suresh.
Awasome Rajkumar !!
I am facing exactly the same requirement and was looking for a good solution and I found it 🙂 .
Nice !
Hi Rajkumar,
Can you please clarify the below statement. I am not sure I understand how can you enable attachements by designing the workflow - can you please provide more details? and where would the initiator attach documents?
“ I have designed the workflow in such a way that once the workflow is triggered, the workitem has to go to the Initiator of the workflow thus enabling the initiator to attach the documents required for the approval for his changed information in ESS”
Many Thanks!
Hi Elkhatib,
The requirement was to attach any proof of documents whenever the employee changes his personal details in the ESS Screen. As there is no provision in the Standard ESS webdynpro Pages to attach the documents, WF is designed in such a way, the approval will first come to the initiator/Employee who has updated the information. Once the Workitem reaches the employee, there is always an provision to attach any documents within the workitem itself.
To make it simple, you can attach documents in the workitem as its a standard feature provided by SAP.
Thanks,
S.Rajkumar.
Hi Rajkumar,
I am using FM - HR_INFOTYPE_OPERATION to update the data once it has been approved from MSS.
Please let me know how to unlock the record which is locked from BAdI in this case.
Thanks,
Brahma
Hi S.Rajkumar,
Thanks a lot for your document. It is very useful for us.
However I need a help from any of you regarding this topic
We appreciate this document but it is focus on IT0021. And when trying to do some similar with the others, we have found that neither IT0009 nor IT0185 contains any rows in SWEHR2 in order to look for the object and Function module implied. Could you let us know any way to continue? Any object related with the possible triger for these infotypes in order to create another Z function for them?
Thanks a lot ,
Jonathan
Infotype records can be assigned a lock indicator, with the exception of records for infotypes 0000 Actions, 0001 Organizational Assignment, 0002 Personal Data, 0003 Payroll Status, and 0031 Reference
Hello 🙂
does this way work with HR renewal 2.0 ?
@Haitham - this still works, but since you already have the F&P, go with it in HR Renewal.
Plus, locked record status can be achieved via controlling user authorization as well.
Hello Rajkumar,
I followed all the steps as you have mentioned in the blog.
But initially i was getting dump with the same. I resolved the dump by changing sprps of additional infotype also.
But after doing this the data of that infotype cleared.
Any idea how to resolve this. I debugged but could not find the problem.
I would be highly obliged to hear solution for same from anyone.
Hello @Rajkumar Shanmuganathan
I have a question do you have a solution for this problem. If the user did a change in ess then for whatever reason in SWEHR3 the function module was not able to start the workflow now we will be in a problem we can't issue an error to the user and in the same time the infotype is locked. I think it will be better to start th WF rightawy if everything is fine then store also the infotype locked so we are sure that eversthing is attached to each other.
Best Regards
Ibrahim