07-16-2007 12:02 PM
Hi,
I m working in internal tables.
I want to hav records like
data : begin of itab occurs 0,
name1(10) type c
id type i,
amount type i,
end of itab.
so i m inserting few records like
<code>
name1 id amount
p1 10 100
p1 10 200
p1 10 300
p2 20 400
p2 20 250
</code>
so i want to use collect and add the numeric fields.
I want to know how to do it.
Regrads,
Kavita
07-16-2007 12:05 PM
Hi,
Try this,
data : begin of itab occurs 0 with key name1 id,
name1(10) type c
id type i,
amount type i,
end of itab.
loop at itab.
collect itab.
endloop.
Regards,
Padmam.
07-16-2007 12:06 PM
DATA: BEGIN OF seats,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
seatsocc TYPE sflight-seatsocc,
END OF seats.
DATA seats_tab LIKE HASHED TABLE OF seats
WITH UNIQUE KEY carrid connid.
SELECT carrid connid seatsocc
FROM sflight
INTO seats.
COLLECT seats INTO seats_tab.
ENDSELECT.
Check the above example...
Regards,
Pavan
07-16-2007 12:06 PM
07-16-2007 12:06 PM
Hi,
First of all I feel that ID should not be a numeric field i.e. it should be a character field instead of I because when we use Collect then ID will also get summed up which is not correct.
Hence declare ID as ID(2) type c.
Then use the following code:
ITAB-NAME = 'P1'.
ITAB-ID = '10'.
ITAB-AMOUNT = 100.
COLLECT ITAB.
This will sum up the numeric fields.
Regards,
Himanshu
07-16-2007 12:07 PM
Hello,
Try as follows and <b>reward if found helpfull</b>.
LOOP AT itab INTO wrk_area.
COLLECT wrk_area INTO itab2.
ENDLOOP.
<b>
itab, itab2 and wrk_area must be of same line type.
</b>
regards,
Rakesh.