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

add the numeric entries

Former Member
0 Likes
913

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
895

hi,

use COLLECT ST IN LOOP AT statement.

as

loop at itab.

collect.

......

endloop.

if helpful reward some points.

with regards,

Suresh Aluri.

6 REPLIES 6
Read only

Former Member
0 Likes
895

use collect statement

eg COLLECT it1.

this will add ur menge

Read only

Former Member
0 Likes
895

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.

Read only

Former Member
0 Likes
896

hi,

use COLLECT ST IN LOOP AT statement.

as

loop at itab.

collect.

......

endloop.

if helpful reward some points.

with regards,

Suresh Aluri.

Read only

Former Member
0 Likes
895

loop at itab into wa.

collect wa to itab..

endloop.

if helpful reward some points.

Read only

Former Member
0 Likes
895

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.

Read only

0 Likes
895

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.