Assign a Standard Task to a Position in PPOME Using Functions

Jimbo's picture

Hierarchical mountain goatsThe interface provided by SAP in the PFTC transaction provides 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 on this site, 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 Users to Positions.

The variables below are hard coded to create a very specific relation between a Position and a Standard Task 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 standard tasks...
  it_HRP1001-MANDT = sy-MANDT.
  it_HRP1001-OTYPE = 'S'.  "Position
  it_HRP1001-OBJID = objParent.
  it_HRP1001-PLVAR = '01'.  " Current plan
  it_HRP1001-RSIGN = 'B'.  " Top down
  it_HRP1001-RELAT = '007'.  " Describes
  it_HRP1001-INFTY = '1001'.
  it_HRP1001-ISTAT = '1'.
  it_HRP1001-BEGDA = SY-DATUM.
  it_HRP1001-ENDDA = '99991231'.
  concatenate 'TS' objChild into it_HRP1001-VARYF.
*  concatenate 'S' objParent into it_HRP1001-OTJID separated by space.
*  it_HRP1001-SUBTY = 'B007'.
  it_HRP1001-SCLAS = 'TS'.  " Standard Task
  it_HRP1001-SOBID = objChild.
  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.

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.

parameters: p_commit as checkbox.
lHRP1001a like HRP1001,
lHRP1001b like HRP1001,
lHRP1000a like HRP1000,
lHRP1000b like HRP1000.

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.

*** Validate the Standard Task ***
select single OBJID from HRSOBJECT into PFTCC-SEARK
where OTYPE eq 'TS'
if sy-subrc ne 0.
  write: / PFTCS-TASK color col_negative, 'Invalid standard task.'.

*** Validate the Position ***
if PFTCS-SEARK co '1234567890 '.
  shift PFTCS-SEARK left deleting leading space.
  select single * from HRP1000 into lHRP1000a
   where OBJID eq PFTCS-SEARK.
else.  "Comes as a name . . .
  select single * from HRP1000 into lHRP1000a
   where STEXT eq PFTCS-SEARK.
if sy-subrc ne 0.
  write: / PFTCS-SEARK color col_negative, 'Org not found.'.
  select single * from HRP1001 into lHRP1001c
   where OBJID eq lHRP1000a-OBJID
     and PLVAR eq '01'  "current plan
     and RELAT eq '007' "Relationship
     and SCLAS eq 'TS'
     and SOBID eq PFTCS-TASK.
    if sy-subrc eq 0.
      write: / PFTCS-SEARK, lHRP1000a-STEXT,
       PFTCS-TASK color col_positive,
       'Already assigned.'.
      PFTCC-SEARCH1 = lHRP1000c-STEXT.
      write: / PFTCS-SEARK, lHRP1000a-STEXT,
       '(', lHRP1000a-OBJID+0(8) color col_total, ')',
       PFTCS-TASK color col_total,
       'Prepared to assign . . . '.
      if p_Commit = 'X'.
        perform InsertObjects using lHRP1000a-OBJID PFTCS-TASK.
        if sy-subrc eq 0.
          write: 'Assigned!' color col_positive.
          write: 'Failed.' color col_negative.
skip_transaction. "Just using LSMW as a wrapper . . .

Calling the code the first time without the p_Commit parameter ticked only shows how the data will be loaded. No connections have been made at this point.

Running the program a second time with the p_Commit parameter ticked causes the data to be loaded. At this point it is clear that the connections have been made.

Programming Language: