0% found this document useful (0 votes)
89 views

SAP HR ABAP Functions EN

Useful HR ABAP Patterns and Functions Date and Time Functions The month on the date entered; First and last days Working days in the month on the date entered HR Process Functions Management of personnel infotypes (read, write, update)

Uploaded by

Mert
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
89 views

SAP HR ABAP Functions EN

Useful HR ABAP Patterns and Functions Date and Time Functions The month on the date entered; First and last days Working days in the month on the date entered HR Process Functions Management of personnel infotypes (read, write, update)

Uploaded by

Mert
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 11

SAP

HR ABAP
Abstract
This guide explores the integration of HR processes with SAP ABAP, focusing on customizing and
automating HR functions within the SAP environment. It covers key ABAP concepts and techniques
tailored to HR modules, providing practical examples for enhancing data management and
reporting. The document is designed for professionals looking to optimize HR operations using
SAP’s tools.

Mert Bozkurt
[email protected]
HR ABAP FUNCTIONS

Specific to ABAP HR , "Information Type, Organizational Management, Payroll, Time


Management..." We can access functions that are used for such processes and provide
convenience in ABAP directories.

1
Table of contents
Date and Time Functions ........................................................................................................................................... 3
The month on the date entered; First and last days .......................................................................................................... 3
Number of years, months, days between two dates ......................................................................................................... 3
The date of n months later or n months ago .................................................................................................................... 3
Working days in the month on the date entered ............................................................................................................. 4
Last day of the following month ........................................................................................................................................ 4
Last day of the previous month .......................................................................................................................................... 4
HR Process Functions ................................................................................................................................................ 5
Personnel Management ( PA ) ....................................................................................................................................................... 5
Reading personnel information .......................................................................................................................................... 5
Locking down personnel data ............................................................................................................................................. 5
Management of personnel infotypes (read, write, update) ............................................................................................ 5
Unlocking personnel data .................................................................................................................................................... 5
Functions that give dates of entry and exit from work ................................................................................................... 6
Function that returns some types of information .............................................................................................................. 6
Personnel Development (PD) ...................................................................................................................................................................7
Links to the selected Organizational Unit ......................................................................................................................... 7
Information of the selected Organizational Unit ............................................................................................................. 7
Finding the Manager (Hat) of the desired Organization or Upper Organizations ................................................... 8
List of employees in the selected organizational unit ...................................................................................................... 8
Payroll & Salary Calculation ( PY ) ........................................................................................................................................................9
Pulling the Table of Wage Types from the Payroll ........................................................................................................ 9

2
Date and Time Functions

DATA: lv_newdate TYPE datum,


lv_begda TYPE datum,
lv_endda TYPE datum.

"The month on the date entered; First and last days

CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'


EXPORTING
iv_date = sy-datum
IMPORTING
ev_month_begin_date = lv_begda
ev_month_end_date = lv_endda.

"The number of years, months, days between two dates

DATA: lv_years TYPE vtbbewe-atage,


lv_months TYPE vtbbewe-atage,
lv_days TYPE vtbbewe-atage.

CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'


EXPORTING
i_date_from = '19960615'
i_date_to = sy-datum
IMPORTING
e_days = lv_days
e_months = lv_months
e_years = lv_years.

"The date of n months later or n months ago

CALL FUNCTION 'RE_ADD_MONTH_TO_DATE'


EXPORTING
months = -4 "+next/-back value
olddate = sy-datum
IMPORTING
newdate = lv_newdate.

3
"Working days in the month on the date entered
DATA: lt_dates TYPE TABLE OF rke_dat.

CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'


EXPORTING
iv_date = sy-datum
IMPORTING
ev_month_begin_date = lv_begda
ev_month_end_date = lv_endda.

CALL FUNCTION 'RKE_SELECT_FACTDAYS_FOR_PERIOD'


EXPORTING
i_datab = lv_begda
i_datbi = lv_endda
i_factid = 'TR'
TABLES
eth_dats = lt_dates

"Last day of the next month

CALL FUNCTION 'PS_LAST_DAY_OF_NEXT_MONTH'


EXPORTING
day_in = sy-datum
IMPORTING
last_day_of_next_mon = lv_newdate.

"Last day of the previous month

CALL FUNCTION 'OIL_LAST_DAY_OF_PREVIOUS_MONTH'


EXPORTING
i_date_old = sy-datum
IMPORTING
e_date_new = lv_newdate.

4
HR Process Functions

Personnel Administration (PA)

"Personnel information

CALL FUNCTION 'HR_READ_INFOTYPE'


EXPORTING
pernr = lv_pernr
infty = '0001'
begda = sy-datum
endda = sy-datum
TABLES
infty_tab = lt_infty.

"Locking down staff data

DATA: ls_bapireturn TYPE bapireturn.

CALL FUNCTION 'HR_EMPLOYEE_ENQUEUE'


EXPORTING
number = ls_infty-pernr "infty-pernr
IMPORTING
return = ls_bapireturn.

"Management of staff infotypes (read, write, update)

CALL FUNCTION 'HR_INFOTYPE_OPERATION'


EXPORTING
infty = '0001'
number = ls_infty-pernr
record = ls_infty
operation = 'INS' "INS-insert, MOD-update, DEL-delete
IMPORTING
return = ls_bapireturn.

"Unlocking staff data

CALL FUNCTION 'HR_EMPLOYEE_DEQUEUE'


EXPORTING
number = ls_infty-pernr
IMPORTING
return = ls_bapireturn.

5
"Functions that give dates of entry and exit from work

DATA: lv_h_date TYPE pa0001-begda,


lv_f_date TYPE pa0001-begda.
DATA: phifi TYPE TABLE OF phifi.

CALL FUNCTION 'RP_HIRE_FIRE'


EXPORTING
beg = pn-begda
end = pn-endda
IMPORTING
hire_date = lv_h_date
fire_date = lv_f_date
TABLES
pp0000 = p0000 "PNP
pp0001 = p0001 "PNP
pphifi = phifi.

DATA: lo_msg TYPE REF TO if_hrpa_message_handler.

CALL FUNCTION 'HR_ECM_GET_HIRE_DATE'


EXPORTING
pernr = p0000-pernr
message_handler = lo_msg
IMPORTING
hire_date = lv_h_date.

"Function that returns some types of information

DATA: lt_0001 TYPE TABLE OF bapip0001b,


lt_0002 TYPE TABLE OF bapip0002b,
lt_0032 TYPE TABLE OF bapip0032b,
lt_0105 TYPE TABLE OF bapip0105b,
lt_toav TYPE TABLE OF bapitoav0.

CALL FUNCTION 'BAPI_EMPLOYEE_GETDATA'


EXPORTING
employee_id = lv_pernr
TABLES
org_assignment = lt_0001
personal_data = lt_0002
internal_control = lt_0032
communication = lt_0105
archivelink = lt_toav.

6
Personel Development (PD)

"Affiliations of the Selected Organizational Unit

DATA: lt_result TYPE TABLE OF objec.

CALL FUNCTION 'RH_STRUC_GET'


EXPORTING
act_otype = 'O'
act_objid = '50001016'
act_wegid = 'O-O-S-P'
act_plvar = '01'
act_begda = sy-datum
act_endda = sy-datum
TABLES
result_objec = lt_result

"Information of the selected Organizational Unit

CALL FUNCTION 'RH_READ_OBJECT'


EXPORTING
plvar = '01'
otype = 'O'
objid = '50001016'
begda = sy-datum
endda = sy-datum
langu = sy-langu
* IMPORTING
* OBEG =
* OEND =
* OSTAT =
* HISTO =
* SHORT =
* STEXT =
* TISTAT =
* TLANGU =
* DISPLAY_TEXT =
.

7
"Finding the Manager (Hat) of the desired Organization or Upper Organizations
DATA: lt_objec TYPE TABLE OF objec,
lt_manager TYPE TABLE OF objec.

CALL FUNCTION 'RH_PM_GET_STRUCTURE'


EXPORTING
plvar = '01'
otype = 'O'
objid = '50001017' "Başlangıç organizasyonu
begda = sy-datum
endda = sy-datum
wegid = 'O-O' "Uyarlamaya göre bu yol değişebilir
TABLES
objec_tab = lt_objec.

DATA(ls_objec) = lt_objec[ 1 ].
"İstenilen organizasyon alınır veya Tüm organizasyonlar için döngü kurulabilir.

CALL FUNCTION 'RH_PM_GET_STRUCTURE'


EXPORTING
plvar = '01'
otype = 'O'
objid = ls_objec-objid
begda = sy-datum
endda = sy-datum
wegid = 'B012' "Yönetilen pozisyon
authy = space
depth = 0 "Derinlik
TABLES
objec_tab = lt_objec.

ls_objec = lt_objec[ otype = 'S' ].

CALL FUNCTION 'HRCM_ORGUNIT_MANAGER_GET'


EXPORTING
plvar = '01'
otype = 'S'
objid = ls_objec-objid
begda = sy-datum
endda = sy-datum
TABLES
manager_info_table = lt_manager.

"List of employees in the selected organizational unit

DATA: lt_pernr TYPE TABLE OF hrpernr.

CALL FUNCTION 'HRCM_ORGUNIT_EMPLOYEE_LIST_GET'


EXPORTING
plvar = '01'
otype = 'O'
objid = '50001012'
begda = sy-datum
endda = sy-datum
path_id = 'O-S-P'
TABLES
pernr_table = lt_pernr.

8
Payroll (PY)

"Drawing the Table of Wage Types from the Payroll


DATA : lt_rgdir TYPE STANDARD TABLE OF pc261,
lv_molga TYPE molga,
lv_fpper TYPE spmon.
DATA : ls_payresulttr TYPE paytr_result.

CALL FUNCTION 'CU_READ_RGDIR'


EXPORTING
persnr = lv_pernr
IMPORTING
molga = lv_molga
TABLES
in_rgdir = lt_rgdir
EXCEPTIONS
no_record_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
RETURN.
ENDIF.

DATA(ls_rgdir) = VALUE
#( lt_rgdir[ payty = space srtza = 'P' fpper = lv_fpper ] OPTIONAL ).

IF ls_rgdir IS INITIAL.
ls_rgdir = VALUE
#( lt_rgdir[ payty = space srtza = 'A' fpper = lv_fpper ] OPTIONAL ).
IF sy-subrc <> 0.
RETURN.
ENDIF.
ENDIF.

FIELD-SYMBOLS: <fs_result> TYPE any.


ASSIGN ls_payresulttr TO <fs_result>.

CALL FUNCTION 'PYXX_READ_PAYROLL_RESULT'


EXPORTING
employeenumber = lv_pernr
sequencenumber = ls_rgdir-seqnr
check_read_authority = 'X'
CHANGING
payroll_result = <fs_result>
EXCEPTIONS
illegal_isocode_or_clusterid = 1
error_generating_import = 2
import_mismatch_error = 3
subpool_dir_full = 4
no_read_authority = 5
no_record_found = 6
versions_do_not_match = 7
OTHERS = 8.
IF sy-subrc <> 0.
RETURN.
ENDIF.

FIELD-SYMBOLS <rt> TYPE hrpay99_rt.


FIELD-SYMBOLS <inter> TYPE pay99_international.
ASSIGN COMPONENT 'INTER' OF STRUCTURE ls_payresulttr TO <inter>.
ASSIGN COMPONENT 'RT' OF STRUCTURE <inter> TO <rt>.

9
10

You might also like