‎2007 Mar 05 1:50 PM
Hallow I have a table with employee num and score like that
Emp_num score
123*************5
123 ************3
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
How can I do that in loop and move the result to a new variable in new emp .
I try like that
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
‎2007 Mar 05 3:54 PM
Hi Antonio,
Please try another one.
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
‎2007 Mar 05 1:53 PM
HI,
Use SUM command.
&----
*& Report ZKB_TEST
*&
&----
*&
*&
&----
REPORT zkb_test.
DATA: BEGIN OF i_tab1 OCCURS 0,
matnr(18) TYPE c,
desc(20) TYPE c,
valu TYPE i,
quan TYPE i,
sno(2) TYPE c,
END OF i_tab1.
DATA: i_tab2 LIKE TABLE OF i_tab1 WITH HEADER LINE.
START-OF-SELECTION.
i_tab1-sno = 1.
i_tab1-matnr = 'abc'.
i_tab1-desc = 'abc'.
i_tab1-valu = 10.
i_tab1-quan = 20.
APPEND i_tab1.
i_tab1-sno = 2.
i_tab1-matnr = 'xyz'.
i_tab1-desc = 'xyz'.
i_tab1-valu = 10.
i_tab1-quan = 20.
APPEND i_tab1.
i_tab1-sno = 3.
i_tab1-matnr = 'abc'.
i_tab1-desc = 'abc'.
i_tab1-valu = 10.
i_tab1-quan = 20.
APPEND i_tab1.
SORT i_tab1 BY matnr.
LOOP AT i_tab1.
i_tab2 = i_tab1.
AT END OF matnr.
SUM.
i_tab2-valu = i_tab1-valu.
i_tab2-quan = i_tab1-quan.
APPEND i_tab2.
ENDAT.
ENDLOOP.
LOOP AT i_tab2.
WRITE:/ i_tab2-sno, i_tab2-matnr, i_tab2-valu, i_tab2-quan.
ENDLOOP.
Regards
SAB
‎2007 Mar 05 1:55 PM
Hi,
Do like this.
Sort score_tab by emp_num.
LOOP AT score_tab.
At end of emp_num INTO wa_score_tab.
Sum.
ADD wa_score_tab-score_sum TO sum_all.
ENDON.
sum_n = sum_all.
ENDLOOP.
Regards,
Anji
‎2007 Mar 05 1:55 PM
LOOP AT score_tab INTO wa_score_tab.
at end of wa_score_tab-emp_num.
sum.
v_sum = wa_score_tab-score
ENDAT
ENDLOOP.
‎2007 Mar 05 1:55 PM
Hi,
u use sum control statement.
LOOP AT itab.
AT last.
SUM.
ENDAT.
endloop.
Regards,
Sruthi
‎2007 Mar 05 1:55 PM
Hi,
Use AT FIRST field and sum.
This will help i suppose.
Regards,
Sreevani
‎2007 Mar 05 1:59 PM
try at end of:
LOOP AT sflight_tab INTO sflight_wa.
AT NEW connid.
WRITE: / sflight_wa-carrid,
sflight_wa-connid.
ULINE.
ENDAT.
WRITE: / sflight_wa-fldate,
sflight_wa-seatsocc.
AT END OF connid.
SUM.
ULINE.
WRITE: / 'Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
SKIP.
ENDAT.
‎2007 Mar 05 3:18 PM
Hi,
sort Emp_table by emp_num.
loop at emp_table.
at end of emp_num.
sum.
endat.
v_num = emp_num.
v_score = emp_score.
endloop.
please reward points if it is useful
Thanks,
Suma.
‎2007 Mar 05 3:43 PM
Hi Antonio,
Please try this.
SORT score_tab by emp_num.
LOOP AT score_tab.
MOVE score_tab TO wa_score_tab.
AT END OF emp_num.
SUM.
sum_all = sum_all + wa_score_tab-score_sum.
ENDAT.
ENDLOOP.
Regards,
Ferry Lianto
‎2007 Mar 05 3:54 PM
Hi Antonio,
Please try another one.
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