2007 Apr 25 1:15 PM
Hello,
I have fetched records from a table into my internal table through, " SELECT * FROM .... INTO TABLE FOR ALL ENTRIES IN ...... "
There are two columns in my internal table against which i need a total of the column. COLLECT sums the amounts . But how can i use COLLECT in this scenario ?
Can anyone kindly guide me ...Thanks
Shehryar Dahar
Hello,
I have fetched records from a table into my internal table through, " SELECT * FROM .... INTO TABLE FOR ALL ENTRIES IN ...... "
There are two columns in my internal table against which i need a total of the column. COLLECT sums the amounts . But how can i use COLLECT in this scenario ?
Can anyone kindly guide me ...Thanks
Shehryar Dahar
2007 Apr 25 1:17 PM
Hi shehryar,
Collect statement is used to collect the all values and place into one.
For Example,
Emp.no Salary
1 1000
2 1000
3 1000
1 1000
4 1000.
Here The Emp.no 1 Comes Twice. So it will add the values like,
1 2000
2 1000
3 1000
4 1000.
for your Requirement,
collect IT.
Thanks.
2007 Apr 25 1:18 PM
collect will occur only on the first field in your internal table...
2007 Apr 25 1:20 PM
Hi
Collect command is used to sum up numeric values only when their non numeric values are equal.
Eg: itab contains 2 coloums
f1 f2
a 10
b 10
a 20
c 21
d 23
b 10
Here when u give collect statement it will add numeric values of a and b ony not c and d their non numeric values are not same.
Hope u understood the point
Regards
Haritha.
2007 Apr 25 1:21 PM
Create a temp internal table of the same structure.
Loop at Itab1 into wa.
COLLECT wa INTO itab2.
endloop.
ur itab2 will have the sums..
but if u want the totals of the column..
i would suggest you to go for control break statements.
loop at itab into wa.
at last.
sum.
endat.
endloop.
u will have the sums populated in ur wa
santhosh
2007 Apr 25 1:23 PM
Hi,
COLLECT add the numeric entries for the corresponding table keys..
Example.
-
DATA: BEGIN OF ITAB OCCURS 0,
MATNR TYPE MATNR,
COUNT TYPE I,
END OF ITAB.
ITAB-MATNR = 'ABC'.
ITAB-COUNT = 2.
COLLECT ITAB.
ITAB-MATNR = 'ABC'.
ITAB-COUNT = 1.
COLLECT ITAB.
ITAB-MATNR = 'ABCD'.
ITAB-COUNT = 2.
COLLECT ITAB.
ITAB-MATNR = 'ABCD'.
ITAB-COUNT = 3.
COLLECT ITAB.
LOOP AT ITAB.
WRITE: / ITAB-MATNR, ITAB-COUNT.
ENDLOOP.
For more information on Collect, check this site:
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/collect.htm
Hope this would help you out.
Regards,
Varun.
2007 Apr 25 1:39 PM
Hi,
Check this Sample code.
TYPES: BEGIN OF t_team,
NAME(20) TYPE C,
score TYPE I,
END OF t_team.
DATA : i_team TYPE STANDARD TABLE OF t_team INITIAL SIZE 0,
wa_team type t_team.
wa_team-NAME = 'Sachin'.
wa_team-score = 10.
COLLECT wa_team INTO i_team.
wa_team-NAME = 'Gangully'.
wa_team-score = 70.
COLLECT wa_team INTO i_team.
wa_team-NAME = 'Sachin'.
wa_team-score = 40.
COLLECT wa_team INTO i_team.
loop at i_team into wa_team.
write: / 'Name :', wa_team-name, 'Scored : ', wa_team-score.
endloop.
Regards,
Suresh
2007 Apr 25 2:06 PM
Got it myself. I guess you all didnt get the question.. thanks a lot though !!!
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |