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

looping problem

Former Member
0 Likes
1,012

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
986

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

9 REPLIES 9
Read only

Former Member
0 Likes
986

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

Read only

Former Member
0 Likes
986

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

Read only

alex_m
Active Contributor
0 Likes
986

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.

Read only

Former Member
0 Likes
986

Hi,

u use sum control statement.

LOOP AT itab.

AT last.

SUM.

ENDAT.

endloop.

Regards,

Sruthi

Read only

Former Member
0 Likes
986

Hi,

Use AT FIRST field and sum.

This will help i suppose.

Regards,

Sreevani

Read only

Former Member
0 Likes
986

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.

Read only

Former Member
0 Likes
986

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.

Read only

Former Member
0 Likes
986

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

Read only

Former Member
0 Likes
987

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