cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with calculating days, between Start Date to End Date

Former Member
0 Kudos

Hi Expert,

i have a problem with calculating days, from Start Date to Finish Date,  if Holiday cominig between this Start Date to Finish Date, it getting count.

How can i calculate properly.  Please provide some Code.

Another Problem is that if i select Start Date (eg. 10-10-2012)   and Finish Date ( 05-10-2012), its accepting.  

What validation code should i give that, if my finish date is less then Start Date, its should pop up message.

Please Provide Validation Code.

Accepted Solutions (0)

Answers (4)

Answers (4)

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

For validating enddate should be greater than begin date, you can simply check startdate <= finishdate. And for excluding holidays between dates, Use fm

HOLIDAY_CALENDER_GET to get name of the Holiday Calender.

HOLIDAY_GET to get the HOLIDAYS.

Then count the table lines of HOLIDAYS from HOLIDAY_GET by describe table. Then substract it from the earlier counted days between dates.

former_member184578
Active Contributor
0 Kudos

Hi,

You have to create Factory calendar in SCAL tcode with your custom holidays. then pass this to the below FM. It will exclude the holidays and gives the difference between 2 dates.

Check the below code,

*   get single attribute

  lo_el_employee->get_attribute(   EXPORTING  name =  `FROM_DATE`

                                                  IMPORTING   value = lv_from_date ).

   lo_el_employee->get_attribute( EXPORTING name =  `TO_DATE`

    IMPORTING  value = lv_to_date ).

    IF lv_to_date < lv_from_date.

  * Reporting Message

      lr_controller = wd_this->wd_get_api( ).

      lr_message_manager = lr_controller->get_message_manager( ).

      lr_message_manager->report_attribute_error_message(

                   attribute_name = 'TO_DATE'

                  element = lo_el_employee

                  message_text = 'To date should be greater than From date' ).

    ElSE.  " if both dates are equal lv_days = 1. it means 1 day

    

    call function 'RKE_SELECT_FACTDAYS_FOR_PERIOD'

          EXPORTING

            i_datab  = lv_from_date

            i_datbi  = lv_to_date

            i_factid = 'IN'        " Holiday cal

          TABLES

            eth_dats = it_dats.

        lv_dayss = lines( it_dats ). " lv_days gives the no of days excluding holidays

EndIF.

Here IN is the Factory calendar. You can create your custom Factory calendar in SCAL Transaction.

Hope this helps u.,

Thanks & Regards,

Kiran.

former_member199125
Active Contributor
0 Kudos

hi Suresh,

before you are calculating write small validation like if date1 is greater then date2 , then only call the function module.

And in your case you need to calculate number of working days not the difference. i dont know the exact fm for that.

Check this link..

http://wiki.sdn.sap.com/wiki/display/ABAP/Function+Module+related+on+Date+calculations

Other wise, use this FM  HR_personal_work_schedule. Pass the start and end date. And pass perws structure. after executing fm , read perws table....check in debugging perws table contents then you will get idea .

Regards

Srinivas

chengalarayulu
Active Contributor
0 Kudos

Hi Suresh,

you can make use of FM : HR_HK_DIFF_BT_2_DATES

Always Date1 should be greater than Date2.