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

calculating total working hours

Former Member
0 Likes
2,393

Hai Experts ,

i want to calculate the total working hours of every employee.

my scenario is .. i am having a table zworkinghours

the fields are

SNO -numc

EMPID-int4--- employee id

DATEE-dats--- date

WHOURS-tims--- hours worked

sample datas:

(PK)SNO EMPID DATEE WHOURS

01 101 2008/01/12 11:12:20

02 102 2008/05/14 12:12:45

03 103 2008/06/24 07:45:56

04 101 2008/04/13 12:12:20

05 102 2008/07/21 15:12:45

06 103 2008/04/25 03:45:56

now i want to calculate the total working hours of a every employee

the output needed is

EMPID(101) TOTAL WORKING HOURS(11:12:45 + 12:12:45)

101 23:25:40

plz help with the code ..

thanks and kind regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,466

Hi,

Make EMP ID as the very First Field of your Internal Table, Sort Internal Table Based on EMP ID and Use SUM Statement inside the AT-NEW, Internal Table Control Level processing events.

Refer:

http://sap.ittoolbox.com/groups/technical-functional/sap-dev/at-new-statement-282169

Hai Experts ,

i want to calculate the total working hours of every employee.

my scenario is .. i am having a table zworkinghours

the fields are

SNO -numc

EMPID-int4--- employee id

DATEE-dats--- date

WHOURS-tims--- hours worked

sample datas:

(PK)SNO EMPID DATEE WHOURS

01 101 2008/01/12 11:12:20

02 102 2008/05/14 12:12:45

03 103 2008/06/24 07:45:56

04 101 2008/04/13 12:12:20

05 102 2008/07/21 15:12:45

06 103 2008/04/25 03:45:56

now i want to calculate the total working hours of a every employee

the output needed is

EMPID(101) TOTAL WORKING HOURS(11:12:45 + 12:12:45)

101 23:25:40

plz help with the code ..

thanks and kind regards

6 REPLIES 6
Read only

Former Member
0 Likes
1,467

Hi,

Make EMP ID as the very First Field of your Internal Table, Sort Internal Table Based on EMP ID and Use SUM Statement inside the AT-NEW, Internal Table Control Level processing events.

Refer:

http://sap.ittoolbox.com/groups/technical-functional/sap-dev/at-new-statement-282169

Read only

Former Member
0 Likes
1,466

Chinna,

Build the internal table with first field as emp id and then loop at the internal tabel , and use the control statements to get output as per the requirement.

LOOP at ITAB.

at end of EMP_ID.

SUM.

TOT_HOURS = Working_hours.

< here you get sum of the working hours of the employee.>

End at.

ENDLOOP.

Use the above logic and derive the result as per the requirement.

Regards..

Read only

Former Member
0 Likes
1,466

Hai Chinnaya,

kindly search in SDN. You will get lots of link regarding this.

https://forums.sdn.sap.com/click.jspa?searchID=18442321&messageID=4492332

Regards,

Harish

Read only

Former Member
0 Likes
1,466

thanks for all who reply ..

this is my code .. i am getting partial output .

i not getting the total working hours

the total working hours is coming as *::*

data : begin of itab occurs 0,

empid type zworkinghour-empid,

datee type zworkinghour-datee,

whours type zworkinghour-whours,

total type zworkinghour-whours,

end of itab.

select * from zworkinghour into CORRESPONDING FIELDS OF TABLE itab.

sort itab by empid.

loop at itab.

at new empid.

write 😕 'Employee Id ',itab-empid.

uline.

sum.

endat.

write 😕 'date' , itab-datee,

'time worked',itab-whours.

itab-total = 0.

itab-total = itab-total + itab-whours.

at end of empid.

uline.

write : / 'total working hours ', itab-total .

skip.

endat.

ENDLOOP.

Read only

0 Likes
1,466

Hi,

Slight change in your code will work. Remember that the Headerline gets cleared inside at AT....ENDAT processing Block. You need to use an explicit workarea to take care of this.

See the BOld Code with the Changes...

Data wa like line of itab.

loop at itab .

Clear wa.

Move itab to wa.at new empid.

write 😕 'Employee Id ',wa-empid.

uline.

sum.

endat.

write 😕 'date' , itab-datee,

'time worked',itab-whours.

itab-total = 0.

itab-total = itab-total + itab-whours.

Clear wa.

Move itab to wa.

at end of empid.

uline.

write : / 'total working hours ', wa-total .

skip.

endat.

ENDLOOP.

This should solve your problem

Edited by: AJAY TIWARI on Nov 9, 2008 9:02 AM

Read only

0 Likes
1,466

hai AJAY TIWARI ,

Thanks for your suggestion.

every thing is coming write except the total working hours

the total working hours is coming now as 00:00:00

can u provide the exact code for this ..

thanks & kind regards

chinnaiya