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: 

aggregate of columns of data

Former Member
0 Kudos

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

8 REPLIES 8

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

JozsefSzikszai
Active Contributor
0 Kudos

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

0 Kudos

I dont need SUM of values of third column. I need the count (number of records) based on second column.

0 Kudos

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

0 Kudos

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

Former Member
0 Kudos

resolved myself