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: 

function module to calculate working days between 2 periods

Former Member
0 Kudos

Hi, All

I need to calculate the number of working days from factory calendar between 2 periods

for example today date is 04/30/2007

if my report is executed today it should calculate the no of days from periods 04(apr)-10(oct) according tho factory calendar ( working days )can any one help me out with this....

Thanks

9 REPLIES 9

Former Member
0 Kudos

Please try FM DURATION_DETERMINE.

Check this sample code from other thread.

data: xt001w type t001w.

data: duration type i.

data: sdate type sy-datum.

data: edate type sy-datum.

  • Get the factory calendar for specific plant

select single * from t001w into xt001w

where werks = '0004'. " Use your plant

  • Set start/end dates

sdate = sy-datum.

edate = sy-datum + 30.

call function 'DURATION_DETERMINE'

exporting

factory_calendar = xt001w-fabkl

importing

duration = duration " In days

changing

start_date = sdate

end_date = edate

exceptions

factory_calendar_not_found = 1

date_out_of_calendar_range = 2

date_not_valid = 3

unit_conversion_error = 4

si_unit_missing = 5

parameters_not_valid = 6

others = 7.

write:/ duration.

0 Kudos

Try this FM,

RKE_SELECT_FACTDAYS_FOR_PERIOD

ferry_lianto
Active Contributor
0 Kudos

Hi,

Welcome to SDN.

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.

Regards,

Ferry Lianto

Former Member
0 Kudos

Hi kalyan,

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.

Former Member
0 Kudos

Hi Kalyan,

Here are some of the function modules which probably might help you in ur problem,

1)FIMA_DAYS_BETWEEN_TWO_DATES

2)DAYS_BETWEEN_TWO_DATES

3)RKE_SELECT_FACTDAYS_FOR_PERIOD

Reward points if this is helpful,

Regards,

Kiran

Former Member
0 Kudos

Hi,

Check out this code. you need to get the Holiays betwenn 2 dates, then get the total number of dates, then minus the Holidays from the total dates ...

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.

kostas_tsioubris
Contributor

Former Member
0 Kudos

Hi,

Use the FM: 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

Regards,

Bhaskar

sreeramkumar_madisetty
Active Contributor
0 Kudos

Hi

Use the FM:

CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

EXPORTING

i_date_from = v_date_from1

i_date_to = date1

IMPORTING

e_days = date.

Regards,

Sreeram