2006 Jan 27 12:09 AM
Hi,
Is there any function available to calculate the number of working days between two dates based on the factory calendar. I know there is a function to check if a particular day is working or not.
Regards
Rani
2006 Jan 27 12:21 AM
Hi Rani,
I don't think there is one.. but you can put the dates in a loop , call FVD_MD_TOOLS_CHECK_WORKDAY and increment a counter for each workday to obtain the number of work days.
Regards,
Suresh Datti
2006 Jan 27 12:25 AM
Thanks..i could think of doing it that way...was on the look out for a nicer way
2006 Jan 27 1:19 AM
Unfortunately there is no single function module that gives you this information. Use HOLIDAY_GET function module by passing your two dates and the factory calendar. Count the number of rows returned in the holiday internal table. Calculate the number of days between the two dates by simply subtracting from_date from to_date. Now the difference between the total number of days minus the number of holidays is your total number of work days. This is easier to do than looping.
Srinivas
2024 May 24 1:51 PM
Hello, the problem with this is that it will include weekends and bank holidays, which are not working days. We need to count the number of weekdays between two dates.
2006 Jan 27 4:52 AM
Hi,
i think you need to create your FM to do that, or you need to call the FM in side the loop of a date table and capture the data.
regards
vijay
2006 Jan 27 6:14 AM
Hi,
Check this FM and kindly reward points by clicking the star on the left of reply,if it helps.
Use the function module
WDKAL_DATE_ADD_FKDAYS
to get the No of working days between the date range.
and the function module,
WEEK_GET_NR_OF_WORKDAYS
gives the no of workable days in a week.
2006 Jan 27 6:22 AM
Hi Rani,
1. Independent PERFORM
for this purpose.
2. Using FM and logic
below is a FORM
which independelty
gives the NUMBER OF WORKING DAys
(inputs are : fromdate, todate, days)
eg. From 24-jan-2006
25-jan-2006
26-jan-2006 (republic day in india)
27-jan-2006
It will Return 3
3. see this code (just copy paste)
REPORT abc.
*----
DATA : days TYPE i.
DATA : dt TYPE sy-datum.
*----
SELECT-OPTIONS : mydate FOR sy-datum DEFAULT '20060124' TO '20060127'.
*----
START-OF-SELECTION.
PERFORM calcdays USING mydate-low mydate-high days.
WRITE days .
*----
FORM
*----
FORM calcdays USING fromdate todate days.
DATA : dt TYPE sy-datum.
dt = fromdate.
DO.
IF dt > todate.
EXIT.
ENDIF.
CALL FUNCTION 'DATE_CHECK_WORKINGDAY'
EXPORTING
date = dt
factory_calendar_id = 'IN'
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.
dt = dt + 1.
IF sy-subrc = 0.
days = days + 1.
ENDIF.
ENDDO.
ENDFORM. "calcdays
regards,
amit m.
2006 Jan 27 9:02 AM
hi,
Check out this code.
it_holidays gives the no. of holidays between the a given period.
x_date will give the no. of working days.
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 😕 x_date.
Regards,
Sailaja.
2009 Jan 20 12:21 PM
Try the function below.... It would give you all the dates between DATE_FROM and DATE_TO. Also, it would mark all the Sundays and Holidays with a FLAG = X based on the Calender ID input. Just count in the table for flag to get holidays or Unflagged to get working days. Remember to give the correct Calender ID
CALL FUNCTION 'DAY_ATTRIBUTES_GET'
EXPORTING
FACTORY_CALENDAR = 'IN'
HOLIDAY_CALENDAR = ' '
DATE_FROM = l_date_ini
DATE_TO = l_date_fin
LANGUAGE = SY-LANGU
NON_ISO = ' '
IMPORTING
YEAR_OF_VALID_FROM =
YEAR_OF_VALID_TO =
RETURNCODE =
TABLES
DAY_ATTRIBUTES = itab_attr
EXCEPTIONS
FACTORY_CALENDAR_NOT_FOUND = 1
HOLIDAY_CALENDAR_NOT_FOUND = 2
DATE_HAS_INVALID_FORMAT = 3
DATE_INCONSISTENCY = 4
OTHERS = 5
2009 Jan 20 12:23 PM
2009 Jan 20 12:45 PM
Hi,
Check the below FM,
WDKAL_CALC_CONS_WORKDAYS_PER
WDKAL_DATE_ADD_FKDAYS
hope it helps.
Regards,
Anki Reddy
2009 Jan 21 3:48 AM
Hi Rani
Please use the below mentioned code snippet:
Variables to be used
DATA: wf_year(4) TYPE n,
wf_month(2) TYPE n,
wf_end_month(2) TYPE n,
wf_start_day(2) TYPE n,
wf_end_day(2) TYPE n,
wf_check_day(1) TYPE n,
wf_check_month(31) TYPE c,
wf_check_year(4) TYPE n,
wf_cnt TYPE i,
wf_first(1) TYPE c,
wf_year_ind(1) TYPE c,
wf_month_ind(1) TYPE c,
lv_str TYPE i,
lv_month TYPE i,
wf_exit.
Check that both dates are specified
IF start_date = 0 OR end_date = 0.
RAISE invalid_date.
ENDIF.
Assign initial values
wf_first = 'Y'.
wf_year = start_date+0(4).
wf_month = start_date+4(2).
wf_start_day = start_date+6(2).
wf_end_day = end_date+6(2).
Get data for requested year(s)
WHILE wf_year LE end_date+0(4).
wf_check_year = wf_year.
IF wf_year = end_date+0(4).
wf_year_ind = 'Y'.
ELSE.
wf_year_ind = 'N'.
ENDIF.
SELECT SINGLE * FROM tfacs
WHERE ident = calendar
AND jahr = wf_check_year.
IF sy-subrc NE 0.
RAISE no_calendar_for_year.
ENDIF.
Check which month
CLEAR wf_check_month.
CLEAR: wf_check_day.
IF wf_first = 'Y'.
wf_first = 'N'.
wf_cnt = start_date+6(2). " - 1.
ELSE.
CLEAR wf_cnt.
ENDIF.
MOVE wf_month TO lv_month.
lv_month = lv_month + 1.
wf_end_month = lv_month - 2.
FIELD-SYMBOLS: <fs> TYPE ANY.
DO 12 TIMES.
lv_month = lv_month + 1.
wf_end_month = lv_month - 2.
IF wf_end_month = end_date+4(2).
wf_month_ind = 'Y'.
ELSE.
wf_month_ind = 'N'.
ENDIF.
ASSIGN COMPONENT lv_month OF
STRUCTURE tfacs TO <fs>.
IF sy-subrc <> 0 OR lv_month = 15.
EXIT.
ENDIF.
lv_str = strlen( <fs> ).
DO.
IF wf_cnt = lv_str OR
( wf_cnt GE end_date+6(2) AND
wf_year_ind = 'Y' AND
wf_month_ind = 'Y' ).
wf_exit = '1'.
EXIT.
ENDIF.
wf_check_day = <fs>wf_cnt(1). " wf_check_monthwf_cnt(1).
IF wf_check_day = 1.
ADD 1 TO number_of_days.
ENDIF.
ADD 1 TO wf_cnt.
ENDDO.
IF wf_cnt GE end_date+6(2) AND
wf_year_ind = 'Y' AND
wf_month_ind = 'Y' AND
wf_exit = '1'.
EXIT.
ENDIF.
CLEAR: wf_cnt.
ENDDO.
wf_year = wf_year + 1.
CLEAR: wf_month, wf_end_month.
ADD 1 TO wf_month.
ADD 3 TO wf_end_month.
If record doesn't exist
IF sy-subrc NE 0.
RAISE no_calendar_for_year.
ENDIF.
IF wf_month > end_date+4(2) AND
wf_year_ind = 'Y' AND
wf_month_ind = 'Y'.
EXIT.
ENDIF.
ENDWHILE.
ENDFUNCTION.
Use the following parameters:
*"----
""Local interface:
*" IMPORTING
*" REFERENCE(CALENDAR) LIKE TFACS-IDENT
*" REFERENCE(START_DATE) LIKE SY-DATUM
*" REFERENCE(END_DATE) LIKE SY-DATUM
*" EXPORTING
*" REFERENCE(NUMBER_OF_DAYS) TYPE I
*" EXCEPTIONS
*" INVALID_DATE
*" NO_CALENDAR_FOR_YEAR
*"----
Create a new FM and copy this code snippet there and then you may reuse it.
Hope this is useful.
Regards
Harsh
2011 Jun 16 3:37 PM