Application Development and Automation 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: 
Read only

duration between given date range, without weekends

Former Member
0 Likes
869

Need a sample program, which gives the number of days between the given date range excluding the weekends.

eg: suppose is give start date is: 16.12.2005 and end date as: 21.12.2005, it should display 19.12.2005, 20.12.2005, 21.12.2005, leaving 17.12.2005 and 18.12.2005, because these two days are saturday and sunday.

For this example i need the ouput as 3.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
768

Hi Anitha,

1. DATE_CHECK_WORKINGDAY

This is one useful FM

2. Try this code (just copy paste)

IT DOES EXACTLY WHAT U REQUIRE.

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

I hope it helps.

Regards,

Amit M.

5 REPLIES 5
Read only

FredericGirod
Active Contributor
0 Likes
768

Hi Anitha

you will need to convert to factory date and to make the minus beetween the two values.

For that, you will need to use a calendar.

FM : DATE_CONVERT_TO_FACTORYDATE

Rgd

Frédéric

Read only

Former Member
0 Likes
769

Hi Anitha,

1. DATE_CHECK_WORKINGDAY

This is one useful FM

2. Try this code (just copy paste)

IT DOES EXACTLY WHAT U REQUIRE.

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

I hope it helps.

Regards,

Amit M.

Read only

0 Likes
768

here the function module will be called 100 time , if the difference which will reduce the performance. can u suggest some other way.

Read only

0 Likes
768

Hi Anitha,

1. other than FM we don't have any way

to find out saturday sunday.

2. There is no command/statement in abap.

3. DON'T WORRY ABOUT PERFROMANCE.

100 TIMES IS NOTHING.

EVEN 1000 TIMES CALLING THIS FM

won't be much strain on the server.

regards,

amit m.

Read only

Former Member
0 Likes
768

check this thread may be it will be useful..