Application Development and Automation 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: 
Read only

Count distinct occurrences

Former Member
0 Likes
901

Hello! Lemme explain my cenario:

I've got this structure, in my infocube    


DAD     SON

1           1
1           2
1           3
2           1
2           2

__________               

TOTAL:     X           5

I have the total for my sons but not for my dads(which X = 2 in that case). The total for the son is calculated using a keyfigure that comes even from my source system, each fills 1 for each line Ive got. Now, I need the total for the DAD ocurrences. Im really new in ABAP and such, how do I manage to work on it?

Thanks a lot!

1 ACCEPTED SOLUTION
Read only

former_member196651
Contributor
0 Likes
815

Hi Andrade,

Hope you are getting these values in an internal table. If so, what you need to do is to copy the values of your internal table to a temporary internal table. Then sort table based on the field DAD. Then delete the adjacent duplicates from the temp. table and final number of count in the temp table will give you the DAD count. For example if ITAB is the internal table where you are getting the above data. Then do as follows:

itab_temp[]     =     ITAB[].

SORT itab_temp BY DAD ASCENDING.

DELETE ADJACENT DUPLICATES FROM itab_temp COMPARING dad.

DESCRIBE TABLE itab_temp LINES lv_count.

The variable lv_count will contain the number of dad.

Regards,

Abijith

Hello! Lemme explain my cenario:

I've got this structure, in my infocube    


DAD     SON

1           1
1           2
1           3
2           1
2           2

__________               

TOTAL:     X           5

I have the total for my sons but not for my dads(which X = 2 in that case). The total for the son is calculated using a keyfigure that comes even from my source system, each fills 1 for each line Ive got. Now, I need the total for the DAD ocurrences. Im really new in ABAP and such, how do I manage to work on it?

Thanks a lot!

2 REPLIES 2
Read only

former_member196651
Contributor
0 Likes
816

Hi Andrade,

Hope you are getting these values in an internal table. If so, what you need to do is to copy the values of your internal table to a temporary internal table. Then sort table based on the field DAD. Then delete the adjacent duplicates from the temp. table and final number of count in the temp table will give you the DAD count. For example if ITAB is the internal table where you are getting the above data. Then do as follows:

itab_temp[]     =     ITAB[].

SORT itab_temp BY DAD ASCENDING.

DELETE ADJACENT DUPLICATES FROM itab_temp COMPARING dad.

DESCRIBE TABLE itab_temp LINES lv_count.

The variable lv_count will contain the number of dad.

Regards,

Abijith

Read only

0 Likes
815

Thank you!

Imma try something similar, to create a new keyfigure and fill 1 on it for each single dad occurrence I find, using the temp table. Like this I think I can also show the subtotals.