Delete infotype (i.e. HRP1001) relationship record by changing the validity date of entry
Below is the very simple ABAP code for deleting a record from the HR relationship table HRP1001 but same code can be used for other infotype tables
such as HRP1000, HRP1002 etc. Well technically it doesn't actually delete it but sets the validity end date to yesterday.
This is actually the correct way to do this as you still have a record of the relationship within the SAP table but it will not be active so will remove the relationship from the user/position.
Also see here for how to create a new entry in HRP1001.
I have tried to make the ABAP code below as generic as possible so that you can just copy and paste it into your SAP system and it will demonstrate the functionality by updating a record. Basically it first selects a record from HRP1001 using some very generic selection criteria, if you have a specific object ID you want to update you can refine this by adding entries to the where clause of the SELECT statement.
Once it has retrieved a record it simply sets the end date (ENDDA) to yesterday's date (i.e. sy-datum - 1) via function module RH_PNNNN_MAINTAIN.
The code also displays an output report show which record has been updated. Might be better to add a break-point where suggested in the ABAP
code so that you can find the record first and see if it is updated correctly. You will also be able to see what values are being passed to the
function module.
REPORT ZHRP1001_UPDATE. DATA: wa_hrp1001 type hrp1001, it_hrp1001 type STANDARD TABLE OF hrp1001. DATA: IPLOG type WPLOG. DATA: ld_datum type datum, wa_hrp1001key type HRIPKEY. ************************************************************************ *START-OF-SELECTION. START-OF-SELECTION. *Set selection data *wa_hrp1001-OBJID = wa_hrp1001-otype = 'S'. wa_hrp1001-PLVAR = '01'. wa_hrp1001-RSIGN = 'A'. *wa_hrp1001-RELAT = wa_hrp1001-istat = '1'. *wa_hrp1001-priox = *wa_hrp1001-BEGDA = sy-datum. *wa_hrp1001-ENDDA = '99991201'. *wa_hrp1001-varyf = *wa_hrp1001-subty = *wa_hrp1001-seqnr = ***********FIND HRP1001 RECORD******* * Select HRP1001 entry to be updated SELECT single * from hrp1001 into wa_hrp1001 where OTYPE = wa_hrp1001-OTYPE * and OBJID = wa_hrp1001-OBJID and PLVAR = wa_hrp1001-PLVAR and RSIGN = wa_hrp1001-RSIGN * and RELAT = wa_hrp1001-RELAT * and ISTAT = wa_hrp1001-ISTAT * and PRIOX = wa_hrp1001-PRIOX and BEGDA le sy-datum and ENDDA gt sy-datum * and VARYF = wa_hrp1001-VARYF * and SEQNR = wa_hrp1001-SEQNR . ************************************************************************ *END-OF-SELECTION. END-OF-SELECTION. ***********UPDATE HRP1001 RECORD******* *Asigne values to key structure, this is usd by the FM to *determine which record to update. MOVE-CORRESPONDING wa_hrp1001 to wa_hrp1001key. *Set validity date to yesterday, this also acts as a delete because *the record is no longer valid ld_datum = sy-datum - 1. CALL FUNCTION 'RH_PNNNN_MAINTAIN' EXPORTING act_fcode = 'CUTI' "AEND act_plvar = wa_hrp1001-PLVAR act_otype = wa_hrp1001-OTYPE act_objid = wa_hrp1001-OBJID act_infty = '1001' * ACT_SUBTY = IPLOG-SUBTY * ACT_BEGDA = IPLOG-BEGDA * ACT_ENDDA = IPLOG-ENDDA * ACT_PNNNN = IPLOG ACT_INFOTYPEKEY = wa_hrp1001key act_gdate = ld_datum SUPPRESS_DIALOG = '2' EXCEPTIONS INFTY_NOT_VALID = 1 NO_PLVAR = 2 OBJECT_NOT_DEFINED = 3 OTYPE_NOT_VALID = 4 NO_AUTHORITY = 5 ACTION_REJECTED = 6 NO_GDATE = 7 FCODE_NOT_SUPPORTED = 8 OTHERS = 9. WRITE:/ wa_hrp1001key-PLVAR, / wa_hrp1001key-OTYPE, / wa_hrp1001key-OBJID, / wa_hrp1001key-INFTY, / wa_hrp1001key-SUBTY, / wa_hrp1001key-ISTAT, / wa_hrp1001key-PRIOX, / wa_hrp1001key-BEGDA, / wa_hrp1001key-ENDDA, / wa_hrp1001key-VARYF, / wa_hrp1001key-SEQNR.
Also see create a new entry in HRP1001
Related Articles
Retrieve SAP HR Organisation unit relationship within HRP1001
SAP Search helps for HR org unit values
Retrieve SAP Organisation unit from HR selection screen
Retrieve text for SAP HR Organisation unit