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

Calculate time difference based on range table!

Former Member
0 Likes
1,859

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

1 ACCEPTED SOLUTION
Read only

rosenberg_eitan
Active Contributor
0 Likes
1,749

Hi,

Please check if  cl_abap_tstmp time stamp will do the job .

Please see here:

regards.

5 REPLIES 5
Read only

former_member207661
Active Participant
0 Likes
1,749

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

Read only

rajkumarnarasimman
Active Contributor
0 Likes
1,749

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.

Regards

Rajkumar Narasimman.

Read only

Former Member
0 Likes
1,749

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

Read only

rosenberg_eitan
Active Contributor
0 Likes
1,750

Hi,

Please check if  cl_abap_tstmp time stamp will do the job .

Please see here:

regards.

Read only

lisa_miller3
Participant
0 Likes
1,749

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 ).