Application Development 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: 

collect

Former Member
0 Kudos

the itab contains the following fields.

sno

sname

smarks

sno sname smarks

1 srinivas 100

2 sri 99

3 srija 89

4 srinivas 45

by using the collect statement i have to add numeric fields and print.how can i write the collect statement plz expalin me.

7 REPLIES 7

Former Member
0 Kudos

Collect statement will add the numeric fields automatically.

Just try this simple code it will work.

loop at itab.

collect itab.

endloop.

loop at itab.

write: / itab-sno,itab-sname,itab-smarks.

endloop.

Thanks & Regards

Santhosh

Message was edited by:

Santhosh

Former Member
0 Kudos

Hi,

First of all the sno field has to be char field, then simply COLLECT ITAB, if the itab contains header line. or collect wa into itab.

Amitava

Former Member
0 Kudos

hi,

collect is just like append statement.where it compares all the record in the body with the record present in the field string...if the record does not exists then it gets appended or else if they r integer values then they get added even numeric values get added if the record exists..

if u feel tht it is an useful answer then reward with points,

with regards,

madhuri.

Former Member
0 Kudos

i t adds numeric fields if a similar record exists els it appends it...

in ur exp

each record is unique they gets appeds at end it does not adds..

if u have again record with sam info but diff nueric field it adds..

Former Member
0 Kudos

when you have the following statement.

COLLECT [wa INTO] itab.

It will autometically add up the neumerical velues when the other character fields remail same.

0 Kudos

Example

Summarized sales figures by company:

TYPES: BEGIN OF COMPANY, 
        NAME(20) TYPE C, 
        SALES    TYPE I, 
      END OF COMPANY. 

DATA: COMP    TYPE COMPANY, 
      COMPTAB TYPE HASHED TABLE OF COMPANY 
                                WITH UNIQUE KEY NAME. 

COMP-NAME = 'Duck'.  COMP-SALES = 10. COLLECT COMP INTO COMPTAB. 
COMP-NAME = 'Tiger'. COMP-SALES = 20. COLLECT COMP INTO COMPTAB. 
COMP-NAME = 'Duck'.  COMP-SALES = 30. COLLECT COMP INTO COMPTAB

.

Table COMPTAB now has the following contents:

NAME | SALES

-


Duck | 40

Tiger | 20

Former Member
0 Kudos

Hi,

sno sname smarks

1 srinivas 100

2 sri 99

3 srija 89

4 srinivas 45

sno should be a non-numeric field. After using collect instead append the result

will be

1 srinivas 100

2 sri 99

3 srija 89

4 srinivas 45

as sno sname fileds combination is unique for all the rows.

IF

1 srinivas 100

2 sri 99

3 srija 89

1 srinivas 45

then result of collect is

1 srinivas 145

2 sri 99

3 srija 89

If helpful reward points,

Regards,

Tanmay