HR-copy of fetching HR data in different ways

Source: Internet
Author: User

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 shoshould include the date parameters for fetching the data. see this simple example to understand 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 = '000000'
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: pernr like pa0001-pernr.
*&---------------------------------------------------------------------*
* Start of Selection
*&---------------------------------------------------------------------*
Start-of-selection.
Call function 'rh _ read_infty'
Exporting
Plvar = '01'
Otype = 'P'
Objid = pernr
Infty = '000000'
Subty = 'b008'
Begda = sy-Datum
Endda = sy-Datum
Tables
Innnn = T1001.
Sort T1001 by begda descending.
Read Table T1001 with key objid = 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 = '000000'
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 = '000000'
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 = '000000'
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: 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 = 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.
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.

 

Source link: http://wiki.sdn.sap.com/wiki/display/Snippets/Copy+of+fetching+hr+data+in+different+ways

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.