HCM Process & Forms (Programatically Cancel Request and Workflow)
Sometimes a HCM Process just needs to be deleted (cancelled). I’ve found that occasionally there will be a hung request out there that no user is able to process. It only happens very rarely, but being able to quickly cancel the request and any associated workflow is a handy thing to do. So here is a quick and dirty program which allows you to choose a process by reference number and cancel both the request and any workflows associated with it. thanks..
report zupd_proc_status.
data: t_t5asrprocesses type t5asrprocesses.
data: t_sww_wi2obj type sww_wi2obj.
selection-screen begin of block b1 with frame title text–002.
selection-screen begin of line.
selection-screen comment 1(27) text–005.
parameter: p_refn like t5asrprocesses–reference_number.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 1(27) text–004.
parameter : p_stat like t5asrprocesses–status default ‘WITHDRAWN’.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 1(27) text–007.
parameter : p_wf type char1 default ‘X’.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 1(27) text–006.
parameter : p_test type char1 default ‘X’.
selection-screen end of line.
selection-screen end of block b1.
start–of–selection.
select single * into t_t5asrprocesses from t5asrprocesses
where reference_number = p_refn.
if sy–subrc <> 0.
message i103(hrasr00_process) with p_refn.
exit.
else.
if t_t5asrprocesses–status eq p_stat.
message ‘Status is already the requested status.’ type ‘I’.
exit.
else.
if p_test is initial.
t_t5asrprocesses–status = p_stat.
if t_t5asrprocesses–status = ‘DRAFT’ or t_t5asrprocesses–status = ‘STARTED’.
clear t_t5asrprocesses–completion_date.
clear t_t5asrprocesses–completion_time.
else.
t_t5asrprocesses–completion_date = sy–datum.
t_t5asrprocesses–completion_time = sy–uzeit.
endif.
update t5asrprocesses from t_t5asrprocesses.
if sy–subrc eq 0.
commit work.
message ‘Update Complete.’ type ‘I’.
if not ( p_wf is initial ).
if not ( t_t5asrprocesses–status = ‘DRAFT’ ) and not ( t_t5asrprocesses–status = ‘STARTED’ ).
select single * into t_sww_wi2obj from sww_wi2obj
where instid = t_t5asrprocesses–case_guid
and catid = ‘CL’
and typeid = ‘CL_HRASR00_WF_PROCESS_OBJECT’
and wi_reltype = ’99’
and wi_rh_task like ‘WS%’.
if sy–subrc eq 0.
call function ‘SWW_WI_ADMIN_CANCEL’
exporting
wi_id = t_sww_wi2obj–wi_id.
if sy–subrc = 0.
message ‘Update Complete. WF Cancelled.’ type ‘I’.
endif.
endif.
endif.
endif.
exit.
endif.
else.
message ‘Update Can Be Done.’ type ‘I’.
exit.
endif.
endif.
endif.
Wow! Very nice. I usually have to do a "Stop Process" process for clients that is similar to this, but this is really nice too! Thanks for sharing and KEEP BLOGGING!
Why not use function module HR_ASR_WITHDRAW_PROCESS?
Thanks Smuli. I may use this function now that you have alerted me to it. (:->
However, the code above allows using any status and not just WITHDRAWN. Also, the other benefit is that there is not an auth check.. But, either way, as long as the job gets done, it's all about keeping the clients happy.