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

Time Split

aasim_khan
Participant
0 Likes
666

Dear Experts,

My report requires to calculate average of the time given. Now, when I calculate, it's giving me the correct output, however, it's not according to the time format.

e.g. The Result = 7.76

Correct Value should be 8.26 i.e. 8 hours and 26 mins

Is there any Function Module available for this?

My Logic is as follows, but not able to calculate it.

FORM time_split USING l_tim1

CHANGING l_tim2.

DATA: l_hrs TYPE i,

l_min TYPE p DECIMALS 2,

l_t1 TYPE i,

l_t2 TYPE i.

DATA: l_hr TYPE n,

l_mn TYPE n,

l_t3 TYPE n,

l_t4 TYPE n.

SPLIT l_tim1 AT '.' INTO l_hr l_mn.

l_hrs = l_hr.

l_min = l_mn.

IF l_min GE 60.

l_min = l_min / 60.

ENDIF.

l_mn = l_min.

SPLIT l_mn AT '.' INTO l_t3 l_t4.

l_t1 = l_t3.

l_t2 = l_t4.

l_hrs = l_hrs + l_t1.

l_hr = l_hrs.

l_t4 = l_t2.

CONCATENATE l_hr '.' l_t4 INTO l_tim2.

ENDFORM. " TIME_SPLIT

3 REPLIES 3
Read only

rainer_hbenthal
Active Contributor
0 Likes
597

Hi,

convert your time in minutes first:

Pseudocode:


split time_1 at ':' into hours minutes.

duration = hours * 60 + minutes.

Do that with all your time durations:


split time_n at ':' into hours minutes.

duration = duration + hours * 60 + minutes.

After that, recalulate the hours by dividing the duartion by 60, ignoring the fraction, and caculating the minutes by the remainder.

Read only

Former Member
0 Likes
597

Hi Aasim,

use the following logic

PARAMETERS : p_time1 TYPE sy-uzeit,

p_time2 TYPE sy-uzeit.

DATA : l_avg_time TYPE sy-uzeit,

l_avg type string.

l_avg_time = ( p_time1 + p_time2 ) / 2.

concatenate l_avg_time00(02) 'Hrs' l_avg_time02(02) 'Minutes' into l_avg separated by space.

WRITE l_avg.

Regards,

Mansi

Read only

Former Member
0 Likes
597

Hi,

I think if you assign l_tm1 to a char type variable and finally use this char type variable in split as Split work with char or string type variable ,I am guessing that SPLIT command is not working fine in your code.else everything seesm to be ok.Just check in the debugger the value l_hr l_mn after split.

Pooja