Una función que lee mediante vías de evaluación el jefe más cercano de una persona, considerando que su Unidad Organizativa no tiene jefe directo.
*&---------------------------------------------------------------------**& Form BUSCA_JEFE
*&---------------------------------------------------------------------*
FORM busca_jefe USING pernr TYPE persno
CHANGING idjefe TYPE persno
nombrejefe TYPE pad_cname.
DATA: l_objid TYPE objec-objid.
DATA: ti_result LIKE objec OCCURS 0 WITH HEADER LINE.
DATA: ti_result2 LIKE objec OCCURS 0 WITH HEADER LINE.
DATA: p0001 TYPE TABLE OF p0001 WITH HEADER LINE.
DATA: exit.
rp-read-infotype pernr 0001 p0001 sy-datum sy-datum.
READ TABLE p0001 INDEX 1.
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = 'P'
act_objid = pernr
act_wegid = 'P-S-O-O'
authority_check = ' '
TABLES
result_objec = ti_result
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
exit = 'X'.
ENDIF.
CHECK exit = space.
LOOP AT ti_result WHERE otype EQ 'O'.
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = 'O'
act_objid = ti_result-objid
act_wegid = 'B012'
authority_check = ' '
TABLES
result_objec = ti_result2
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
READ TABLE ti_result2 WITH KEY otype = 'S'.
CHECK sy-subrc = 0 and p0001-plans <> ti_result2-objid.
l_objid = ti_result2-objid.
REFRESH ti_result2.
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = 'S'
act_objid = l_objid
act_wegid = 'SAP_ORG'
authority_check = ' '
TABLES
result_objec = ti_result2
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.
IF sy-subrc <> 0.
CONTINUE.
ENDIF.
READ TABLE ti_result2 WITH KEY otype = 'P'.
CHECK sy-subrc = 0.
idjefe = ti_result2-objid.
nombrejefe = ti_result2-stext.
EXIT.
ENDLOOP.
ENDFORM. " BUSCA_JEFE