03-05-2007 3:45 PM
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
03-05-2007 3:59 PM
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
03-05-2007 3:52 PM
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.
03-05-2007 3:55 PM
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
03-05-2007 3:59 PM
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
03-05-2007 4:00 PM
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.