Edit: Since posting this I realised that the problem is I'm not creating the 1001 record, but still having all sorts of issues introducing this insertion due to mainly due to it thinking that personnel number doesn't exist yet, even if I put it after the first set of approve/flush methods. Hence problem still stands, but I'm getting closer.
Hi All,
Below is some fairly cool HR Infotype code, albeit structured a little badly plus it's a little cut down from the production version, to programmatically hire a new/rehire a old person into a position, but even though PA-OM integration is set-up in the system, and working through the normal UI, this method being called (via Gateway) is not doing the OM update (background issue perhaps). You can fix it by running rhinte00 but this should be automatic and not require this brute force fix. Any ideas what I'm missing, be it code or configuration?
Thanks,
Matt
DATA: o_exception TYPE REF TO cx_root, action type MASSG, is_ok TYPE boole_d, new_employee_id TYPE pernr_d, is_internal TYPE boole_d, itbld TYPE itbld, s_pskey TYPE pskey, s_0000 TYPE p0000, s_0001 TYPE p0001, s_0002 TYPE p0002, s_0003 TYPE p0003, s_0006 TYPE p0006, s_0007 TYPE p0007, s_0008 TYPE p0008, s_0016 type p0016, s_0105 TYPE p0105, s_1000 TYPE p1000, o_person_reader TYPE REF TO cl_hrcce_person_reader, s_emergency_contact TYPE zhr_new_hire_emerg_parameters, * HRPA related objects o_pa_messages TYPE REF TO cl_hrpa_message_list, o_masterdata_buffer TYPE REF TO if_hrpa_masterdata_buffer, o_pa_plain_access TYPE REF TO if_hrpa_plain_infotype_access, o_pa_buffer_token TYPE REF TO if_hrpa_token, o_template_0001 TYPE hrpad_infotype_container_ref, o_container_0001 TYPE REF TO cl_hrpa_infotype_container, * HRBAS related objects o_business_logic TYPE REF TO if_hrbas_dispatch_bl, o_bas_plain_access TYPE REF TO cl_hrbas_plain_infotype_access, o_bas_messages TYPE REF TO cl_hrbas_message_list, o_bas_message TYPE hrbas_msg_handler_if_ref, o_bas_buffer_token TYPE hrbas_token_ref, text type string. * Need to do this a convoluted way due to issues with pernr generation. e.g. HR_PAD_HIRE_EMPLOYEE will not work in this scenario * Overly long method, but mostly tedious get new infotype record, update values, insert logic. CREATE OBJECT o_pa_messages. cl_hrpa_masterdata_factory=>get_masterdata_buffer( IMPORTING masterdata_buffer = o_masterdata_buffer ). cl_hrpa_masterdata_factory=>get_plain_infotype_access( IMPORTING plain_infotype_access = o_pa_plain_access ). o_pa_plain_access->if_hrpa_buffer_control~initialize( ). o_pa_plain_access->if_hrpa_buffer_control~start_trial( IMPORTING magic_cookie = o_pa_buffer_token ). if is_hire_information-rehire_employee_id is initial. action = CO_ACTION_NEWHIRE. DO. CALL METHOD cl_hrpa_pernr_checks=>create_pernr EXPORTING werks = is_hire_information-personnel_area_id persg = is_hire_information-employee_group_id persk = is_hire_information-employee_sub_group_id message_handler = o_pa_messages IMPORTING is_ok = is_ok CHANGING pernr = new_employee_id is_internal = is_internal. IF is_ok = abap_false. o_pa_plain_access->if_hrpa_buffer_control~discard_trial( o_pa_buffer_token ). RAISE EXCEPTION TYPE zcx_hr_object EXPORTING textid = zcx_hr_object=>hire_unknown_error text = 'Could not create new Employee Id'. ENDIF. SELECT SINGLE pernr FROM pa0003 INTO new_employee_id WHERE pernr EQ new_employee_id. IF sy-subrc <> 0. EXIT. " Avoids dodgy data in non-production (hopefully not production) systems ENDIF. ENDDO. else. action = co_action_rehire. new_employee_id = is_hire_information-rehire_employee_id. endif. * fill container with partial data of Infotype 0001 CALL METHOD cl_hrpa_infotype_factory=>get_container_template EXPORTING tclas = cl_hrpa_tclas=>tclas_employee infty = '0001' IMPORTING template = o_template_0001. s_pskey-pernr = new_employee_id. s_pskey-infty = '0001'. s_pskey-subty = space. s_pskey-endda = if_hrpa_plain_infotype_access=>high_date. s_pskey-begda = is_hire_information-start_date. s_pskey-sprps = if_hrpa_read_infotype=>locked. o_template_0001 ?= o_template_0001->modify_key( s_pskey ). o_container_0001 ?= o_template_0001. * Now to set up Infotype 1 MOVE-CORRESPONDING s_pskey TO s_0001. * populate with required fields s_0001-werks = is_hire_information-personnel_area_id. s_0001-btrtl = is_hire_information-personnel_sub_area_id. if is_hire_information-fixed_term_end_date is initial. s_0001-persg = is_hire_information-employee_group_id. else. case is_hire_information-employee_group_id. when '1'. " Permanent Full Time s_0001-persg = '3'. " Temporary Full Time when '2'. s_0001-persg = '4'. " Temporary Part Time when others. s_0001-persg = is_hire_information-employee_group_id. endcase. endif. s_0001-persk = is_hire_information-employee_sub_group_id. s_0001-abkrs = is_hire_information-payroll_area. s_0001-otype = 'S'. " Position s_0001-plans = objid. " Position Id o_template_0001 ?= o_container_0001->modify_primary_record( s_0001 ). * write container into buffer - no checks will really be carried out CALL METHOD o_masterdata_buffer->insert EXPORTING container = o_template_0001 no_ale = abap_true no_workflow = abap_true. if is_hire_information-rehire_employee_id is initial. * now create the IT0003 s_0003-pernr = new_employee_id. s_0003-infty = '0003'. s_0003-begda = if_hrpa_plain_infotype_access=>low_date. s_0003-endda = if_hrpa_plain_infotype_access=>high_date. CALL METHOD o_pa_plain_access->insert EXPORTING tclas = cl_hrpa_tclas=>tclas_employee massn = action massg = is_hire_information-reason_for_hire_id no_auth_check = abap_false message_handler = o_pa_messages IMPORTING is_ok = is_ok CHANGING pnnnn = s_0003. IF is_ok = abap_false. o_pa_plain_access->if_hrpa_buffer_control~discard_trial( o_pa_buffer_token ). raise_hire_exception( EXPORTING io_pa_messages = o_pa_messages ). ENDIF. * set grouping - so that IT0001 and 0000 don't get confused (viekn is blank for SRG) CALL METHOD cl_hrpa_viekn=>set_viekn EXPORTING tclas = cl_hrpa_tclas=>tclas_employee pernr = new_employee_id viekn = space. endif. * Create Action 0000 s_pskey-infty = '0000'. s_pskey-pernr = new_employee_id. s_pskey-subty = space. s_pskey-endda = if_hrpa_plain_infotype_access=>high_date. s_pskey-begda = is_hire_information-start_date. s_pskey-sprps = if_hrpa_read_infotype=>unlocked. CALL METHOD o_pa_plain_access->get_initial_record EXPORTING tclas = cl_hrpa_tclas=>tclas_employee pskey = s_pskey itbld = itbld massn = action massg = is_hire_information-reason_for_hire_id no_auth_check = abap_false message_handler = o_pa_messages IMPORTING pnnnn = s_0000 is_ok = is_ok. IF is_ok = abap_false. o_pa_plain_access->if_hrpa_buffer_control~discard_trial( o_pa_buffer_token ). raise_hire_exception( EXPORTING io_pa_messages = o_pa_messages ). ENDIF. * insert the action s_0000-subty = space. s_0000-massn = action. s_0000-massg = is_hire_information-reason_for_hire_id. CALL METHOD o_pa_plain_access->insert EXPORTING tclas = cl_hrpa_tclas=>tclas_employee massn = action massg = is_hire_information-reason_for_hire_id no_auth_check = abap_false message_handler = o_pa_messages IMPORTING is_ok = is_ok CHANGING pnnnn = s_0000. IF is_ok = abap_false. o_pa_plain_access->if_hrpa_buffer_control~discard_trial( o_pa_buffer_token ). raise_hire_exception( EXPORTING io_pa_messages = o_pa_messages ). ENDIF. * update IT0001 with an unlocked record s_0001-sprps = if_hrpa_read_infotype=>unlocked. s_0001-sbmod = co_administrator_group. s_0001-sachp = co_administrator_hr. CALL METHOD o_pa_plain_access->insert EXPORTING tclas = cl_hrpa_tclas=>tclas_employee massn = action massg = is_hire_information-reason_for_hire_id no_auth_check = abap_false message_handler = o_pa_messages IMPORTING is_ok = is_ok CHANGING pnnnn = s_0001. IF is_ok = abap_false. o_pa_plain_access->if_hrpa_buffer_control~discard_trial( o_pa_buffer_token ). raise_hire_exception( EXPORTING io_pa_messages = o_pa_messages ). ENDIF. * Fill Infotype 1000 structure s_1000-mandt = sy-mandt. s_1000-plvar = '01'. s_1000-otype = 'CP'. s_1000-infty = '1000'. s_1000-istat = 1. s_1000-begda = is_hire_information-start_date. s_1000-endda = if_hrpa_plain_infotype_access=>high_date. s_1000-short = is_hire_information-applicant_last_name. s_1000-stext = is_hire_information-applicant_last_name. CALL METHOD cl_hrbas_dispatch_bl=>get_instance IMPORTING dispatch_bl = o_business_logic. CREATE OBJECT o_bas_plain_access EXPORTING dispatch_bl = o_business_logic. CREATE OBJECT o_bas_messages. o_bas_message ?= o_bas_messages. o_bas_plain_access->if_hrbas_buffer_control~initialize( ). o_bas_plain_access->if_hrbas_buffer_control~start_trial( IMPORTING magic_cookie = o_bas_buffer_token ). CALL METHOD o_bas_plain_access->if_hrbas_plain_infotype_access~insert EXPORTING no_auth_check = abap_true message_handler = o_bas_message IMPORTING is_ok = is_ok CHANGING pnnnn = s_1000. IF is_ok = abap_false. o_pa_plain_access->if_hrpa_buffer_control~discard_trial( o_pa_buffer_token ). o_bas_plain_access->if_hrbas_buffer_control~discard_trial( o_bas_buffer_token ). raise_hire_exception( EXPORTING io_bas_messages = o_bas_messages ). ENDIF. * o_person_reader = cl_hrcce_person_reader=>get_instance( ). * CALL METHOD o_person_reader->put_cp_relation * EXPORTING * p_personid = s_1000-objid * p_pernr = new_employee_id. * Approve and flush (without commit) so we can add the additional infotype information o_pa_plain_access->if_hrpa_buffer_control~approve_trial( EXPORTING magic_cookie = o_pa_buffer_token ). o_pa_plain_access->if_hrpa_buffer_control~flush( no_commit = abap_true ). o_bas_plain_access->if_hrbas_buffer_control~approve_trial( EXPORTING magic_cookie = o_bas_buffer_token ). o_bas_plain_access->if_hrbas_buffer_control~flush( no_commit = abap_true ). Do Other infotype updates from here