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: 

Some questions regarding CL_SALV_TABLE

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

4 REPLIES 4

SuhaSaha
Advisor
Advisor
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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.

0 Kudos

Thanks for the reply, this solves the issue!