Asign a User to a Position in PPOME Using Functions

Jimbo's picture

Hierarchical mountain goatsThe interfaces provided by SAP in PPOM and PPOME provide almost nothing for creating recordings that can be used to load HR data in a batch. Until now, there has been very little documentation on how to access the HRP1000 and HPR1001 tables directly using off-the-shelf functions provided with SAP.

The task of building the organization and Staffing hierarchy using functions has already been documented, but assigning Users to Positions in the hierarchy still remains to be completed. A simple form to encapsulate the RF_INSERT_INFTY_1001_EXT function wraps up the task quite neatly and leaves time to code a solution to assign Standard Tasks to Positions.

The variables below are hard coded to create a very specific relation between a Position and a User and the values used are documented in the remarks. For an example of a form that can be used to make more types of connections, see this whitepaper.

Form InsertObjects using objParent objChild.
  data: it_HRP1001 LIKE hri1001 OCCURS 0 WITH HEADER LINE.
  data: vtask like HRRHAP-VTASK.
  refresh it_HRP1001.
  clear it_HRP1001.
*** The parameters below are specific for adding users...
  it_HRP1001-MANDT = sy-MANDT.
  it_HRP1001-OTYPE = 'S'.
  it_HRP1001-OBJID = objParent.
  it_HRP1001-PLVAR = '01'. " Current plan
  it_HRP1001-RSIGN = 'A'. " Bottom Up
  it_HRP1001-RELAT = '008'.  " Holder
  it_HRP1001-ISTAT = '1'.
  it_HRP1001-BEGDA = SY-DATUM.
  it_HRP1001-ENDDA = '99991231'.
  concatenate 'US' objChild into it_HRP1001-VARYF.
  it_HRP1001-INFTY = '1001'.
*  concatenate 'S' objParent into it_HRP1001-OTJID separated by space.
*  it_HRP1001-SUBTY = 'A008'.
  it_HRP1001-SCLAS = 'US'.  "User
  it_HRP1001-SOBID = objChild.
  it_HRP1001-PROZT = '100'.
  append it_HRP1001.
  vtask = 'D'.
  CALL FUNCTION 'RH_INSERT_INFTY_1001_EXT'
       EXPORTING
            fcode                   = 'INSE'
            vtask                   = vtask
*           ORDER_FLG               = 'X'
*           COMMIT_FLG              = 'X'
*           AUTHY                   = 'X'
*           KEEP_LUPD               = 'X'
*           PPPAR_IMP               =
       TABLES
            innnn                   = it_HRP1001
       EXCEPTIONS
            no_authorization        = 1
            error_during_insert     = 2
            relation_not_reversible = 3
            corr_exit               = 4
            begda_greater_endda     = 5
            OTHERS                  = 6.
endform.

A p_Commit parameter allows the user to validate the connections before they are made in the system--more on this later. A few variables are added for the purpose of validating the data and p_Break is used later on for the purpose of debugging.

parameters: p_break as checkbox, p_Commit as checkbox.
data: lHRP1001 like HRP1001,
lHRP1000a like HRP1000,
lHRP1000b like HRP1000,
lHRP1000c like HRP1000,
lHRP1000d like HRP1000,
wa_USR like v_usr_name.

To complete the project, a small amount of code is used to validate the Position and the User. If they both exist and the link does not already exist then the OBJID and BNAME values are passed to the InsertObjects form from above and the connection is made.

select single * from v_usr_name into wa_USR
where ( BNAME eq PPOMS-USRID or NAME_TEXT eq PPOMS-USRID ).
if sy-subrc eq 0.
  move wa_USR-BNAME to PPOMU-USERID.
  select single * from HRP1001 into lHRP1001
   where OBJID eq PPOMS-OBJID  "Object ID of Position
     and SCLAS eq 'US'
     and SOBID eq PPOMU-USERID.
  if sy-subrc eq 0. "Already loaded!  Don't load again.
    write: / PPOMS-OBJID, PPOMS-USRID color col_positive,
     'User already attached to workflow.'.
    skip_transaction.
  else.
    write: / PPOMS-OBJID, 
     PPOMS-USRID color col_total,
     'Prepared to attach . . .'.
    if p_Commit eq 'X'.
      perform InsertObjects using PPOMS-OBJID wa_USR-BNAME.
      if sy-subrc eq 0.
        write: 'Success' color col_positive.
      else.
        write: 'Fail' color col_negative.
      endif.
    endif.
  endif.
else.
  write: / PPOMS-OBJID, PPOMS-USRID color col_negative,
   'User not found.'.
endif.
skip_transaction. "Just using LSMW as a wrapper . . .

The end result is that the user appears in the hierarchy where desired. No additional effort is required.

Programming Language: 
ABAP