Application Development 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: 

Function Module

Former Member
0 Kudos

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

10 REPLIES 10

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

hi

good

go through this function module

RP_CALC_DATE_IN_INTERVAL Add/subtract years/months/days from a date

thanks

mrutyun^

0 Kudos
use fm...
call function 'GET_DELTA_TIME_FROM_DT'
     exporting
          t1 = uzeit1
          t2 = uzeit2
          d1 = datum1
          d2 = datum2
     importing
          t3 = result.
 
 
          write:/ result.

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Thanks for your replies . Assigned Points to everyone

Former Member
0 Kudos

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)

Former Member
0 Kudos

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