Google Search - Blog...........

HR ABAP - Retrieve Manager For An Employee.


In order to get the Manager or Supervisor we need to get the position and organization unit of the manager for the person entered on the selection screen by using the certain relations from the hrp1001 with the below fields:

objid----Object ID
otype----Object Type ( O-->org unit S-->position P-->persion )
rsign----Relationship Specification ( A-->bottom up B-->top down )
relat----Relationship Between Objects ( 002--->Reports to
003--->Belongs to
008--->Holder
012--->Manages)
sclas----Type of Related Object ( O-->org unit S-->position P-->persion c-->job)
sobid----ID of Related Object


Then we need to get the personnel number from that we need to get the details
of the manager by the infotype PA0002 by passing Personnel number.

----------------------------------------------------------------------------------

REPORT ygetsupervisor MESSAGE-ID zmsg.

&---------------------------------------------------------------------

database tables used
&---------------------------------------------------------------------
TABLES:pa0001, "Infotype 0001 (Org. Assignment)
hrp1001, "Infotype 1001
pa0002. "Infotype 0002 (Personal Data)
&---------------------------------------------------------------------


"Internal tables declaration
&---------------------------------------------------------------------
*----internal tables for holding
DATA: t1001 LIKE p1001 OCCURS 0 WITH HEADER LINE,
t1002 LIKE p1001 OCCURS 0 WITH HEADER LINE,
t1003 LIKE p1001 OCCURS 0 WITH HEADER LINE,
t1004 LIKE p1001 OCCURS 0 WITH HEADER LINE,
t0001 LIKE p0001 OCCURS 0 WITH HEADER LINE,
t0002 TYPE p0002 OCCURS 0 WITH HEADER LINE.
&---------------------------------------------------------------------


"Variable declaration
&---------------------------------------------------------------------
*---0 to capture the id of the object "may be orgunit, position, persion.
DATA: g_sobid1 LIKE p1001-objid,
g_sobid2 LIKE p1001-objid,
g_sobid3 LIKE p1001-objid,
*--to capture the personnel number
g_pernr LIKE pa0002-pernr.

&---------------------------------------------------------------------

selection screen paramters
&---------------------------------------------------------------------
*----enter a valid personnel number
PARAMETERS:p_pernr LIKE pa0002-pernr.

&---------------------------------------------------------------------

start of selection
&---------------------------------------------------------------------

START-OF-SELECTION.
*Get the Position for entered Personnel number.
*----RH_READ_INFTY function module is used for the OM info-types . starting with HRP

CALL FUNCTION 'RH_READ_INFTY'
EXPORTING
plvar = '01'
otype = 'P'
objid = p_pernr
infty = '1001'
subty = 'B008'
begda = sy-datum
endda = sy-datum
TABLES
innnn = t1001
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 i000 WITH 'this number is not maintained in hrp1001'.
ENDIF.


"Get the latest record reading T1001 with following values.
SORT t1001 BY begda DESCENDING .

READ TABLE t1001 WITH KEY objid = p_pernr "personnel number
otype = 'P' "Person
rsign = 'B' "hirarchy top down
relat = '008' "Holder
sclas = 'S'. "Position

IF NOT t1001[] IS INITIAL.

g_sobid1 = t1001-sobid. "ID of Related Object


"Get Org unit for the position obtained from above
CALL FUNCTION 'RH_READ_INFTY'
EXPORTING
plvar = '01'
otype = 'S'
objid = g_sobid1
infty = '1001'
subty = 'A003'
begda = sy-datum
endda = sy-datum
TABLES
innnn = t1002.
ENDIF.

SORT t1002 BY begda DESCENDING .
READ TABLE t1002 WITH KEY objid = g_sobid1
otype = 'S' "Position
rsign = 'A' "bottom up
relat = '003' "Belongs to
sclas = 'O'. "org unit

IF NOT t1002[] IS INITIAL.

g_sobid2 = t1002-sobid.


"Get position for the Org unit (Manager)
CALL FUNCTION 'RH_READ_INFTY'
EXPORTING
plvar = '01'
otype = 'O'
objid = g_sobid2
infty = '1001'
subty = 'B012'
begda = sy-datum
endda = sy-datum
TABLES
innnn = t1003.

ENDIF.

SORT t1003 BY objid.

READ TABLE t1003 WITH KEY objid = g_sobid2
otype = 'O' "org unit
rsign = 'B' "hirarchy top down
relat = '012' "Manages
sclas = 'S'. "Position

IF NOT t1003[] IS INITIAL.

g_sobid3 = t1003-sobid.



"Get Personnel number for the Manager
CALL FUNCTION 'RH_READ_INFTY'
EXPORTING
plvar = '01'
otype = 'S'
objid = g_sobid3
infty = '1001'
subty = 'A008'
begda = sy-datum
endda = sy-datum
TABLES
innnn = t1004.
ENDIF.

READ TABLE t1004 WITH KEY objid = g_sobid3
otype = 'S' "Position
rsign = 'A' "bottom up
relat = '008' "Holder
sclas = 'P'. "Person
IF NOT t1004[] IS INITIAL.

g_pernr = t1004-sobid+0(8).


*--Get name of Manager(Supervisor)

CALL FUNCTION 'HR_READ_INFOTYPE'
EXPORTING
pernr = g_pernr
infty = '0002'
TABLES
infty_tab = t0002.

SORT t0002 BY pernr begda.

READ TABLE t0002 INDEX 1.

IF NOT t0002[] 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 t0002-pernr COLOR 4,
30 sy-vline,
31 t0002-vorna COLOR 4,
60 sy-vline,
61 t0002-nachn COLOR 4,
101 sy-vline.

WRITE:/1(101) sy-uline .

ENDIF.
ENDIF.



ALSO READ:

- Generate Compensation Statement Report.

- Fetch HR Data Or Records From HR Database Tables.

- Using Macros In HR ABAP Report Program.

- Get The List Of Employees With Experience.

- BADI HRECM00_BDG0001 - Upload Initial Budgets From Excel Sheet.

.....Back To Sub-Index On HR ABAP.

.....Back To MAIN INDEX.



No comments:

Post a Comment