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

cl_salv_table - Problem with aggregating rows

mario_maisto
Participant
9,397

Hi,

Does anyone have a solution to an issue where the row aggregation does not display when using the cl_salv_table's add_aggregation method? I do not get any type of error (e.g. "column not found") - just the totals are not shown, whereas the add_sort method (assigned with a similar style) is working properly.

When the table is displayed and I select the corresponding column of DMBTR and press the total button, the totals are shown correctly.


Here's my sample code -

* x.1 Test
 DATA: BEGIN OF ls,
 lifnr TYPE elifn,
 dmbtr TYPE dmbtr_cs,
 END OF ls,
 lt_table LIKE TABLE OF ls
 .
 SELECT lifnr, dmbtr FROM mseg 
   INTO CORRESPONDING FIELDS OF TABLE @lt_table UP TO 15 ROWS.

 cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lr_result_salv)
 CHANGING t_table = lt_table ).

 lr_result_salv->get_functions( )->set_all( 'X' ).
 lr_result_salv->get_sorts( )->add_sort( columnname = 'LIFNR' subtotal = 'X' ).
 lr_result_salv->get_aggregations( )->add_aggregation( columnname = 'DMBTR' ).

 lr_result_salv->display( ).

The displayed result:

Wished result (same as pressing the 'Total' button)

Am i missing something?

Thank you for your help 🙂 !

Regards,
Mario

1 ACCEPTED SOLUTION
Read only

abo
Active Contributor
8,366

Could it be an error in the ALV code itself?

There is a corrective note with a very interesting description!

20 REPLIES 20
Read only

Sandra_Rossi
Active Contributor
0 Likes
8,366

Your code should work fine.

What type is data element DMBTR_CS? (you should define it with TYPE MSEG-DMBTR to avoid problems)

Did you define a default layout variant that overwrites the layout defined in your code?

Read only

RaymondGiuseppi
Active Contributor
Read only

mario_maisto
Participant
0 Likes
8,366

Hi Sandra, thank you for your input!

DMBTR_CS is the data element assigned for the field DMBTR in the table of MSEG (so there shouldn't be any problem with it - I just in case tried with the dmbtr type mseg-dmbtr also - no dice, same result).

The the code should work fine - every documentation and post I went through seem to say so 🙂 - yet something is missing.

For the layout - I did not define anything else seen from the sample code (nor did I changed it in the GUI). It seems weird, because the total function works when initiated from the button in GUI.

I had a problem with optimizing the columns where r_column->set_optimized( 'X' ) did not do the trick and I had to add the overall optimize for the r_columns( )->set_optimize( 'X' ) as well - maybe there's something similar missing here with the aggregations (did not find any info on it though).

Read only

FredericGirod
Active Contributor
0 Likes
8,366
Read only

RaymondGiuseppi
Active Contributor
8,366
  • Could you perform The Consistancy Check of the ALV grid?
  • Did you recently apply 'Amount Field Length Extension'
Read only

8,365
  • Did the check - have some errors.. Can this be the reason ?

  • Have to check.
Read only

0 Likes
8,365

Could you look at f

  • Fields definition on MSEG with SE11 (length 13,2 or 23,2)
  • Fields definition in the field catalog (thru Consustency Check)
  • Do you work in a HANA sandbox, not every module activated?
  • Is somebody testing 2628654 - S4TWL: Amount Field Length Extension?
Read only

0 Likes
8,365

Hi, im looking into it.
The field length in mseg for dmbtr is 13,2.

Read only

Sandra_Rossi
Active Contributor
8,365

raymond.giuseppi I don't have this extension, so I couldn't know. So I guess that DMBTR_CS has type CURR 23 / 2.

  • "In SAP S/4HANA, currency amount fields with a field length between 9-22 including 2 decimals have been extended to 23 digits including 2 decimals."
mario.maisto In that case, there must be a bug in the standard code or SAP GUI, search for SAP notes. In my case, I copied your code and it works perfectly well (except that I replaced DMBTR_CS which doesn't exist in my S/4HANA).
Read only

mario_maisto
Participant
0 Likes
8,365

Frederic - but I do, with the line of (You can see the lifnr sorted on my first image 'is.png' 😞

lr_result_salv->get_sorts()->add_sort( columnname ='LIFNR' subtotal ='X').

Read only

mario_maisto
Participant
0 Likes
8,365

Sandra Rossi - so you had the same code, but with dmbtr TYPE mseg-dmbtr ? And it worked?
I'll try one more time 🙂

Read only

mario_maisto
Participant
0 Likes
8,365

Did not work.

Read only

FredericGirod
Active Contributor
0 Likes
8,365

Maybe because MSEG-DMBTR is also based on DMBTR_CS

did you try with a "simple" dmbtr like DMBTRV ?

Read only

mario_maisto
Participant
0 Likes
8,365

Hi Frederic, Thank you for the input - I tried with the element of DMBTRV - did not work.


If the data type is wrong, shouldn't it be the same case then when pressing the 'Totals' button manually ?

Read only

mario_maisto
Participant
0 Likes
8,365

I also tried casting with no result..

SELECT lifnr, CAST( dmbtr AS DEC( 8, 2 ) ) AS dmbtr 
FROM mseg INTO CORRESPONDING FIELDS OF TABLE @lt_table UP TO 15 ROWS.
Read only

FredericGirod
Active Contributor
8,365

Honestly your problem is really strange.

This code works also for me (SAP ECC 😞

SELECT lifnr, dmbtr FROM mseg
   INTO TABLE @data(lt_table) UP TO 15 ROWS.


 cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lr_result_salv)
 CHANGING t_table = lt_table ).


 lr_result_salv->get_functions( )->set_all( 'X' ).
 lr_result_salv->get_sorts( )->add_sort( columnname = 'LIFNR' subtotal = 'X' ).
 lr_result_salv->get_aggregations( )->add_aggregation( columnname = 'DMBTR' ).


 lr_result_salv->display( ).
Read only

mario_maisto
Participant
8,365

Yes.. strange.
First I started with a dynamic table definition also with

SELECT lifnr, CAST( dmbtr AS DEC( 8, 2 ) ) AS dmbtr FROM mseg 
INTO TABLE @DATA(lt_tablex) UP TO 15 ROWS.
.. When this didn't work, I defined a test type before hoping this would solve the issue. It did not. Apparently.

So - it may be a bug in my system then - my sample code seems to work in other systems :P.

Thank you again for your help.
Read only

abo
Active Contributor
8,367

Could it be an error in the ALV code itself?

There is a corrective note with a very interesting description!

Read only

Sandra_Rossi
Active Contributor
0 Likes
8,365
    Summary of note 2957556 - ALV-OM: Totals row is not displayed:

  • "The ALV is called in the object model (CL_SALV_TABLE). At the interface, aggregations are set for column objects."
  • SAP_BASIS 781
  • Read only

    mario_maisto
    Participant
    0 Likes
    8,365

    Andrea Borgia - for some reason I cannot reply to your answer (Add a Comment does nothing), so I have to write here -

    The note indeed looks like something that may help, but it does not suit for my basis version of 755. Also did not find anything on the mentioned hotfix.