08-28-2007 8:14 PM
Dear Abapers,
I have to calculate the working days (ie days which are not OFF) between two dates for the employees.
Is there any function to achieve that? any advice will be greatly appreciated & rewarded.
Thanks in advance,
Fede.
08-28-2007 8:20 PM
You can use this FM RKE_SELECT_FACTDAYS_FOR_PERIOD.
data: begin of itab occurs 0.
include structure RKE_DAT.
data: end of itab.
data: wa_num type i.
CALL FUNCTION 'RKE_SELECT_FACTDAYS_FOR_PERIOD'
EXPORTING
i_datab = start_date
i_datbi = end_date
i_factid = '01'
TABLES
eth_dats = itab.
describe table itab lines wa_num.
write: / 'Working days between two periods is', wa_num.
08-28-2007 8:16 PM
Federico,
Use FM <b>RKE_SELECT_FACTDAYS_FOR_PERIOD</b>
Regards
Aneesh.
08-28-2007 8:23 PM
Guys, thanks a lot for your time, but I think I didnt explain myself very well.
The days I need depends on the planned working time of each employee (ie its work schedule rule), because an employee could work from sunday through friday, and other from monday through wednesday, and then they have diffentes amount of days OFFs between two given dates
Hope I was clear enough
08-28-2007 8:30 PM
HI,
Where you store this working schedule.. what every code that we have send works on factory calender, which considers monday to friday as working days.
what you can do is .. get the working scheduel for the employee from that table.. then pass the schedule to this function module and it will return you the working days...
Thanks
Mahesh
08-28-2007 8:32 PM
Federico,
Try this, but I am not sure it works. Just give it a try
data: it_ptpsp type standard table of t_ptpsp initial size 0,
wa_ptpsp type t_ptpsp.
CALL FUNCTION 'HR_PERSONAL_WORK_SCHEDULE'
EXPORTING
pernr = pernr-pernr
begda = pn-begda
endda = pn-endda
* KUG =
* REFRESH = 'X'
* WORKING_HOURS = 'X'
* SWITCH_ACTIV =
* MODIFY_ENTRIES = 'X'
* I0001_I0007_ERROR = '0'
* READ_CLUSTER =
IMPORTING
warning_occured = gd_warning
TABLES
* I0000 =
* I0001 =
* I0002 =
* I0007 =
* I0049 =
* I2001 =
* I2002 =
* I2003 =
perws = it_ptpsp "Stores employees work schedule
* I0003 =
EXCEPTIONS
error_occured = 1
abort_occured = 2
OTHERS = 3.
08-28-2007 8:34 PM
Working schedule is stored in infotype 0007, table PA0007, field SCHKZ; the code you kindly gave to me considers monday to friday as working days, but not all employees follow that schedule, some of the employees in my company work 6 times a week (so that they have only 1 day OFF) and others work 4 days a week and the like.
08-28-2007 8:53 PM
08-28-2007 8:55 PM
08-28-2007 9:00 PM
HI,
What is that you are trying to find out.. the total working days in a month or a year . or between any two dates...
Thansk
mahesh
08-28-2007 9:11 PM
08-28-2007 9:30 PM
Ok..
what you have to do is.
select the Work Schedule Rule from PA0007 for a employee .
case v_schedule
when 'STANDARD'.
use the code that we have already sent you.
when 'ESP_0102' " this will tell you on what days a person will work.
let us say he works from monday through wed..day.
let us say start date is today... and i want to calculate the total number of working days for this guy till sept 15.
data : lv_startdate type sy-datum,
lv_enddate type sy-datum,
lv_tempdate type sy-datum.
data : lv_workdays type i.
lv_startdate = sy-datum.
lv_tempdate = sy-datum + 7.
call function DAY_ATTRIBUTES_GET and pass lv_startdate and lv_enddate it will return the details of the week.. mon , tue , wen, thru, as we know he starts on monday ..
say read table where WE = 'MO'.
this table will have the start date..so ur start date wold be
lv_startdate = itab-date.
and end date would be
lv_enddate = lv_startdate + 4.
while lv_enddate <= sept15.
data: begin of itab occurs 0.
include structure RKE_DAT.
data: end of itab.
data: wa_num type i.
CALL FUNCTION 'RKE_SELECT_FACTDAYS_FOR_PERIOD'
EXPORTING
i_datab = start_date
i_datbi = end_date
i_factid = '01'
TABLES
eth_dats = itab.
describe table itab lines wa_num.
lv_workingdays = wa_num + lv_workingdays.
lv_startdate = lv_startdate + 6.
lv_enddate = lv_enddate + 6.
endwhile.
here lv_workingdays will have the no of working days for a employe..
like this you have to do for each and every type of possible work Schedule rule
08-28-2007 10:12 PM
Thanks a lot dude for your time, i tried it but it didnt work as I expected.
08-28-2007 10:16 PM
I am sure you play around with this logic... nothing beyond this.. i am sure.. where do you think this will not work.. i dont see y this will not work ... let me know what exactly u r not getting...
08-28-2007 11:23 PM
Your logic is quite nice Mahesh, thats for sure, the problem is that you are assumming that all works schedule have the same scheduling every week, and that is not true because there are some rotating works schedule wich changes the scheduling weekly, so I cant put the logic in a case statement as you kindly suggested.
Best regards.
08-28-2007 8:19 PM
08-28-2007 8:20 PM
You can use this FM RKE_SELECT_FACTDAYS_FOR_PERIOD.
data: begin of itab occurs 0.
include structure RKE_DAT.
data: end of itab.
data: wa_num type i.
CALL FUNCTION 'RKE_SELECT_FACTDAYS_FOR_PERIOD'
EXPORTING
i_datab = start_date
i_datbi = end_date
i_factid = '01'
TABLES
eth_dats = itab.
describe table itab lines wa_num.
write: / 'Working days between two periods is', wa_num.
08-28-2007 8:21 PM
REPORT ZTEST NO STANDARD PAGE HEADING LINE-COUNT 65
LINE-SIZE 132
MESSAGE-ID ZZ.
PARAMETER : P_DATE LIKE SY-DATUM.
data: it_holidays like iscal_day occurs 0 with header line.
DATA: T_DATE LIKE SY-DATUM.
data : x_date(4) type c.
data: cnt type i.
REFRESH : IT_HOLIDAYS.
CLEAR : IT_HOLIDAYS.
T_DATE = SY-DATUM.
CALL FUNCTION 'HOLIDAY_GET'
EXPORTING
HOLIDAY_CALENDAR = 'US'
FACTORY_CALENDAR = ' '
DATE_FROM = P_DATE
DATE_TO = T_DATE
IMPORTING
YEAR_OF_VALID_FROM =
YEAR_OF_VALID_TO =
RETURNCODE =
TABLES
HOLIDAYS = IT_HOLIDAYS
EXCEPTIONS
FACTORY_CALENDAR_NOT_FOUND = 1
HOLIDAY_CALENDAR_NOT_FOUND = 2
DATE_HAS_INVALID_FORMAT = 3
DATE_INCONSISTENCY = 4
OTHERS = 5.
cnt = 0.
loop at it_holidays.
write 😕 it_holidays.
cnt = cnt + 1.
endloop.
x_date = t_date - p_date - cnt.
write 😕 'No of working days are' , x_date.
08-28-2007 10:14 PM
Dear all, I made myself a program to achieve my need, because I didnt find any function to do it, I will share what I coded, may be it could be useful for anyone else:
REPORT zphr_working_days.
PARAMETER p_fechad LIKE sy-datum OBLIGATORY.
PARAMETER p_fechah LIKE sy-datum OBLIGATORY.
PARAMETER p_pernr LIKE pa0007-pernr OBLIGATORY.
TABLES t552a.
DATA wa_t552a LIKE t552a.
DATA anio LIKE t552a-kjahr.
DATA mes LIKE t552a-monat.
DATA dia LIKE t552a-monat.
DATA v_fecha LIKE sy-datum.
DATA v_pht LIKE pa0007-schkz.
data v_wdays type i.
DATA wa_duration LIKE psen_duration_dec.
* Data para los punteros
FIELD-SYMBOLS: <v_symb_ttp>.
DATA v_field_ttp(14) TYPE c.
FIELD-SYMBOLS: <v_symb_tpr>.
DATA v_field_tpr(14) TYPE c.
v_wdays = 0.
v_fecha = p_fechad.
WHILE v_fecha <= p_fechah.
select single schkz
into v_pht
from pa0007
where pernr = p_pernr
and begda <= v_fecha
and endda >= v_fecha.
if sy-subrc = 0.
* Recupero el anio, mes y día
anio = v_fecha+0(4).
mes = v_fecha+4(2).
dia = v_fecha+6(2).
SELECT SINGLE *
FROM t552a
INTO wa_t552a
WHERE zeity = '1'
AND mofid = 'PR'
AND mosid = '10'
AND schkz = v_pht
AND kjahr = anio
AND monat = mes.
CONCATENATE 'WA_T552A-TTP' dia INTO v_field_ttp.
ASSIGN (v_field_ttp) TO <v_symb_ttp>.
CONCATENATE 'WA_T552A-TPR' dia INTO v_field_tpr.
ASSIGN (v_field_tpr) TO <v_symb_tpr>.
if ( <v_symb_ttp> eq ' ' OR
<v_symb_ttp> eq 0 ) AND
<v_symb_tpr> ne 'OFF'.
add 1 to v_wdays.
endif.
endif.
* Incrementamos el día en uno
add 1 to v_fecha.
ENDWHILE.
write: / 'PHT:' , v_pht , 'working days:' , v_wdays .
I know it is not performant at all, Im far of being an abaper,
Best regards