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 tables

Former Member
0 Likes
454

Hallow I have a problem to sum recorded in table .

I have a 2 tables first table <b>emp_tab</b> is table with pernr (employee number) org unit and jobs and hour for employee

And second table (my main table) t_itab that have org unit and jobs of employee

Emp_tab is like that

Job org.unit person_num hour

50 00007676 00000163 00100003

22 00009001 00000163 00100004

15 00295349 00000273 00096050

5 02523298 00000273 00250052

6 02906773 00000273 00250052

7 07859563 00000163 00000040

8 09863256 00000163 00000040

9 31049912 00000273 00250052

I wont to sum the hour that employee do in org.unit (like163) and job (like 40) and move it to my main table t_itab.

Ex. In org_unit 163 and job 40 the sum is 15 hours

And this sum I wont to move to a new field In t_itab

the Keys job and org.unit

Maybe some one have idea how to do that

Tanks for your time

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
429

Hi Antonio,

You can create new internal table (emp_tab2) with fields like this.


...

DATA: BEGIN OF EMP_TAB2 OCCURS 0,
        JOB_ORG LIKE  ...
        JOB  LIKE  ...
        ORG_UNIT ...
        PERSON_NUM LIKE ...
        HOUR LIKE ...
DATA: END OF EMP_TAB2.

SORT EMP_TAB.

LOOP AT EMP_TAB.
  MOVE EMP_TAB-JOB      TO EMP_TAB2-JOB_ORG(2).
  MOVE EMP_TAB-ORG_UNIT TO EMP_TAB2-JOB_ORF+2(8).
  MOVE EMP_TAB-PERSON   TO EMP_TAB2-PERSON.
  MOVE EMP_TAB-HOUR     TO EMP_TAB2-HOUR. 
  COLLECT EMP_TAB2.
ENDLOOP.

...

Now .. the EMP_TAB2 has the sum of hour by combinnatino of job and org.unit.

Next, you can move EMP_TAB2 data to internal table T_TAB.

Please check the syntax and hope this will help.

Regards,

Ferry Lianto

Hallow I have a problem to sum recorded in table .

I have a 2 tables first table <b>emp_tab</b> is table with pernr (employee number) org unit and jobs and hour for employee

And second table (my main table) t_itab that have org unit and jobs of employee

Emp_tab is like that

Job org.unit person_num hour

50 00007676 00000163 00100003

22 00009001 00000163 00100004

15 00295349 00000273 00096050

5 02523298 00000273 00250052

6 02906773 00000273 00250052

7 07859563 00000163 00000040

8 09863256 00000163 00000040

9 31049912 00000273 00250052

I wont to sum the hour that employee do in org.unit (like163) and job (like 40) and move it to my main table t_itab.

Ex. In org_unit 163 and job 40 the sum is 15 hours

And this sum I wont to move to a new field In t_itab

the Keys job and org.unit

Maybe some one have idea how to do that

Tanks for your time

2 REPLIES 2
Read only

Former Member
0 Likes
430

Hi Antonio,

You can create new internal table (emp_tab2) with fields like this.


...

DATA: BEGIN OF EMP_TAB2 OCCURS 0,
        JOB_ORG LIKE  ...
        JOB  LIKE  ...
        ORG_UNIT ...
        PERSON_NUM LIKE ...
        HOUR LIKE ...
DATA: END OF EMP_TAB2.

SORT EMP_TAB.

LOOP AT EMP_TAB.
  MOVE EMP_TAB-JOB      TO EMP_TAB2-JOB_ORG(2).
  MOVE EMP_TAB-ORG_UNIT TO EMP_TAB2-JOB_ORF+2(8).
  MOVE EMP_TAB-PERSON   TO EMP_TAB2-PERSON.
  MOVE EMP_TAB-HOUR     TO EMP_TAB2-HOUR. 
  COLLECT EMP_TAB2.
ENDLOOP.

...

Now .. the EMP_TAB2 has the sum of hour by combinnatino of job and org.unit.

Next, you can move EMP_TAB2 data to internal table T_TAB.

Please check the syntax and hope this will help.

Regards,

Ferry Lianto

Read only

RaymondGiuseppi
Active Contributor
0 Likes
429

They key is the instruction collect. character fields (or keys if sorted table) are used as key and numeric data is summed.

So

LOOP AT emp_tab.

move-corresponding emp_tab into t_itab.

collect itab.

ENDLOOP.

Regards.