04-25-2007 11:51 AM
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.
04-25-2007 11:54 AM
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
04-25-2007 11:55 AM
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
04-25-2007 2:38 PM
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.
04-25-2007 2:43 PM
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..
04-25-2007 2:48 PM
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.
04-25-2007 2:51 PM
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
04-25-2007 2:51 PM
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