2007 Sep 05 1:24 PM
hello experts,
i have an itab it1 in follwing form
matnr mtart menge
7221008 fert 100
7221008 fert 10
7221008 fert 5
i wnt to sum the menge field in same it1 is it possible.
if anybody can help.
points will be rewarded
thanx
2007 Sep 05 1:35 PM
hi,
use COLLECT ST IN LOOP AT statement.
as
loop at itab.
collect.
......
endloop.
if helpful reward some points.
with regards,
Suresh Aluri.
2007 Sep 05 1:26 PM
2007 Sep 05 1:30 PM
u can do that with collect statement right???
COLLECT <wa> INTO <itab>.
DATA: BEGIN OF LINE,
COL1(3) TYPE C,
COL2(2) TYPE N,
COL3 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE
WITH NON-UNIQUE KEY COL1 COL2.
LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 3.
COLLECT LINE INTO ITAB.
WRITE / SY-TABIX.
LINE-COL1 = 'def'. LINE-COL2 = '34'. LINE-COL3 = 5.
COLLECT LINE INTO ITAB.
WRITE / SY-TABIX.
LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 7.
COLLECT LINE INTO ITAB.
WRITE / SY-TABIX.
LOOP AT ITAB INTO LINE.
WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
ENDLOOP.
The output is:
1
2
1
abc 12 10
def 34 5
The example fills a sorted table. The first two COLLECT statements work like normal insertion statements. In the third COLLECT statement, the first line of ITAB is modified.
<itab> must have a flat line type, and all of the fields that are not part of the table key must have a numeric type (F, I, or P). You specify the line that you want to add in a work area that is compatible with the line type.
When the line is inserted, the system checks whether there is already a table entry that matches the key. If there is no corresponding entry already in the table, the COLLECT statement has the same effect as inserting the new line. If an entry with the same key already exists, the COLLECT statement does not append a new line, but adds the contents of the numeric fields in the work area to the contents of the numeric fields in the existing entry.
You should only use the COLLECT statement if you want to create summarized tables. If you use other statements to insert table entries, you may end up with duplicate entries
reward points if helpful.
2007 Sep 05 1:35 PM
hi,
use COLLECT ST IN LOOP AT statement.
as
loop at itab.
collect.
......
endloop.
if helpful reward some points.
with regards,
Suresh Aluri.
2007 Sep 05 1:36 PM
loop at itab into wa.
collect wa to itab..
endloop.
if helpful reward some points.
2007 Sep 05 1:51 PM
I am assuming that you have records in internal table. SUM is the better option than collect. If you are extractiong data from databse table and want to use Select and endselect, that COLLECT is the better option
At new mtart.
l_menge = it1-menge.
endat.
2007 Sep 05 1:53 PM
Sorry. I missed SUM in my previous reply.
At new mtart.
SUM.
l_menge = it1-menge.
endat.
Award points, if you find it useful. Let me know if you need more details about this statement.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |