07-16-2008 2:17 PM
hi,
i have data as follows in my internal table
aaa bbbb ccc
100 xxxx 5
200 xxxx 3
300 yyyy 9
I need to group by "bbbb" and count of records based on column "bbbb" of my internal table
xxxx 2
yyyy 1
whats the abap statement(s) for this ?
thks
07-16-2008 2:23 PM
Hi you can try;
AT END OF <field-xxx>.
count = count + 1.
ENDAT.
<removed_by_moderator> <= read [the rules|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/rulesofEngagement] here!
Regards,
Prabhu Rajesh
Edited by: Julius Bussche on Jul 16, 2008 2:52 PM
07-16-2008 2:25 PM
sort itab by bbbb.
data lv_count type i.
loop at itab.
add 1 to lv_count.
at end of bbbb.
field = itab-bbbb.
total = lv_count.
clear lv_count.
endat.
endloop.
Hope this helps
//Kothand
07-16-2008 2:33 PM
Hi
You can below logic-
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
07-16-2008 4:01 PM
hi,
because bbb is not the first field of the internal tables, all of these AT LAST... things won't work. best is if you create a 2nd itab with only bbb and ccc fields than:
LOOP AT itab.
itab2-bbb = itab-bbb.
itab2-ccc = itab-ccc.
COLLECT itab2.
ENDLOOP.
after this you have the summerized values in itab2
hope this helps
ec
07-16-2008 4:57 PM
I dont need SUM of values of third column. I need the count (number of records) based on second column.
07-16-2008 5:00 PM
sorry...
than declare ccc as integer in itab2 and change in my code:
itab2-ccc = itab-ccc ==> itab2-ccc = 1.
the rest of the code is OK
07-16-2008 7:12 PM
I suppose my logic should be as follows:
read itab into wa_itab index 1.
l_var = wa_itab-var.
count = 0.
loop at itab into wa_itab.
if wa_itab-var = l_var.
count = count + 1.
else.
processing logic
count = 0.
l_var = wa_itab-var.
count = count + 1.
endif.
endloop.
repeat processing logc here. (this is to ensure that the last set of records are also processed).
hope i am clear.
thanks
07-16-2008 7:13 PM