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: 

ALV GRID: Count values in Totals row.

Former Member
0 Kudos

Hi gurus,

I have an ALV GRID and I have this requeriment:

"In Totals row, there must be the numbers of rows where the field FLAG is set to 'X''.

I'm calling the totals row with IT_SORT parameter in 'REUSE_ALV_GRID_DISPLAY' and setting the attribute DO_SUM in the fieldcat for the fields I need to sumarize; but I need to count how many rows have value 'X'.

How can I do this? Some ideas?

An Example of what I need:

Col.A | Col.B

1000 | X

2000 |

3000 | X

_____________________

6000 | 2 <- TOTALS ROW

A lot of thanks.

Edited by: Ole ES on May 11, 2009 9:18 PM

10 REPLIES 10

anuj_srivastava
Active Participant
0 Kudos

Hi ,

For this u can add one more field into ur internal table and loop through the table to update the field according to the field marked as 'X' and modify the table.

Now u can give this table to ALV dispaly with the total of the new field giving the total no of records having specific field marked as 'X'

Regards,

Anuj

Edited by: ANUJ SRIVASTAVA on May 12, 2009 1:05 AM

former_member194669
Active Contributor
0 Kudos

May be check this thread

Former Member
0 Kudos

Create a Col3 as integer type and move a 1 to it for every occurance of X in Col2. You can then hide Col2.

0 Kudos

I've already thought in that solution...but I need the totals under the colum with 'X'.

I've started thinking my requeriment is not possible; at least, not easily possible

0 Kudos

I havent' found a solution yet...

¿Some more ideas?

Edited by: Ole ES on May 14, 2009 2:53 PM

0 Kudos

Its simple but you dont need to use do_sum now.

Suppose your internal table is itab with column names as A and B.

itab

A B

3000 X

2000

1000 X

data final type i.

data count type i.

Loop at itab into wa.

final = wa-A + final.

if wa-B = 'X'.

count = count + 1.

endif.

endloop.

wa-A = final.

wa-B = count.

append wa to itab.

I think this will solve your problem and u dont need to do do_sum.

0 Kudos

I think this is not a solution for my issue.

What I need is show a number in totals row; but in the normal rows, I need to show 'X'.

Colum A

X

X

X

X

___

4 <- Totals Row that appears with 'do_sum' at fieldcat.

0 Kudos

the value of count is having the number of 'X' in your table. And u can store this count value in the same column and append this row at the end of your table. My code should work fine. Have u tried??

0 Kudos

Your code works great; but I need 'do_sum' at all because I need to sumarize another fields too; and I want to preserve standard ALV funcion buttons.

If I compute in my programa the totals row; I lose the ALV control when pushing sorting buttons, for example.

Edited by: Ole ES on May 14, 2009 4:15 PM

Former Member
0 Kudos

No solution by now.