Function used to obtain the number of working days between two dates based on the factory calendar

Source: Internet
Author: User

I found the common date functions provided by SAP for one afternoon and did not find the functions that suit my needs. If I did, I wrote one myself. Which of the following heroes found and told the younger brother that it would not be so troublesome to write on his own next time. The written Function Code is as follows:

Function zposo_get_work_days.
*"----------------------------------------------------------------------
* "*" Local interface:
* "Importing
* "Value (B _date) type SY-DATUM
* "Value (e_date) type SY-DATUM
* "Exporting
* "Reference (days) Type I
*"----------------------------------------------------------------------
Data: Work (1 ),
P_date like sy-datum.
Call function 'fima _ days_and_months_and_years'
Exporting
I _date_from = B _date
I _date_to = e_date
Importing
E_days = days. "Get the number of days between two dates. leave is not excluded.

P_date = B _date.
Do days times. "increment the date and convert it to the factory calendar to determine if it is a holiday
Clear work.
Call function 'rp _ calc_date_in_interval'
Exporting
Date = p_date
Days = '01'
Months = '00'
Years = '00'
Importing
Calc_date = p_date.

Call function 'date _ convert_to_factorydate'
Exporting
Date = p_date
Factory_calendar_id = 'ps'
Importing
Workingday_indicator = work.
If work ne ''.
Days = days-1.
Endif.
Enddo.
Clear work.
Call function 'date _ convert_to_factorydate' "is converted to a factory calendar to determine whether the start date is a holiday.
Exporting
Date = B _date
Factory_calendar_id = 'ps'
Importing
Workingday_indicator = work.
If work ne ''.
Days = days-1.
Endif.
If e_date ne p_date.
Clear work.
Call function 'date _ convert_to_factorydate' "to determine whether the end date is a holiday
Exporting
Date = e_date
Factory_calendar_id = 'ps'
Importing
Workingday_indicator = work.
If work ne ''.
Days = days-1.
Endif.
Endif.

Days = days + 1.
Endfunction.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.