Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

FM to find n.of working days

Former Member
0 Kudos

Hi experts,

Is there any FM to find n.of working days between two given dates?

Regards

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi ravi,

1. Not only the number of days,

but also the list of dates.

WORKING DAYS based upon the calendar id.

2. This program

(it has an independent form)

which will give such thing.

3. Just copy paste in new program.

REPORT abc.

data : num type i.

parameters : frdate type sy-datum default '20051216'.

parameters : todate type sy-datum default '20051221'.

perform getinfo using frdate todate changing num.

break-point.

&----


*& Form getinfo

&----


  • text

----


FORM getinfo USING fromdate todate CHANGING numofdays type i.

DATA : d TYPE sy-datum.

d = fromdate - 1.

DO.

d = d + 1.

IF d > todate.

EXIT.

endif.

CALL FUNCTION 'DATE_CHECK_WORKINGDAY'

EXPORTING

date = d

factory_calendar_id = '01'

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 = 0.

numofdays = numofdays + 1.

write 😕 d.

ENDIF.

ENDDO.

ENDFORM. "getinfo

regards,

amit m.

11 REPLIES 11

Former Member
0 Kudos

Hi,

you can use this FM.

DATE_CHECK_WORKINGDAY

Regards,

Sumit.

0 Kudos

parameters: p_start type sy-datum,

p_end type sy-datum.

data: idays type table of rke_dat with header line.

data: workingdays type i.

call function <b>'RKE_SELECT_FACTDAYS_FOR_PERIOD'</b>

exporting

i_datab = p_start

i_datbi = p_end

i_factid = 'P8' " Fact Calender ID

tables

eth_dats = idays

exceptions

date_conversion_error = 1

others = 2.

describe table idays lines workingdays.

write:/ workingdays.

0 Kudos

Thanks..But it is giving Sy-Subrc = 1. after exicuting that FM.I given dates from 20.06.2006 to 31.08.2006.

The out put is 0.

Any suggessions?

0 Kudos

r u giving start date and enddate as a sy-datum type...

parameters: p_start type sy-datum,

p_end type sy-datum.

0 Kudos

It will definitely work, check your date format on input screen

0 Kudos

See the same code:

parameters: p_start type sy-datum,

p_end type sy-datum.

data: idays type table of rke_dat with header line.

data: workingdays type i.

call function 'RKE_SELECT_FACTDAYS_FOR_PERIOD'

exporting

i_datab = p_start

i_datbi = p_end

i_factid = 'P8' " Fact Calender ID

tables

eth_dats = idays

exceptions

date_conversion_error = 1

others = 2.

describe table idays lines workingdays.

write:/ workingdays.

It is giving sy-subrc = 1. in version 4.7

0 Kudos

See sample code below:

report zcalculate_days.

  • Sample code to calculate total working days and holidays between 2 dates.

data: total_days(4) type c,

v_holidays type i,

v_work_days type i,

v_total_days type i.

data: begin of holidays occurs 0.

include structure iscal_day.

data: end of holidays.

parameters: from_dt like sy-datum,

to_date like sy-datum,

calendar like scal-hcalid.

start-of-selection.

  • Get total days between 2 dates

call function 'DAYS_BETWEEN_TWO_DATES'

exporting

i_datum_bis = to_date

i_datum_von = from_dt

i_kz_excl_von = '0'

i_kz_incl_bis = '1'

i_kz_ult_bis = ' '

i_kz_ult_von = ' '

i_stgmeth = '0'

i_szbmeth = '2'

importing

e_tage = total_days

exceptions

days_method_not_defined = 1

others = 2.

  • Get Holidays between 2 dates

call function 'HOLIDAY_GET'

exporting

holiday_calendar = calendar

factory_calendar = calendar

date_from = from_dt

date_to = to_date

tables

holidays = holidays

exceptions

factory_calendar_not_found = 1

holiday_calendar_not_found = 2

date_has_invalid_format = 3

date_inconsistency = 4

others = 5.

describe table holidays lines v_holidays. "Total holidays

v_total_days = total_days. "Total days

v_work_days = total_days - v_holidays. "Total working days

write:/ 'Start date : ', from_dt.

write:/ 'End date : ', to_date.

write:/ 'Calendar : ', calendar.

write:/ 'Total days : ', v_total_days.

write:/ 'Working days : ', v_work_days.

write:/ 'Holidays : ', v_holidays.

Former Member
0 Kudos

Hi,

You can get holidays between 2 dates using function module HOLIDAY_GET

Get total number of days between 2 dates and then deduct the number of holidays the result is number of working days.

Hope this helps.

regards

Damasus

Former Member
0 Kudos

hi,

You might not have passed the parameter factory calender id to the function module.

Regards,

Sailaja.

Former Member
0 Kudos

Hi Ravi,

It might not getting the FACTORY CALENDAR. Make sure that factory calender exists.

Rgds,

Prakash

Former Member
0 Kudos

Hi ravi,

1. Not only the number of days,

but also the list of dates.

WORKING DAYS based upon the calendar id.

2. This program

(it has an independent form)

which will give such thing.

3. Just copy paste in new program.

REPORT abc.

data : num type i.

parameters : frdate type sy-datum default '20051216'.

parameters : todate type sy-datum default '20051221'.

perform getinfo using frdate todate changing num.

break-point.

&----


*& Form getinfo

&----


  • text

----


FORM getinfo USING fromdate todate CHANGING numofdays type i.

DATA : d TYPE sy-datum.

d = fromdate - 1.

DO.

d = d + 1.

IF d > todate.

EXIT.

endif.

CALL FUNCTION 'DATE_CHECK_WORKINGDAY'

EXPORTING

date = d

factory_calendar_id = '01'

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 = 0.

numofdays = numofdays + 1.

write 😕 d.

ENDIF.

ENDDO.

ENDFORM. "getinfo

regards,

amit m.