10-21-2008 9:49 AM
I am looping into an internal table then giving
at end of <field1>
SUM
and i have field like
field1 field2
abc 100
abc 100
abc 200
def 100
def 200
Now my sums should be 400 then 300..
and theloop pass should enter at end of vtref only for the last time to sum the values..
but my loop is entering every time into at end of f1 and giving
wrong values..
any specfic reasons?
10-21-2008 9:53 AM
1. is the table sorted?
2. is field1 really the first field of the internal table?
10-21-2008 9:52 AM
10-21-2008 9:53 AM
1. is the table sorted?
2. is field1 really the first field of the internal table?
10-21-2008 9:57 AM
Hi,
First sort the internal table and then use "ON change of "
or "at new" . this will help you out
and then delete the other rows
Thanks & Regards
Edited by: Ranjit Kumar on Oct 21, 2008 11:13 AM
10-21-2008 10:16 AM
at new or onchange of will not work...because i need all addition of similar values
10-21-2008 10:20 AM
>
> at new or onchange of will not work...because i need all addition of similar values
Hi Arvind ,
Use "Collect Statement
Thanks & Regards
10-21-2008 10:01 AM
Hi,
Check the following code:
data: begin of itab occurs 0,
fld1(5) type c,
fld2 type i,
end of itab.
itab-fld1 = 'abc'.
itab-fld2 = 100.
append itab.
itab-fld1 = 'abc'.
itab-fld2 = 100.
append itab.
itab-fld1 = 'abc'.
itab-fld2 = 200.
append itab.
itab-fld1 = 'def'.
itab-fld2 = 100.
append itab.
itab-fld1 = 'def'.
itab-fld2 = 200.
append itab.
loop at itab.
write:/ itab-fld1, itab-fld2.
at end of fld1.
sum.
uline.
write:/ itab-fld1, itab-fld2.
skip.
endat.
endloop.
Regards,
Bhaskar
10-21-2008 10:01 AM
Consider there are three fileds in the ITAB.
fld1,fld2 and fld3.
When you write AT END OF fld3, the loop pass will go inside this block whenever the value in fld1 or fld2 or fld3 changes.
Thats the reason why you are getting such result.
Try ON CHNAGE OF
10-21-2008 10:05 AM
Hi Aravind,
Try the below code.
DATA : BEGIN OF ITAB OCCURS 0,
NAME(3),
VALUE TYPE I,
END OF ITAB.
ITAB-NAME = 'abc'.
ITAB-VALUE = 100.
APPEND ITAB.
ITAB-NAME = 'abd'.
ITAB-VALUE = 100.
APPEND ITAB.
ITAB-NAME = 'abc'.
ITAB-VALUE = 100.
APPEND ITAB.
ITAB-NAME = 'abd'.
ITAB-VALUE = 300.
APPEND ITAB.
SORT ITAB BY NAME.
LOOP at ITAB.
AT END OF NAME.
SUM.
write 😕 itab-name , itab-value.
ENDAT.
ENDLOOP.
10-21-2008 10:06 AM
Hello,
Better to use collect statement to add the sum for similar field values.
loop the internal table
Collect workarea to internal table
endloop.
Use this statement for u r internal table it will automatically add the sum for the similar field
abc 400
def 300
Your internal table contain these 2rows.
10-21-2008 10:15 AM
Hi
As per the code given by you, and the itab content
the output itab after the entire loop should be
field1 field2
abc 400
def 300
The output will be like this only if field1 is the 1st field of the itab.If not, the control enters into the at end stmt whenever data changes in the fields left of field1.
Please make sure of this point and proceed.
Please notify if this is not working
Regards
Winnie
10-21-2008 10:23 AM
Hi Arvind,
try it like this:
Sort itab by field1.
Loop at itab into wa.
At end of field1.
Sum.
Write: wa-field1,
wa-field2. " Here you will get the sum of similar fields
Endat.
Endloop.
With luck,
Pritam.
10-21-2008 10:24 AM
Hi Arvind,
Just sort the internal table by field1.
then place your same code .
loop
at end of <field1>
SUM
and i have field like
endloop.
I think it will help you.
Thanks and Regards
Subhankar
10-21-2008 11:09 AM
Hi VR ARVIND ,
Control break statement are very sensitive . make sure that this is the 1st field of an internal table .I thing you have more field before that which causes in each pass the previous values changes and in end of fire . and sort the ITAB with the control break Statements , before looping and Sum is work only for P I F field only.
Thanks ;
Tarak.
11-25-2008 8:45 AM