Use functions to create and link objects in HRP1000 and HRP1001 without PPOME

Jimbo's picture

Hierarchical mountain goatsThe PPOCE and PPOME transaction are notoriously slow and, because of the design of the interface, impossible to automate with a recording. PPOC and PPOM aren't much better as there is no way to drill down into the organizational hierarchy in order to create objects at lower levels.

The HRP1000 and HRP1001 tables are straightforward enough and easily understood, but there is little documentation on how to manage the data in these tables available on the internet. Fortunately, there are solutions for managing HR data in these tables.

Related content:

Start by creating hierarchical data in a flat, relational file. The highest Organization level will have no parent.
Source data

In the GLOBAL_DATA section, add a p_Commit parameter that allows users to validate the hierarchical format of the data before committing it to SAP. The program will refrain from actually calling the functions in SAP if this is not ticked.

 p_Commit as checkbox.

Read this data into an internal table. In LSMW, this can be done by passing the data in as source data and appending it to an internal table. The skip_transaction statement is included here to ensure that no converted records are produced; all work will be handled by off-the-shelf functions from SAP.

*** Populate the internal relational table ***
clear: wa_P1000.
append wa_P1000 to it_P1000.

Next, loop through the data organizing it in a hierarchical format to be displayed to the user. Having a p_Commit parameter allows for the program to be run so that the user can validate the structure before committing it into the system.

The calls to the forms that create and link the objects are embedded here, but they do nothing if the p_Commit parameter is not ticked. More on that later . . .

data: nLevel type i.
data: wa_P1000a like P1000, wa_P1000b like P1000, wa_P1000c like P1000.

loop at it_P1000 into wa_P1000a where UNAME eq ''.
  write: / wa_P1000a-SHORT, wa_P1000a-STEXT color 1.
  perform CreateObject using wa_P1000a-OTYPE wa_P1000a-SHORT
   wa_P1000a-STEXT changing wa_P1000a-OBJID.
  loop at it_P1000 into wa_P1000b where UNAME eq wa_P1000a-SHORT.
    write: / '..', wa_P1000b-SHORT, wa_P1000b-STEXT color 2.
    perform CreateObject using wa_P1000b-OTYPE wa_P1000b-SHORT
     wa_P1000b-STEXT changing wa_P1000b-OBJID.
    perform LinkObjects using wa_P1000a-OBJID wa_P1000b-OBJID
     '002' 'B'.  "Top down.  Reports to
*** Bottom Up link is automatically created with the Top Down link.
*    perform LinkObjects using wa_P1000b-OBJID wa_P1000a-OBJID
*     '002' 'A'.  "Bottom Up.  Reports to
    loop at it_P1000 into wa_P1000c where UNAME eq wa_P1000b-SHORT.
      write: / '.....', wa_P1000c-SHORT, wa_P1000c-STEXT color 3.
      perform CreateObject using wa_P1000c-OTYPE wa_P1000c-SHORT
       wa_P1000c-STEXT changing wa_P1000c-OBJID.
      perform LinkObjects using wa_P1000b-OBJID wa_P1000c-OBJID
       '003' 'B'.  "Top down.  Belongs to
*** Bottom Up link is automatically created with the Top Down link.
*      perform LinkObjects using wa_P1000c-OBJID wa_P1000b-OBJID
*       '003' 'A'.  "Bottom Up.  Belongs to

Validate the hierarchical structure.
This tool was written for triage over the weekend of go-live, so it is not the prettiest code ever written, but it is functional and provided here for the sake of edification. The client for whom it was written was very happy with the results.

If the user is satisfied with the hierarchical format of the data, then the program can be run again with the p_Commit parameter ticked. Because this program was written after lunch on the Sunday of go-live weekend, the p_Commit parameter is checked inside the CreateObject form and the LinkObjects form does nothing because blank OBJID values are being passed in.

The CreateObject returns the OBJID of the newly created object (Organization or Position for this example) and that value, along with the parent value are passed to the LinkObjects form causing the parent and child objects to be linked together.

The HRP1001 table has Top Down (RSIGN = B) and Bottom Up (RSIGN = 'A') links between parent and child objects in the hierarchy. During development, code was written to create both links, but during testing it was discovered that the Bottom Up link is created automatically when the Top Down link is created. The call to create the Bottom Up link was simply remarked out in the code above.

form CreateObject using lvOTYPE lvSHORT lvSTEXT changing lvOBJID.
  if p_Commit eq 'X'. "Commit parameter selected.
    data: lvP1000 like P1000,
     ltP1000 LIKE p1000 OCCURS 0 WITH HEADER LINE.
    lvP1000-MANDT = sy-MANDT.
    lvP1000-PLVAR = '01'. "Current
    lvP1000-OTYPE = lvOTYPE.
    lvP1000-INFTY = '1000'.
    lvP1000-ISTAT = '1'.
    lvP1000-BEGDA = sy-datum.
    lvP1000-ENDDA = '99991231'.
    lvP1000-SHORT = lvSHORT.
    lvP1000-STEXT = lvSTEXT.
    append lvP1000 to ltP1000.
    lvVTASK = 'D'.
            LANGU               = sy-LANGU
            PLVAR               = lvP1000-PLVAR
            OTYPE               = lvP1000-OTYPE
            SHORT               = lvP1000-SHORT
            STEXT               = lvP1000-STEXT
            BEGDA               = lvP1000-BEGDA
            ENDDA               = lvP1000-ENDDA
            VTASK               = lvVTASK
            OBJID               = lvP1000-OBJID
            TEXT_REQUIRED       = 1
            INVALID_OTYPE       = 2
            INVALID_DATE        = 3
            ERROR_DURING_INSERT = 4
            UNDEFINED           = 5
            OTHERS              = 6.
    lvOBJID = lvP1000-OBJID.
    wait up to 1 seconds. "Give database time to commit.
    write: lvP1000-OBJID color col_positive.

Form LinkObjects using objParent objChild lvRELAT lvRSIGN.
  data: it_HRP1001 LIKE hri1001 OCCURS 0 WITH HEADER LINE.
  data: vtask like HRRHAP-VTASK,
   lHRP1000p like HRP1000, lHRP1000c like HRP1000.
  select single * from HRP1000 into lHRP1000p
   where OBJID eq objParent
     and PLVAR eq '01'
     and AEDTM eq sy-DATUM. "Extra level of safety.
  if sy-subrc eq 0.
    select single * from HRP1000 into lHRP1000c
     where OBJID eq objChild
       and PLVAR eq '01'
       and AEDTM eq sy-DATUM. "Extra level of safety.
    if sy-subrc eq 0.

    refresh it_HRP1001.
    clear it_HRP1001.
    it_HRP1001-MANDT = sy-MANDT.
    it_HRP1001-OTYPE = lHRP1000p-OTYPE. "Parent
    it_HRP1001-OBJID = lHRP1000p-OBJID.
    it_HRP1001-PLVAR = lHRP1000p-PLVAR.
    it_HRP1001-RSIGN = lvRSIGN.  " 'B'.  "Top down.
    it_HRP1001-RELAT = lvRELAT.  " '007'.
    it_HRP1001-INFTY = '1001'.
    it_HRP1001-ISTAT = lHRP1000p-ISTAT.
    it_HRP1001-BEGDA = SY-DATUM.
    it_HRP1001-ENDDA = '99991231'.
    it_HRP1001-VARYF = lHRP1000c-OTYPE.
    it_HRP1001-VARYF+2(8) = lHRP1000c-OBJID.
    it_HRP1001-SCLAS = lHRP1000c-OTYPE.
    it_HRP1001-SOBID = lHRP1000c-OBJID.
    it_HRP1001-PROZT = '0'.
    append it_HRP1001.
    vtask = 'D'.
              fcode                   = 'INSE'
              vtask                   = vtask
*             ORDER_FLG               = 'X'
*             COMMIT_FLG              = 'X'
*             AUTHY                   = 'X'
*             KEEP_LUPD               = 'X'
*             PPPAR_IMP               =
              innnn                   = it_HRP1001
              no_authorization        = 1
              error_during_insert     = 2
              relation_not_reversible = 3
              corr_exit               = 4
              begda_greater_endda     = 5
              OTHERS                  = 6.
      if sy-subrc eq 0.
        write: 'Linked', lHRP1000p-OBJID, 'to', lHRP1000c-OBJID.
      wait up to 1 seconds. "Allow database to commit writes.

Finally, the system creates the objects and links them together in a hierarchical format. See the LSMW report explaining the success of the creation and links and then the screen shot of the tables HRP1000 and HRP1001.