Scenario -
There could be few scenarios where you want to trigger the HCM P&F based process from a background job or an ABAP report. You may want to perform a mass processing using some kind of simple background job. Keeping that in mind, I am writing this blog which would trigger the process using a simple ABAP report(this report can be enhanced for multiple processing).
Solution -
Create a Report with the below selection criteria -
PARAMETERS : p_pernr type pernr_d,
p_email type pa0105-USRID_LONG.
Instantiate the Process Execute Object instance(of type IF_HRASR00_PROCESS_EXECUTE) and retrieve the basic attributes(Special Data, Additional Data, UI Attributes, Input helps) of your process(say ZTEST2) -
TRY.
g_process = 'ZTEST2'.
* Move the selected Personnel Number to the Object Key
MOVE P_PERNR TO object_key.
* Instantiate the Process Execute
lo_process_execute ?= cl_hrasr00_process_execute=>get_instance( iv_process = g_process ).
* Get the Attributes of the process
lo_process_execute->initialize_form(
EXPORTING
iv_process = g_process
iv_object_key = object_key
iv_initiator_role = 'HRASRD'
IMPORTING
et_form_field_values = gt_special_data
et_input_help_values = gt_additional_data
et_messages = gt_messages
et_field_ui_attributes = gt_ui_attributes
ev_is_ok = gv_is_ok
et_input_help_extended = gt_input_helps_extended ).
CATCH cx_hrasr00_process_execute INTO lx_proc_exec.
lv_msg_text = lx_proc_exec->if_message~get_text( ).
write lv_msg_text.
EXIT.
ENDTRY.
Update the "SPECIAL_DATA" Internal table with the parameter value and perform the check -
TRY.
* Update the selected email ID
read table gt_special_data ASSIGNING <special_data> with key FIELDNAME = 'I0105_USRID_LONG'.
IF SY-SUBRC = 0.
move p_email to <special_data>-FIELDVALUE.
ENDIF.
lo_process_execute->check_form_data(
EXPORTING
iv_process = g_process
iv_object_key = object_key
CHANGING
ct_form_field_values = gt_special_data
ct_input_help_values = gt_additional_data
ct_message_list = gt_messages
ct_field_ui_attributes = gt_ui_attributes
ct_input_help_extended = gt_input_helps_extended ).
CATCH cx_hrasr00_process_execute INTO lx_proc_exec.
lv_msg_text = lx_proc_exec->if_message~get_text( ).
write : lv_msg_text.
EXIT.
ENDTRY.
Finally trigger the process -
TRY.
lo_process_execute->submit_form_data(
EXPORTING
iv_process = g_process
iv_object_key = object_key
IMPORTING
ev_process_ref_number = g_procref
CHANGING
ct_form_field_values = gt_special_data
ct_input_help_values = gt_additional_data
ct_message_list = gt_messages
ct_field_ui_attributes = gt_ui_attributes ).
CATCH cx_hrasr00_process_execute INTO lx_proc_exec.
lv_msg_text = lx_proc_exec->if_message~get_text( ).
WRITE : lv_msg_text.
EXIT.
ENDTRY.