Please note in these examples I will use table HRP1001 for demonstration but you can use these methods to add entries to other infotype tables
such as HRP1000, HRP1002 etc.
It took a bit of playing around but once you know it is very simple to create a new entry in HRP1001
but there are a few different methods you can use.
Obviously one way would be to use the ABAP MODIFY statement to write the entry to the actual database table.
I would not recommend this way as it by-passes all standard SAP functionality and you would have to know
exactly what you want to add. For example for a B relationship (RELAT field) entry you also need a matching
A relationship entry which is automatically handled when using the following function modules.
The following ABAP code shows two very simple methods of adding a B 012(manages) relationship record
to the HRP1001 table. Also see how to
delete HRP1001 relationship
Method one
This is probably the most straight forward way using function
module OM_CREATE_NEW_RELATIONS. You basically pass the parent details stored in OBJID and the child details
stored in SOBID. The FM will then take these details and create the required entry. Also as mentioned above it
will also create the reverse entry i.e If you pass vrsign = B like below it will also create an entry
where rsign = A with the details flipped.
REPORT ZHRP1001_ENTRY. data: ld_orgeh type pa0001-orgeh. data: ld_pobject type OBJEC, it_cobject type OBJEC_T, ld_cobject like line of it_cobject, ld_flag TYPE FLAG. *Fill Parent object details (OBJID details) ld_pobject-PLVAR = '01'. ld_pobject-OTYPE = 'O'. ld_pobject-OBJID = '10000001'. ld_pobject-BEGDA = sy-datum. ld_pobject-ENDDA = '99991231'. ld_pobject-ISTAT = '1'. *ld_pobject-HISTO = *ld_pobject-SHORT = *ld_pobject-STEXT = *ld_pobject-REALO = *Fill child object details (SOBID details) ld_cobject-PLVAR = '01'. ld_cobject-OTYPE = 'S'. ld_cobject-OBJID = '20000001'. ld_cobject-BEGDA = sy-datum. ld_cobject-ENDDA = '99991231'. ld_cobject-ISTAT = '1'. *ld_cobject-HISTO = *ld_cobject-SHORT = *ld_cobject-STEXT = *ld_cobject-REALO = append ld_cobject to it_cobject. CALL FUNCTION 'OM_CREATE_NEW_RELATIONS' EXPORTING PARENT_OBJECT = ld_pobject CHILD_OBJECTS = it_cobject VRSIGN = 'B' VRELAT = '012' VBEGDA = sy-datum VENDDA = '99991231' * PERCENTAGE = * ACTION_INFO = IMPORTING RELATION_CREATED = ld_flag * TABLES * RELATIONS_TO_CUT = . CALL FUNCTION 'RHOM_WRITE_BUFFER_TO_DB' * EXPORTING * NO_COMMIT = * EXCEPTIONS * DATABASE_ERROR = 1 * CORR_EXIT = 2 * OTHERS = 3 .
Method Two
This method Two works equaly well but requires a bit more processing
upfront to create some extra field values before passing the data
to function module RH_PNNNN_MAINTAIN
REPORT ZHRP1001_ENTRY2. DATA: wa_hrp1001 type hrp1001. DATA: IPLOG LIKE WPLOG. DATA: OUT_FCODE LIKE T77FC-FCODE. wa_hrp1001-OBJID = '10000001'. wa_hrp1001-otype = 'O'. wa_hrp1001-sclas = 'S'. wa_hrp1001-sobid = '20000002'. "dept linked too wa_hrp1001-PLVAR = '01'. wa_hrp1001-RSIGN = 'B'. wa_hrp1001-RELAT = '012'. wa_hrp1001-BEGDA = sy-datum. wa_hrp1001-ENDDA = '99991231'. wa_hrp1001-INFTY = '1001'. wa_hrp1001-istat = '1'. CONCATENATE wa_hrp1001-RSIGN wa_hrp1001-RELAT into wa_hrp1001-subty. move-corresponding wa_hrp1001 to IPLOG. CONCATENATE wa_hrp1001-sclas wa_hrp1001-sobid into iplog-vdata SEPARATED BY space. CALL FUNCTION 'RH_PNNNN_MAINTAIN' EXPORTING ACT_FCODE = 'INSE' ACT_PLVAR = IPLOG-PLVAR ACT_OTYPE = IPLOG-OTYPE ACT_OBJID = IPLOG-OBJID ACT_INFTY = IPLOG-INFTY ACT_SUBTY = IPLOG-SUBTY ACT_ISTAT = IPLOG-ISTAT ACT_BEGDA = IPLOG-BEGDA ACT_ENDDA = IPLOG-ENDDA ACT_PNNNN = IPLOG SUPPRESS_DIALOG = '2' IMPORTING ACT_OK_CODE = OUT_FCODE ACT_PNNNN_OUT = IPLOG 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.
You should also be able to use function module 'RH_INSERT_INFTY_1001_EXT' but I could not get this to work as easily as the
solutions above. It may also need some extra authorisation, as when you run it without catching the exceptions the short
dump mentions an authorisation failure but does not show up in SU53:-(. Strangly enough though if you catch the exceptions
it does not seem to fail because of authorisations.
Also see deleting a HRP1001 entry for simple ABAP code to delete a relationship,
by changing the validity date (i.e. sets end date to to yesterday).