Hi the code below explains how we can find the reporting manager of a person by giving his personal number.

REPORT  zhr_get_man_of_pernr.

INFOTYPES:    0001,0002,1001.
DATA:        lv_sobid  TYPE hrp1001objid.
DATA:        lv_sobid1  TYPE hrp1001objid.
PARAMETERSp_pernr TYPE p_pernr.

PERFORM find_org.


IF sysubrc = 0.
  lv_sobid = p0001orgeh.
  lv_sobid1 = p0001orgeh.

  PERFORM find_manager_pos.


  IF sysubrc = 0.


    PERFORM fetch_man_pernr.


         IF sysubrc = 0.
           PERFORM check_pernr.
         ENDIF.

  ENDIF.

ENDIF.

PERFORM disp_result.

*&———————————————————————*
*&      Form  FIND_ORG
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*

FORM find_org .

  CALL FUNCTION ‘HR_READ_INFOTYPE’
    EXPORTING
*     TCLAS           = ‘A’
      pernr           = p_pernr
      infty           = ‘0001’
      begda           = ‘18000101’
      endda           = ‘99991231’
    TABLES
      infty_tab       = p0001
    EXCEPTIONS
      infty_not_found = 1
      OTHERS          = 2.

  IF sysubrc <> 0.
    MESSAGE ‘Invalid Personal Number’ TYPE ‘E’.
  ENDIF.

ENDFORM.                    ” FIND_ORG

*&———————————————————————*
*&      Form  FIND_MANAGER_POS
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*

FORM find_manager_pos .

*– Get position for the Org unit (Manager)

  CALL FUNCTION ‘RH_READ_INFTY’
    EXPORTING
      plvar                = ’01’
      otype                = ‘O’
      objid                = lv_sobid
      infty                = ‘1001’
      subty                = ‘B012’
      begda                = sydatum
      endda                = sydatum
    TABLES
      innnn                = p1001
    EXCEPTIONS
      all_infty_with_subty = 1
      nothing_found        = 2
      no_objects           = 3
      wrong_condition      = 4
      wrong_parameters     = 5
      OTHERS              = 6.

  IF sysubrc <> 0.
    MESSAGE ‘No data fecth for the specified key1’ TYPE ‘E’.
  ENDIF.

  SORT  p1001 BY objid.
  READ TABLE p1001 WITH KEY objid = lv_sobid
                          otype = ‘O’      “org unit
                          rsign = ‘B’      “hirarchy top down
                          relat = ‘012’    “Manages
                          sclas = ‘S’.    “Position

ENDFORM.                    ” FIND_MANAGER_POS

*&———————————————————————*
*&      Form  FETCH_MAN_PERNR
*&——————————————————————–*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*

FORM fetch_man_pernr .

  IF NOT p1001[] IS INITIAL.
    lv_sobid = p1001sobid.
*– Get Personnel number for the Manager
    CALL FUNCTION ‘RH_READ_INFTY’
      EXPORTING
        plvar                = ’01’
        otype                = ‘S’
        objid                = lv_sobid
        infty                = ‘1001’
        subty                = ‘A008’
        begda                = sydatum
        endda                = sydatum
      TABLES
        innnn                = p1001
      EXCEPTIONS
        all_infty_with_subty = 1
        nothing_found        = 2
        no_objects           = 3
        wrong_condition      = 4
        wrong_parameters     = 5
        OTHERS              = 6.

    IF sysubrc <> 0.
      MESSAGE ‘No data fecth for the specified key2’ TYPE ‘E’.
    ENDIF.

  ENDIF.

  READ TABLE p1001 WITH KEY objid = lv_sobid
                           otype = ‘S’      “Position
                           rsign = ‘A’      “bottom up
                           relat = ‘008’    “Holder
                           sclas = ‘P’.    “Person

ENDFORM.                    ” FETCH_MAN_PERNR

*&———————————————————————*
*&      Form  CHECK_PERNR
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*

FORM check_pernr .

*IF NOT p1001[] IS INITIAL.

  IF p_pernr = p1001sobid+0(8).
*– Get  the Org unit
    CALL FUNCTION ‘RH_READ_INFTY’
      EXPORTING
        plvar                = ’01’
        otype                = ‘O’
        objid                = lv_sobid1
        infty                = ‘1001’
        subty                = ‘A002’
        begda                = sydatum
        endda                = sydatum
      TABLES
        innnn                = p1001
      EXCEPTIONS
        all_infty_with_subty = 1
        nothing_found        = 2
        no_objects           = 3
        wrong_condition      = 4
        wrong_parameters     = 5
        OTHERS              = 6.

    IF sysubrc <> 0.
      MESSAGE ‘No reporting manager’ TYPE ‘E’.
    ENDIF.

*    READ TABLE p1001 INDEX 1.
*    lv_sobid1 = p1001-sobid.

    SORT  p1001 BY objid.
    READ TABLE p1001 WITH KEY objid = lv_sobid1
                            otype = ‘O’      “org unit
                            rsign = ‘A’      “hirarchy top down
                            relat = ‘002’    “Manages
                            sclas = ‘O’.    “Position

    IF sysubrc = 0.


      lv_sobid = p1001sobid.
      PERFORM find_manager_pos.

      IF sysubrc = 0.

        PERFORM fetch_man_pernr.
        p_pernr = p1001sobid.

      ENDIF.

    ENDIF.

  ELSE.

    p_pernr = p1001sobid+0(8).

  ENDIF.

ENDFORM.                    ” CHECK_PERNR

*&———————————————————————*
*&      Form  DISP_RESULT
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*

FORM disp_result .

*–Get name of Manager(Supervisor)

  CALL FUNCTION ‘HR_READ_INFOTYPE’

    EXPORTING
      pernr     = p_pernr
      infty     = ‘0002’
    TABLES
      infty_tab = p0002.

  SORT p0002 BY pernr begda.
  READ TABLE p0002 INDEX 1.

  IF NOT p0002[] IS INITIAL.
    FORMAT COLOR 7 .
    SKIP 3.

    WRITE:/1(101) syuline .
    WRITE:/1 syvline,
           2 ‘manager personnel number’,
           30 syvline,
           31 ‘manager first name’ ,
           60 syvline,
           61 ‘manager lastname’,
           101 syvline.

    FORMAT COLOR OFF.      WRITE:/1(101) syuline .

    WRITE:/1 syvline,
           p0002pernr  COLOR 4,
           30 syvline,
           31 p0002vorna COLOR 4,
           60 syvline,
           61  p0002nachn COLOR 4,
           101 syvline.

    WRITE:/1(101) syuline .

  ENDIF.

ENDFORM.                    ” DISP_RESULT

*STEPS.

*1. In the above program first i am finding the organizational unit using the personal number.

*2. After fetching the personal number i am finding the manager of that organization.

*3. After getting the manager position object id i am finding the person who is holding that positon.

To report this post you need to login first.

11 Comments

You must be Logged on to comment or reply to a post.

  1. Hitesh Wankhede

    Hi,

    Nice document.

    But in HR there are lot of standard utilities available for getting manager.

    For example,method ‘GET_MANAGER’ of class ‘CL_HRPAD_MANAGER_UTIL’.

    Please check if it gives the same result.

    (0) 
            1. Raymond Giuseppi

              AFAIK, the class CL_HRPAD_MANAGER_UTIL and function group HRPAD_EXTRACTION were delivered with EA-HRGXX 606 in 2012, so many people can still find interest in your document. 😉

              Regards,

              Raymond

              (0) 

Leave a Reply