Skip to Content
avatar image
Former Member

Calculate time difference based on range table!

Hello all,


I just to let you know that i have searched forum before posting this , may be requirement is too specific.
I have a Ztable shown below:

Company code | Calendar ID | Range ID | Hour range from | Hour range to |

CC1                |     IT            |   R1        |  09:00:00am       |   01:00:00pm  |

CC1                |     IT            |   R2        |  02:00:00am       |   06:00:00pm  |

I now have to calculate time difference between two dates (considering holidays in calendar ) also considering times based on working hours in the range table.

Example:
creation date1: 05/12/2014

creation hour1: 09:15:00am

Creation date2: 08/12/2014

Creation hour2: 10:00:00am

The difference is: 07:45:00 + 01:00:00 = 08:45:00.

Please provide some inputs on how to proceed and various scenarios i need to consider to avoid miscalculation.

Regards,
Giri

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    Jan 06, 2015 at 04:02 PM

    Hi,

    Please check if  cl_abap_tstmp time stamp will do the job .

    Please see here:

    regards.

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 06, 2015 at 03:22 PM

    Hi Giri,

    You need to follow below approach:

    1) get no. of working days using some standard FM/class (please refer ). Say you got A-no. of days

    2) calculate ( A - 2 ) * hours per day as per that CC and range. This will give you solid hours for between days

    3) Calculate no. of applicable hours for 1st and last day and add in outcome of step-2

    probably you need to take care if a particular document was created after valid time of that day, then consider from next day. You need to take that decision based on particular requirement.

    Hope this helps.

    Warm Regards,

    Shyam Agrawal

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 06, 2015 at 03:25 PM

    Hi Giri,

    Is it related to HR requirement.

    We can calculate the same using workschedule of the particular employee.

    Use FM CATS_GET_TARGET_HOURS as shown below.

    Pass the employee number and date1 and date2 as shown below.

    The work schedule of the particular employee is displayed as shown below.

    Holidays are pointed out as 000000 hours.

    Calculate the difference using SOBEG and SOEND Time.

    Also find the below link.

    Get an Employee’s Planned Work Shift START TIME and END TIME

    Regards

    Rajkumar Narasimman.


    Add comment
    10|10000 characters needed characters exceeded

  • Jan 06, 2015 at 03:25 PM

    Hi Giri!

    You could try to use the FM "DURATION_DETERMINE", like this:

    For example, I'm using Unit = 'H' (Hour) and Factory_Calendar = 'BR'. To change that unit, see another one from table T006, field MSEHI.

    Best regards from Brazil,

    Alexandre B. Dambrowski


    Add comment
    10|10000 characters needed characters exceeded

  • Jan 06, 2015 at 06:19 PM

    1. Get total elapsed time, in hours between CREATE1 and CREATE2

        CALL FUNCTION 'SD_DATETIME_DIFFERENCE'

         -> datediff and timediff

    2. Pull out any holidays during time period

        CALL FUNCTION 'HOLIDAY_GET'

         -> if holiday, datediff = datediff - 1

    3. Calculate elapsed time

        elapsed_time = timediff + ( datediff * 24 ).

    Add comment
    10|10000 characters needed characters exceeded