2006 Nov 09 11:37 AM
Hi ,
I have two internal tables with following fields
<b>ITAB1</b>
DATE1
TIME1
<b>ITAB2</b>
DATE2
TIME2
Now i need to subtract these two date and time from two internal tables and get the <b>result in Hours</b> .
Give function module name or sample code
Thanks
Points Will be assigned
2006 Nov 09 11:40 AM
Hello,
Loop at itab1.
read table itab2 index sy-tabix.
if sy-subrc eq 0.
date = itab1-date1 - itab2-date2.
time = itab1-time1 - itab2-time2.
endif.
clear itab1.
clear itab2.
endloop.
2006 Nov 09 11:43 AM
U can use the FM CCU_TIMESTAMP_DIFFERENCE, it gives the difference in seconds which can be divided by 3600 to get hours.
loop at itab1.
read table itab2 index sy-tabix.
concatenate itab1-date1 itab1-time1 into lts1.
concatenate itab1-date2 itab1-time2 into lts2.
call function 'CCU_Timestamp_difference'
exporting
timestamp1 = lst1
timestamp2 = lst2
importing
difference = ldiff.
ldiff = ldiff / 3600.
endloop.
2006 Nov 09 11:45 AM
Loop at itab1.
read table itab2 index sy-tabix.
if sy-subrc eq 0.
date = itab1-date1 - itab2-date2.
time = itab1-time1 - itab2-time2.
total_hrs = (date * 24) + time.
append total_hrs.
endif.
endloop.
santhosh
Message was edited by: Kaluvala Santhosh
2006 Nov 09 11:49 AM
hi
good
go through this function module
RP_CALC_DATE_IN_INTERVAL Add/subtract years/months/days from a date
thanks
mrutyun^
2006 Nov 09 11:50 AM
use fm...
call function 'GET_DELTA_TIME_FROM_DT'
exporting
t1 = uzeit1
t2 = uzeit2
d1 = datum1
d2 = datum2
importing
t3 = result.
write:/ result.
2006 Nov 09 11:56 AM
Hi Shiba,
you can use the function module CCU_TIMESTAMP_DIFFERENCE. This will give the difference in seconds.
You can convert it to years or days as per your requirement.
data : dt1 like CCUPEAKA-TIMESTAMP,
dt2 like CCUPEAKA-TIMESTAMP,
diff type i,
days type i,
years type i.
dt1 = '20050101111111'.
dt2 = '20040101112222'.
CALL FUNCTION 'CCU_TIMESTAMP_DIFFERENCE'
EXPORTING
timestamp1 = dt1
timestamp2 = dt2
IMPORTING
DIFFERENCE = diff
.
write : / 'Difference in seconds', diff.
*If you want diff in hours
diff = diff / 3600.
reward if helpful.
regards,
keerthi.
2006 Nov 09 11:58 AM
hi,
d = itab2-v - itab1-v. diff of dates
t2 = itab2-t - itab1-t. diff of times
translate d using '- '. to remove '-' sign at the end
translate t2 using '- '.
(or)
d = itab1-v - itab2-v. diff of dates
t2 = itab1-t - itab2-t. diff of times
d = d * 24. to convert days into hours
t2 = t2 / ( 60 * 60 ). to convert seconds into hours
r = d + t2. total
write:/ d,t2,r.
do assign points if it helps you
2006 Nov 10 5:15 AM
2006 Nov 10 10:05 AM
hi,
i think this is usefull to u........
call function 'GET_DELTA_TIME_FROM_DT'
exporting
t1 = uzeit1
t2 = uzeit2
d1 = datum1
d2 = datum2
importing
t3 = result.
write:/ result.
with regards
m.srikanth.(review the points if it is usefull)
2006 Nov 10 10:09 AM
Hi,
For avoiding confusiong , try to put all data in one internal table and use an use FM <b>sd_datetime_difference</b>, pass date1 as earlier date, date2 as later date and enter time1 and time2 .
Regards,
Raghav