SAP HCM ABAP FUNC
From SapWiki
ejemplo función HR (PE04)
form fuz_45.
constants: lc_max_no_of_read type i value 12. "maximum of payroll
" "results to be read for calculation of outpayments
data: lt_rgdir type hrpy_tt_rgdir, "GWY839032
ls_rgdir type line of hrpy_tt_rgdir,
ls_result type pay99_result,
ls_v0 like line of ls_result-inter-v0,
ls_rt like line of ls_result-inter-rt,
lv_relid like pcl2-relid,
lv_molga like t500l-molga,
ls_t500l like t500l,
lv_current_pcurrency type waers, "payroll currency of last result
lv_prior_paycurrency type waers, "payroll currency of older results
lv_begda_processed_res type fpbeg,
lv_amount like q0045-darbt,
lv_paycu like q0045-paycu,
ls_paper type pc2paper,
lf_payment_value_date type datum,
ls_loid_33 type pclo_id, "Note 834827
lv_subrc type sysubrc,
lv_numrg type i,
lv_loan_begda type q0045-begdaf, "begin of loan
lflag_loan_exists type abap_bool, "a loan was processed in the period
lv_num_processed_res type i, "number of already processed results
lt_outpay_wt type standard table of t506w,
ls_outpay_wt like line of lt_outpay_wt,
lt_outpay_wt_range type range of lgart,
ls_outpay_wt_range like line of lt_outpay_wt_range.
data: ls_ot type pc207,
ls_it type pc207.
refresh ot[].
* read payroll directory and remove P, O and voided results
* (i.e. only keep actual results)
* don't read archived results; archived data is not to be evaluated
call function 'CU_READ_RGDIR_NEW'
exporting
persnr = pernr-pernr
check_read_authority = space
importing
molga = lv_molga
tables
in_rgdir = lt_rgdir
exceptions
no_record_found = 1
no_read_authority = 2
others = 4.
if sy-subrc <> 0. "no error if there is no record or no authority
return. "from this method
endif.
*Necesitamos que la función lea la RT de la ultima nomina regular. Es la de indicador P, sin motivo.
loop at lt_rgdir transporting no fields
where void = abap_true
or payty <> space
or srtza <> 'P'.
delete lt_rgdir index sy-tabix.
endloop.
sort lt_rgdir descending by seqnr.
describe table lt_rgdir lines lv_numrg.
* get relid
select single * from t500l
into ls_t500l
where molga = lv_molga.
move ls_t500l-relid to lv_relid.
read table lt_rgdir into ls_rgdir index 1.
if sy-subrc <> 0.
return.
endif.
call function 'PYXX_READ_PAYROLL_RESULT'
exporting
clusterid = lv_relid
employeenumber = pernr-pernr
sequencenumber = ls_rgdir-seqnr
read_only_international = 'X'
check_read_authority = ' '
changing
payroll_result = ls_result
exceptions
others = 1.
if sy-subrc <> 0.
return. "exit this method
endif.
lv_num_processed_res = lv_num_processed_res + 1.
"Note 834827
lv_current_pcurrency = ls_result-inter-versc-waers.
* get loan result for current loan id
loop at ls_result-inter-v0 into ls_v0 where v0typ = 'L'.
* if ls_v0-vinfo+0(4) = pf_dlart
* and ls_v0-vinfo+4(2) = pf_objps.
loop at ls_result-inter-rt into ls_rt
where v0typ = 'L'
and v0znr = ls_v0-v0znr
and ( lgart = '/LCI' or lgart = '/LLB' ).
if ls_rt-betrg = 0. "this is a potential period
"here the loan is already paid back completely
lv_subrc = 1. "this is equal to that no /LLB exists
* exit. "the loop and check previous period
else.
* pfx_opelo = ls_rt-betrg.
MOVE-CORRESPONDING ls_rt to ls_ot.
append ls_ot to ot.
endif.
endloop. "at RT
*
* endif. "for loan-id
endloop. "at loan-
* Fill IT from OT
loop at ot into ls_it.
if sw_prot eq 'X'.
perform log_wage_type in program h39plog0
using ls_it
calc_currency
changing ptext[].
endif.
collect ls_it into it..
endloop.
refresh ot[].
endform.