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 hrp1001-objid.
DATA: lv_sobid1 TYPE hrp1001-objid.
PARAMETERS: p_pernr TYPE p_pernr.
PERFORM find_org.
IF sy-subrc = 0.
lv_sobid = p0001-orgeh.
lv_sobid1 = p0001-orgeh.
PERFORM find_manager_pos.
IF sy-subrc = 0.
PERFORM fetch_man_pernr.
IF sy-subrc = 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 sy-subrc <> 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 = sy-datum
endda = sy-datum
TABLES
innnn = p1001
EXCEPTIONS
all_infty_with_subty = 1
nothing_found = 2
no_objects = 3
wrong_condition = 4
wrong_parameters = 5
OTHERS = 6.
IF sy-subrc <> 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 = p1001-sobid.
*-- Get Personnel number for the Manager
CALL FUNCTION 'RH_READ_INFTY'
EXPORTING
plvar = '01'
otype = 'S'
objid = lv_sobid
infty = '1001'
subty = 'A008'
begda = sy-datum
endda = sy-datum
TABLES
innnn = p1001
EXCEPTIONS
all_infty_with_subty = 1
nothing_found = 2
no_objects = 3
wrong_condition = 4
wrong_parameters = 5
OTHERS = 6.
IF sy-subrc <> 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 = p1001-sobid+0(8).
*-- Get the Org unit
CALL FUNCTION 'RH_READ_INFTY'
EXPORTING
plvar = '01'
otype = 'O'
objid = lv_sobid1
infty = '1001'
subty = 'A002'
begda = sy-datum
endda = sy-datum
TABLES
innnn = p1001
EXCEPTIONS
all_infty_with_subty = 1
nothing_found = 2
no_objects = 3
wrong_condition = 4
wrong_parameters = 5
OTHERS = 6.
IF sy-subrc <> 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 sy-subrc = 0.
lv_sobid = p1001-sobid.
PERFORM find_manager_pos.
IF sy-subrc = 0.
PERFORM fetch_man_pernr.
p_pernr = p1001-sobid.
ENDIF.
ENDIF.
ELSE.
p_pernr = p1001-sobid+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) sy-uline .
WRITE:/1 sy-vline,
2 'manager personnel number',
30 sy-vline,
31 'manager first name' ,
60 sy-vline,
61 'manager lastname',
101 sy-vline.
FORMAT COLOR OFF. WRITE:/1(101) sy-uline .
WRITE:/1 sy-vline,
2 p0002-pernr COLOR 4,
30 sy-vline,
31 p0002-vorna COLOR 4,
60 sy-vline,
61 p0002-nachn COLOR 4,
101 sy-vline.
WRITE:/1(101) sy-uline .
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
25 | |
5 | |
4 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 |