2021 Jan 22 8:24 AM
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
2021 Jan 22 2:28 PM
Could it be an error in the ALV code itself?
There is a corrective note with a very interesting description!
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.
2021 Jan 22 12:35 PM
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?
2021 Jan 22 12:52 PM
sandra.rossi , check 2628654 - S4TWL: Amount Field Length Extension
2021 Jan 22 12:53 PM
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).
2021 Jan 22 12:58 PM
2021 Jan 22 12:59 PM
2021 Jan 22 1:49 PM

2021 Jan 25 8:09 AM
Could you look at f
2021 Jan 25 9:02 AM
Hi, im looking into it.
The field length in mseg for dmbtr is 13,2.
2021 Jan 22 1:00 PM
raymond.giuseppi I don't have this extension, so I couldn't know. So I guess that DMBTR_CS has type CURR 23 / 2.
2021 Jan 22 1:01 PM
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').
2021 Jan 22 1:05 PM
Sandra Rossi - so you had the same code, but with dmbtr TYPE mseg-dmbtr ? And it worked?
I'll try one more time 🙂
2021 Jan 22 1:12 PM
2021 Jan 22 2:02 PM
Maybe because MSEG-DMBTR is also based on DMBTR_CS
did you try with a "simple" dmbtr like DMBTRV ?
2021 Jan 22 2:06 PM
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 ?
2021 Jan 22 2:09 PM
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.
2021 Jan 22 2:13 PM
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( ).
2021 Jan 22 2:19 PM
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.2021 Jan 22 2:28 PM
Could it be an error in the ALV code itself?
There is a corrective note with a very interesting description!
2021 Jan 22 5:35 PM
2021 Jan 25 12:56 PM
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.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |