2005 Apr 27 9:54 PM
Hi,
I want to do some caculations based on the factory calander. Its like :
date = 04/27/2005.
I want to substract 4 days from this. But in case the new date is a leave day (Saturday/ sunday) then it should return the last working day along with the weekday like monday.
So here its saurday, so it should return 04/22/2005 friday, instead of 04/23/2005 saturday.
Is there a way to do this calculation. Please advise.
Thanks,
2005 Apr 27 10:10 PM
Hi Simi,
You can use Function Module END_TIME_DETERMINE. You can supply a negative number for duration. The default unit is DAY.
Cheers,
Ramki.
2005 Apr 27 11:22 PM
I have used the function module DATE_CONVERT_TO_FACTORYDATE to do this on several occasions. The only stipulation is that the Factory calendar must be maintained.
The function module has a parameter CORRECT_OPTION that you can set to + or -. If this parameter is set to + you input a date and a factory calendar and if the date is not a working day it will return the next working day. If this parameter is set to - and the input date is not a working day then it will return the previous working day.
Thus, in your example you can add the 4 days to the date call the function module and get back the same day if it is a work day or (depending on how you set the parameter) get back either the next work day or the most recent work day.
You could even increment the days in a loop calling the function module for each and advance the days by work days only skipping over holidays and weekends.
Hope this helps,
Brent
2005 Apr 28 7:18 AM
Hi,
Use these function modules
FACTORYDATE_CONVERT_TO_DATE Calendar function: Returns date for a factory calendar date
LAST_FACTORYDATE_GET Calendar function: Return last factory date for a factory calendar
Thanks & Regards,
Judith
2005 Apr 28 7:49 AM
Hi,
You can try this :
&----
*& Form CHECK_FOR_HOLIDAYS
&----
form check_for_holidays_plus using p_cal like scal-fcalid
p_xdate type i
changing p_date like sy-datum.
p_cal is you calendar ID, you have to check in table
SCAL
p_xdate the nb of day you want to add
p_date the result date ( like sy-datum)
data: l_days type i value 1,
l_found.
data: l_attributes like thol occurs 0 with header line.
p_date = sy-datlo.
if p_xdate < 0.
l_days = -1.
endif.
do.
if ( l_days gt p_xdate and p_xdate > 0 ) or
( l_days lt p_xdate and p_xdate < 0 ).
exit.
endif.
if p_xdate > 0.
p_date = p_date + 1.
else.
p_date = p_date - 1.
endif.
call function 'DATE_CONVERT_TO_FACTORYDATE'
exporting
date = p_date
factory_calendar_id = p_cal
importing
workingday_indicator = l_found
exceptions
calendar_buffer_not_loadable = 1
correct_option_invalid = 2
date_after_range = 3
date_before_range = 4
date_invalid = 5
factory_calendar_not_found = 6
others = 7.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
if l_found eq space and p_xdate > 0.
l_days = l_days + 1.
elseif l_found eq space and p_xdate < 0.
l_days = l_days - 1.
else.
clear l_found.
endif.
enddo.
endform. " CHECK_FOR_HOLIDAYS
Hope this helps.
Regards,
Erwan.
2005 May 04 7:32 AM
Hi,
Try this out
*&----
*& Form ADD_WORKING_DAYS
&----
Add n number of factory days(working days) to date
----
<-- P_DAYS Number of days to add
<-- P_PAYDATE Starting date
----
FORM add_working_days USING p_days
CHANGING p_paydate TYPE sy-datum.
DATA: gd_factorydat LIKE scal-facdate,
gd_resdate LIKE sy-datum.
Convert date to factory date
CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
EXPORTING
date = p_paydate "Starting date
factory_calendar_id = 'GB'
IMPORTING
factorydate = gd_factorydat. "Factory calender date
Add n number of days to factory date, ignors non working days
gd_factorydat = gd_factorydat + p_days.
Convert factory date back to actual date
CALL FUNCTION 'FACTORYDATE_CONVERT_TO_DATE'
EXPORTING
factorydate = gd_factorydat
factory_calendar_id = 'GB'
IMPORTING
date = gd_resdate. "Actual date
p_paydate = gd_resdate.
ENDFORM. " ADD_WORKING_DAYS
<b>OR</b>
*&----
*& Form ADD_WORKING_DAYS_RESNONWORK
&----
Add n number of factory days(working days) to date, but allow
resultant date to be a non working day
----
<-- P_DAYS Number of days to add
<-- P_PAYDATE Starting date
----
FORM add_working_days_resnonwork USING p_days
CHANGING p_paydate TYPE sy-datum.
DATA: ld_count TYPE i.
ld_count = p_days.
WHILE ld_count GT 0.
CALL FUNCTION 'DATE_CHECK_WORKINGDAY'
EXPORTING
date = p_paydate
factory_calendar_id = 'GB'
message_type = 'I'
EXCEPTIONS
date_after_range = 1
date_before_range = 2
date_invalid = 3
date_no_workingday = 4
factory_calendar_not_found = 5
message_type_invalid = 6
OTHERS = 7.
IF sy-subrc NE 4.
p_paydate = p_paydate + 1.
ld_count = ld_count - 1.
ELSE.
p_paydate = p_paydate + 1.
ENDIF.
ENDWHILE.
ENDFORM. " ADD_WORKING_DAYS_RESNONWORK
Thanks & Regards,
Judith.