Thursday, April 24, 2025

DeCouple Framework - ABAP HR - OOPS - Employee Data Creation Update

Create (insert) and Modify(Update) Employee Data using OOABAP HR in SAP HCM (Decouple Framework) 

Logic

 Read the SAP ECC/S4 Data (table) for the employee

If no record found then trigger - INSERT method 
(this will create the record that is coming from WD)

 Else, if record is found, check the field wise validation

Example (for Address): 
workday-postal_code = Existing_S4-postal_code
workday-city = Existing_S4-City
workday-Country = Existing S4-Country

 

If all fields are same, then no need to modify
If any data is changed then trigger MODIFY method


DATA li_iread TYPE REF TO if_hrpa_plain_infotype_access.
cl_hrpa_masterdata_factory=>get_plain_infotype_access(
  IMPORTING plain_infotype_access = li_iread     ).
" * Message handler
DATA lo_mhand TYPE REF TO if_hrpa_message_handler.
DATA lo_mlist TYPE REF TO cl_hrpa_message_list.
FREE lo_mlist.

CREATE OBJECT lo_mlist.
lo_mhand = lo_mlist.

DATA ls_p0006 TYPE p0006.
li_iread->read_single(
  EXPORTING tclas           = cl_hrpa_tclas=>tclas_employee
            pernr           = '00000100'
            infty           = '0006'
            subty           = '1'
            objps           = '*' "lc_objps_all
            sprps           = if_hrpa_read_infotype=>unlocked
            begda           = '19000101'
            endda           = '99991231'
            mode            = if_hrpa_read_infotype=>last_intersecting_record
            no_auth_check   = if_hrpa_boole_d=>true
            message_handler = lo_mhand
  IMPORTING pnnnn           = ls_p0006  ).

li_iread->insert( EXPORTING tclas = cl_hrpa_tclas=>tclas_employee
                            no_auth_check   = if_hrpa_boole_d=>true
                            message_handler = lo_mhand
                  CHANGING  pnnnn           = ls_p0006    ).

" * Modify record

DATA ls_pskey TYPE pskey.

MOVE-CORRESPONDING ls_p0006 TO ls_pskey.
li_iread->modify( EXPORTING tclas           = cl_hrpa_tclas=>tclas_employee
            old_pskey       = ls_pskey
            no_auth_check   = if_hrpa_boole_d=>true
            message_handler = lo_mhand
  CHANGING  pnnnn           = ls_p0006    ).

li_iread->if_hrpa_buffer_control~flush( no_commit = abap_false ).
DATA lt_mlist TYPE hrpad_message_tab.
lo_mlist->get_message_list(
  IMPORTING messages = lt_mlist

0 comments: