10-27-2011 3:43 AM
Hi everyone,
I am dealing with a problem in generating an ALV Grid table.
I am creating a customized report which requires me to total up the fields in the report similar to the standard transaction MB52,
which looks like this:
http://i1129.photobucket.com/albums/m513/Saltyfish89/ScreenHunter_01Oct271031-1.jpg
notice the total of unrestricted is categorized by unit
but when I implement the aggregation method in SALV, this is what i get:
http://i1129.photobucket.com/albums/m513/Saltyfish89/ScreenHunter_02Oct271032.jpg
For further reference I used the get sort and get aggregation method in SALV.
FORM set_sort .
* Sort
g_sorts = g_alv->get_sorts( ).
TRY.
g_sort = g_sorts->add_sort(
columnname = 'MEINS'
sequence = if_salv_c_sort=>sort_up
group = if_salv_c_sort=>group_with_underline
subtotal = abap_true ).
g_sort = g_sorts->add_sort(
columnname = 'VRKME'
sequence = if_salv_c_sort=>sort_up
group = if_salv_c_sort=>group_with_underline
subtotal = abap_true ).
CATCH cx_salv_data_error.
ENDTRY.
ENDFORM.
FORM set_aggregation .
* Aggregation
g_aggr = g_alv->get_aggregations( ).
* g_aggr->SET_AGGREGATION_BEFORE_ITEMS( ).
g_aggr->SET_NUMERICAL_AGGREGATION( ).
TRY. "NETWR
CALL METHOD g_aggr->add_aggregation
EXPORTING
columnname = 'TBUOM'
aggregation = if_salv_c_aggregation=>total.
CATCH cx_salv_data_error .
CATCH cx_salv_not_found .
CATCH cx_salv_existing .
ENDTRY.
* Aggregation
g_aggr = g_alv->get_aggregations( ).
TRY. "NETWR
CALL METHOD g_aggr->add_aggregation
EXPORTING
columnname = 'TSUOM'
aggregation = if_salv_c_aggregation=>total.
CATCH cx_salv_data_error .
CATCH cx_salv_not_found .
CATCH cx_salv_existing .
ENDTRY.
* Aggregation
g_aggr = g_alv->get_aggregations( ).
TRY. "NETWR
CALL METHOD g_aggr->add_aggregation
EXPORTING
columnname = 'TVAL'
aggregation = if_salv_c_aggregation=>total.
CATCH cx_salv_data_error .
CATCH cx_salv_not_found .
CATCH cx_salv_existing .
ENDTRY.
ENDFORM.
Hope the gurus here could provide me with some insight on how to achieve that by using SALV.
Edited by: Saltyfish on Oct 27, 2011 4:43 AM
11-01-2011 1:34 PM
Hi,
This is not a problem of sorting or aggregation. It is just because you forgot to reference the unit column to your value column.
You have to call the method set_quantity_column. You can leave the sort on unit fields...
something like:
DATA: gr_columns TYPE REF TO cl_salv_columns_table,
gr_column TYPE REF TO cl_salv_column_table.
gr_columns = g_alv->get_columns( ).
TRY.
gr_column ?= gr_columns->get_column( 'TVAL' ).
gr_column->set_quantity_column( 'MEINS' ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
Kr,
Manu.
10-27-2011 7:35 AM
Hello,
This is because you've advised the SALV model to perform a sub-total based on the Unit:
g_sort = g_sorts->add_sort(
columnname = 'MEINS'
sequence = if_salv_c_sort=>sort_up
group = if_salv_c_sort=>group_with_underline
subtotal = abap_true ).
Try to remove the sub-total flag & check!
BR,
Suhas
10-27-2011 10:04 AM
Hi Suhas,
Thanks for your reply, however after I removed the subtotal from the sort function, the output ended up like this :
http://i1129.photobucket.com/albums/m513/Saltyfish89/ScreenHunter_06Oct271701.jpg
Any other ways to rectify this matter?
I would very appreciate if you could further guide me in solving this issue. Thanks.
11-01-2011 1:34 PM
Hi,
This is not a problem of sorting or aggregation. It is just because you forgot to reference the unit column to your value column.
You have to call the method set_quantity_column. You can leave the sort on unit fields...
something like:
DATA: gr_columns TYPE REF TO cl_salv_columns_table,
gr_column TYPE REF TO cl_salv_column_table.
gr_columns = g_alv->get_columns( ).
TRY.
gr_column ?= gr_columns->get_column( 'TVAL' ).
gr_column->set_quantity_column( 'MEINS' ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
Kr,
Manu.
11-02-2011 2:20 AM