Copyright 2024 - BV TallVision IT

So your user is the manager and you need to know who is being managed ? Here's a 2-step approach to this using function module HR_STRUC_GET or HR_STRUCTURE_GET on newer systems, accessing a great variaty (700+) of evaluation paths. Who's on my team ? 

SAP's organisation plan (transaction PPOME) is quite an elaborate beast and accessing all this information can get quite complex. To make all this functionality available from Abap viewpoint, evaluation paths (WEGID) were introduced. These can be viewed (and changed) via transaction code PPSM or PPST. Study the output of these transactions - the module described below will return the output.

Table T778A holds a list of evaluation paths that effectively define what information is selected from the organisation plan. With transaction OOAW, (part of SPRO) you can define your own evaluation paths, or check which paths are available and how they can be accessed. For this example we are looking for all personell under a manager, which requires looking up what organisation the manager is running, followed by the people in that organisation. There are nearly 900 evaluation paths in table T778A and many of these overlap in functionality. Also there is a strong dependance with the way your system has been set up - so this example may not work for your system. Focus on the actual evaluation paths to get it to work.

With the personell number of the manager, first determine the organisational unit he/she is on, like so:

CLEAR: lt_results[].
CALL FUNCTION 'HR_STRUC_GET'
  EXPORTING
    root_otype     = 'P '
    root_objid     = p_pernr
    pathid         = 'MANAS' "Evaluation path
* MANAS: Organizational assignment for lead/manager
  IMPORTING
    result_objects = lt_results
  EXCEPTIONS
    OTHERS         = 4.
IF sy-subrc <> 0.
  MESSAGE 'Invalid personell number' TYPE 'E'.
  EXIT.
ENDIF.
* Get the organisation:
READ TABLE lt_results INTO lw_result WITH KEY otype = 'O'.
IF sy-subrc <> 0.
  MESSAGE 'Not a manager...' TYPE 'E'.
ENDIF.

Note the STRU_TECH_DEPTH parameter (not shown here) which can be used to define how deep the selection should go. If it is not defined (STRU_TECH_DEPTH = 0), the evaluation path will recursively walk through the defined path, until it reaches the end. Would you like all personell under the manager or do you leave the personell under managers managing under your manager as-is ? If the parameter is initial - no restriction to the selection depth is assumed. The next thing to do is a call to the same module with the 'O' (Organisation) of the manager, to request all "players" on the organisation: 

clear: lt_results2[]. 
CALL FUNCTION 'HR_STRUC_GET'
  EXPORTING
    root_otype     = 'O '
    root_objid     = lw_result-objid
    pathid         = 'OSP' "Evaluation path
* OSP: Internal persons per organizational unit
  IMPORTING
    result_objects = lt_results2
  EXCEPTIONS
    OTHERS         = 4.

OSP is one of many WEGID evaluation paths. Use report RHWEGID0 or table T778A to list the evaluation paths available on your system. Then simply try out the evaluation path you found using the function module testing in SE37 for the HR_STRUC_GET module. Beware: evaluation paths are specific to the object that is used, so OSP is typically for an O Organisation and MANAG for a P Person.

Also note: RH_STRUC_GET operates in much the same way and produces much the same output as HR_STRUCTURE_GET. The latter is preferred, as it is newer.