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: 

loop help

Former Member
0 Kudos

hallow i have a table with employee and score and i wont to sum the score of employee and move it to another field after <b>every</b> employee .

this ex. of my table with just 2 employee i have more

Emp_num score

123*************5

123 ************2

123************ 7

456************ 2

456************3

The asterisk is just for the example .

I wont to do sum in loop like emp 123 score is 17 and emp num 456 is 5 .

<b>I try like that but is not working what i doing wrong?</b>

LOOP AT score_tab_3 INTO wa_score_tab_3.

AT END OF Emp_num.

SUM.

sum_all = wa_score_tab_3-score.

ENDAT.

ENDLOOP.

if i have 2 field in my table where i get the sum? i have to declare anter field?

regards

LOOP AT score_tab INTO wa_score_tab.

ON CHANGE OF wa_score_tab-emp_num.

ADD wa_score_tab-score_sum TO sum_all.

ENDON.

sum_n = sum_all.

ENDLOOP.

But its not working

regards

1 ACCEPTED SOLUTION

ferry_lianto
Active Contributor
0 Kudos

Hi Antonio,

Please try this.


DATA: ITAB_TOTAL TYPE SCORE_TAB. 

SORT score_tab by emp_num.

LOOP AT score_tab.

  MOVE score_tab TO wa_score_tab.

  AT END OF emp_num.
     SUM.
     itab_total-emp_num = wa_score_tab-emp_num.
     itab_total-score_sum = score_tab-score_num.
     append itab_total.
  ENDAT. 

ENDLOOP.

LOOP AT itab_total.
  Write: /itab_total-emp_num, itab_total-score_num.
ENDLOOP.

Regards,

Ferry Lianto

4 REPLIES 4

former_member187255
Active Contributor
0 Kudos

Antonio,

try this way....

LOOP AT score_tab INTO wa_score_tab.

AT NEW wa_score_tab-emp_num.

sum_n = wa_score_tab-score_sum + sum_n.

ENDAT.

ENDLOOP.

write: sum_n

Regards.

Former Member
0 Kudos

Hello,

DO like this:


sort score_tab_3 by emp_num.
LOOP AT score_tab_3 INTO wa_score_tab_3.
AT END OF Emp_num.
SUM.
sum_all = wa_score_tab_3-score.
ENDAT.
ENDLOOP.

Regards,

Vasanth

ferry_lianto
Active Contributor
0 Kudos

Hi Antonio,

Please try this.


DATA: ITAB_TOTAL TYPE SCORE_TAB. 

SORT score_tab by emp_num.

LOOP AT score_tab.

  MOVE score_tab TO wa_score_tab.

  AT END OF emp_num.
     SUM.
     itab_total-emp_num = wa_score_tab-emp_num.
     itab_total-score_sum = score_tab-score_num.
     append itab_total.
  ENDAT. 

ENDLOOP.

LOOP AT itab_total.
  Write: /itab_total-emp_num, itab_total-score_num.
ENDLOOP.

Regards,

Ferry Lianto

Former Member
0 Kudos
SORT score_tab_3 by emp_num score.

LOOP AT score_tab_3 INTO wa_score_tab_3.

AT END OF Emp_num.
SUM.
write : / wa_score_tab_3-emp_num,
           wa_score_tab_3-score.
ENDAT.

ENDLOOP.

OR

If u want to move the sum to another internal table , then

LOOP AT score_tab_3 INTO wa_score_tab_3.

AT END OF Emp_num.
SUM.
 move-corresponding  wa_score_tab_3 to wa_itab1.
 append wa_itab1 to itab1.

ENDAT.

ENDLOOP.