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

Showing posts with label fm rh_read_infty. Show all posts
Showing posts with label fm rh_read_infty. Show all posts

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.



ABAP - Fetching HR Data In Different Ways.

There are 3 methods in fetching the data from HR database tables .

1.Using select statements .

This is the simple method for the selection of data from the hr tables(pannnn). in the HR data time is the major component , in the where condition we should include the date parameters for fetching the data .see this example

REPORT ZHRTESTS.

tables:pa0002 .

data:begin of itab occurs 0,
pernr like pa0002-pernr,
begda like pa0002-begda,
endda like pa0002-endda,
vorna like pa0002-vorna,
nachn like pa0002-nachn,
end of itab .

select-options:s_pernr for pa0002-pernr ,
s_date for sy-datum.

start-of-selection .


select pernr
begda
endda
vorna
nachn
from pa0002
into table itab
where pernr in s_pernr
and begda le s_date-high
and endda ge s_date-low.

if not itab[] is initial.
loop at itab .
write:/ itab-pernr,
itab-begda,
itab-endda,
itab-vorna,
itab-nachn .
endloop.
endif.

2. Using Different Function Modules..

1. Using Function Module hr_read_infotype

This function module is used for fetching the data from Personnel Administration and Time management info types . This is used to get a single PERNR from the Info type .see the below example....


REPORT ZHRTESTS.

tables:pa0002 .

data: itab type p0002 occurs 0 with header line .

select-options:s_pernr for pa0002-pernr no intervals no-extension,
s_date for sy-datum.

start-of-selection .


CALL FUNCTION 'HR_READ_INFOTYPE'
EXPORTING
TCLAS = 'A'
pernr = s_pernr-low
infty = '0002'
BEGDA = s_date-low
ENDDA = s_date-high
TABLES
infty_tab = itab.

if not itab[] is initial.
loop at itab .
write:/ itab-pernr,
itab-begda,
itab-endda,
itab-vorna,
itab-nachn .
endloop.
endif.

2. Using Function Module rh_read_infty

This is used for the organization management info types. With this function module we can get the relations for the given object ( means we can get position for a pernr , organization for a position , organization for an organization....)


report ygetsupervisor.

*&---------------------------------------------------------------------*
* database tables used
*&---------------------------------------------------------------------*
tables:pa0001,
hrp1001,
pa0002.
*&---------------------------------------------------------------------*
* internal tables declaration
*&---------------------------------------------------------------------*

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,
it_pa0002 type pa0002 occurs 0 with header line.
*&---------------------------------------------------------------------*
* variable declaration
*&---------------------------------------------------------------------*
data: v_sobid1 like p1001-objid,
v_sobid2 like p1001-objid,
v_sobid3 like p1001-objid,
v_pernr like pa0002-pernr.

*&---------------------------------------------------------------------*
* selection screen paramters
*&---------------------------------------------------------------------*
parameters:p_pernr like pa0001-pernr.

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

start-of-selection.


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 .


sort t1001 by begda descending .

read table t1001 with key objid = p_pernr
otype = 'P'
rsign = 'B'
relat = '008'
sclas = 'S'.

if sy-subrc = 0.

v_sobid1 = t1001-sobid.

call function 'RH_READ_INFTY'
exporting
plvar = '01'
otype = 'S'
objid = v_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 = v_sobid1
otype = 'S'
rsign = 'A'
relat = '003'
sclas = 'O'.

if sy-subrc = 0.

v_sobid2 = t1002-sobid.

call function 'RH_READ_INFTY'
exporting
plvar = '01'
otype = 'O'
objid = v_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 = v_sobid2
otype = 'O'
rsign = 'B'
relat = '012'
sclas = 'S'.

if sy-subrc = 0.

v_sobid3 = t1003-sobid.

call function 'RH_READ_INFTY'
exporting
plvar = '01'
otype = 'S'
objid = v_sobid3
infty = '1001'
subty = 'A008'
begda = sy-datum
endda = sy-datum
tables
innnn = t1004 .

endif.

read table t1004 with key objid = v_sobid3
otype = 'S'
rsign = 'A'
relat = '008'
sclas = 'P'.
if sy-subrc = 0.

v_pernr = t1004-sobid+0(8).

select pernr
vorna
nachn
cname
from pa0002
into corresponding fields of table it_pa0002
where pernr = v_pernr.

sort it_pa0002 by pernr begda.

read table it_pa0002 index 1.

if sy-subrc eq 0.
write:/ it_pa0002-pernr,it_pa0002-vorna,it_pa0002-nachn,it_pa0002-cname.
endif.
endif.

3. Using Function Module rh_struc_get

This is used to get the higher organization unit for the given personnel no. This is easier way for getting the highest org unit for a given pesonnel no or for a given org.unit ..

REPORT ZHRTESTS.

PARAMETERS:P_OBJID TYPE OBJID.

DATA:RESULT_OBJEC TYPE OBJEC OCCURS 0 WITH HEADER LINE ,
RESULT_OBJEC1 TYPE OBJEC OCCURS 0 WITH HEADER LINE ,
V_OBJID1 TYPE OBJID .

*---here we will get the organization unit for the given pesonnel number.

CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = 'P'
act_objid = p_objid
act_wegid = 'P-S-O' " person-position-orgunit
TABLES
RESULT_OBJEC = RESULT_OBJEC.


LOOP AT RESULT_OBJEC WHERE OTYPE = 'O'.

*--- loop the orgunits only to get the higher orgunits

V_OBJID1 = RESULT_OBJEC-OBJID.


CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = 'O'
act_objid = V_OBJID1
act_wegid = 'O-O'
TABLES
RESULT_OBJEC = RESULT_OBJEC1 .


LOOP AT RESULT_OBJEC1.
ENDLOOP.
*----this is the highest orgunit for the Personnel number
WRITE:/ RESULT_OBJEC1-OBJID.
ENDLOOP.


3. Using Logical Databases (Macros).
Here i am using the PNP logical database for this example . And I am using the macros for getting the data from the databases .

REPORT ZHRTESTS.

TABLES: PERNR.

INFOTYPES: 0002.
GET PERNR.

*---get the first record for the pernr from the infotype
RP_PROVIDE_FROM_FRST P0002 SPACE PN-BEGDA PN-ENDDA .

IF PNP-SW-FOUND eq 1.
WRITE: / PERNR-PERNR,
PN-BEGDA,
PN-ENDDA,
P0002-VORNA,
P0002-NACHN,
P0002-GBDAT.
ENDIF.

*---get the last record for the pernr from the infotype
RP_PROVIDE_FROM_LAST P0002 SPACE PN-BEGDA PN-ENDDA.

IF PNP-SW-FOUND eq 1.
WRITE: / PERNR-PERNR,
PN-BEGDA,
PN-ENDDA,
P0002-VORNA,
P0002-NACHN,
P0002-GBDAT.
ENDIF.





ALSO READ:

- Get Managers List For All The Organization Units.

- Get Employees List Working Under An Organization Unit.

- Retrieve Manager For An Employee.

- Generate Compensation Statement Report.

- Fetch HR Data Or Records From HR Database Tables.

- Using Macros In HR ABAP Report Program.

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

.....Back To MAIN INDEX.



HR ABAP - Get The Manager Of The Employee

*&---------------------------------------------------------------------*
*& Report ZSUP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZSUP.
TABLES:PA0001,
HRP1001,
PA0002.

DATA: T1001 LIKE P1001 OCCURS 0 WITH HEADER LINE.
DATA: T1002 LIKE P1001 OCCURS 0 WITH HEADER LINE.
DATA: T1003 LIKE P1001 OCCURS 0 WITH HEADER LINE.
DATA: T1004 LIKE P1001 OCCURS 0 WITH HEADER LINE.
DATA: T0001 LIKE P0001 OCCURS 0 WITH HEADER LINE.
DATA: IT_PA0002 TYPE PA0002 OCCURS 0 WITH HEADER LINE.

DATA: V_SOBID1 LIKE P1001-OBJID.
DATA: V_SOBID2 LIKE P1001-OBJID.
DATA: V_SOBID3 LIKE P1001-OBJID.

DATA:V_PERNR LIKE PA0002-PERNR.

PARAMETERS:P_PERNR LIKE PA0001-PERNR.

START-OF-SELECTION.

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.

SORT T1001 BY BEGDA DESCENDING .

READ TABLE T1001 WITH KEY OBJID = P_PERNR
OTYPE = 'P'
RSIGN = 'B'
RELAT = '008'
SCLAS = 'S'.

IF SY-SUBRC = 0.

V_SOBID1 = T1001-SOBID.

CALL FUNCTION 'RH_READ_INFTY'
EXPORTING
PLVAR = '01'
OTYPE = 'S'
OBJID = V_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 = V_SOBID1
OTYPE = 'S'
RSIGN = 'A'
RELAT = '003'
SCLAS = 'O'.

IF SY-SUBRC = 0.

V_SOBID2 = T1002-SOBID.

CALL FUNCTION 'RH_READ_INFTY'
EXPORTING
PLVAR = '01'
OTYPE = 'O'
OBJID = V_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 = V_SOBID2
OTYPE = 'O'
RSIGN = 'B'
RELAT = '012'
SCLAS = 'S'.

IF SY-SUBRC = 0.

V_SOBID3 = T1003-SOBID.

CALL FUNCTION 'RH_READ_INFTY'
EXPORTING
PLVAR = '01'
OTYPE = 'S'
OBJID = V_SOBID3
INFTY = '1001'
SUBTY = 'A008'
BEGDA = SY-DATUM
ENDDA = SY-DATUM
TABLES
INNNN = T1004.

ENDIF.

READ TABLE T1004 WITH KEY OBJID = V_SOBID3
OTYPE = 'S'
RSIGN = 'A'
RELAT = '008'
SCLAS = 'P'.
IF SY-SUBRC = 0.

V_PERNR = T1004-SOBID+0(8).

SELECT PERNR
VORNA
NACHN
CNAME
FROM PA0002
INTO CORRESPONDING FIELDS OF TABLE IT_PA0002
WHERE PERNR = V_PERNR.

SORT IT_PA0002 BY PERNR BEGDA.

READ TABLE IT_PA0002 INDEX 1.

IF SY-SUBRC EQ 0.
WRITE:/ IT_PA0002-PERNR,
IT_PA0002-VORNA,
IT_PA0002-NACHN,
IT_PA0002-CNAME.
ENDIF.
ENDIF.


ALSO READ:

- Creating An HR Infotype Step By Step.

- Creating HR Report Category In PNP Logical Database.

- Fetching The Entry Or Joining Date For Employees.

- Fetching HR Data In Different Ways.

- Get Managers List For All The Organization Units.

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

.....Back To MAIN INDEX.