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

sum in internal table

Former Member
0 Likes
653

Hallow I have a internal table with employee number and number of hours that employee done in jobs the problem is that I have for one employee 3 kind of hour.

Pernr hour

123 10

123 10.5

123 15

456 4

456 9

How can I do that I sum the hour ex.

Emp num 123 35.5

Emp num 456 13

Because its internal table I cant do a select count

thankes

5 REPLIES 5
Read only

Former Member
0 Likes
595

try control break event like......

at end of pernr.

sum.

endat.

regds,

kiran

Read only

0 Likes
595

Or use a <b>collect</b> statement !

( collect instead of append, it'll do the job )

Hope this helps,

Erwan

Read only

Former Member
0 Likes
595

Hi,

COLLECT statement will give u the desired output.

regards,

madhumitha

Read only

Former Member
0 Likes
595

Hi Antonio,

Please try this by creating new internal table (ITAB2) with the same structure (ITAB).

...

SORT ITAB.

LOOP ITAB.
  ITAB2-PERNR = ITAB-PERNR.
  ITAB2-HOUR = ITAB-HOUR.
  COLLECT ITAB2.
ENDLOOP.

...

Now, your ITAB2 has the total hours by PERNR.

Regards,

Ferry Lianto

Read only

Former Member
0 Likes
595

Hi Antonio,

Use control-break statements to achieve your requirement.

DATA:

BEGIN OF ITAB OCCURS 0,

PERNR TYPE PERNR.

HOUR TYPE I,

END OF ITAB.

DATA ITAB_NEW TYPE ITAB OCCURS 0 WITH HEADER LINE.

DATA V_COUNT TYPE I.

DATA V_PERNR TYPE PERNR.

SORT ITAB BY PERNR.

LOOP AT ITAB.

V_PERNR = ITAB-PERNR.

AT NEW PERNR.

CLEAR V_COUNT.

ENDAT.

V_COUNT = V_COUNT + ITAB-HOUR.

AT END OF PERNR.

ITAB_NEW-PERNR = V_PERNR.

ITAB_NEW-HOUR = V_C0UNT.

APPEND ITAB_NEW.

ENDAT.

ENDLOOP.

Thanks,

Vinay