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: 

I need the grand total for particular coulumn for ALV grid report(OOPs).

Former Member
0 Kudos

Hello,

I have used the following code,

But i m not getting the grand total by default.No error but not getting the desired result.

Could you please help me in this regard.

FORM display_simple_alv.

DATA : lr_msg TYPE REF TO cx_salv_msg.

DATA : lv_header TYPE REF TO cl_salv_form_layout_grid,

lv_h_label TYPE REF TO cl_salv_form_label,

lv_h_flow TYPE REF TO cl_salv_form_layout_flow.

DATA: gr_sorts TYPE REF TO cl_salv_sorts.

DATA: gr_agg TYPE REF TO cl_salv_aggregations.

TRY .

cl_salv_table=>factory( IMPORTING r_salv_table = gr_salv_table

CHANGING t_table = gt_invdetails4 ).

CATCH cx_salv_msg INTO lr_msg.

ENDTRY .

  • Display Basic Toolbar

gr_functions = gr_salv_table->get_functions( ).

gr_functions->set_all( abap_true ).

TRY .

gr_columns = gr_salv_table->get_columns( ).

gr_columns->set_optimize( ).

CATCH cx_salv_not_found.

ENDTRY .

*

TRY .

gr_column ?= gr_columns->get_column( 'KUNNR' ).

gr_column->set_long_text( text-009 ).

gr_column->set_medium_text( text-009 ).

gr_column->set_short_text( text-009 ).

gr_column ?= gr_columns->get_column( 'NAME1' ).

gr_column->set_long_text( text-010 ).

gr_column->set_medium_text( text-010 ).

gr_column->set_short_text( text-011 ).

gr_column ?= gr_columns->get_column( 'AMOUNT' ).

gr_column->set_long_text( text-012 ).

gr_column->set_medium_text( text-012 ).

gr_column->set_short_text( text-012 ).

gr_column ?= gr_columns->get_column( 'TAX' ).

gr_column->set_long_text( text-013 ).

gr_column->set_medium_text( text-013 ).

gr_column->set_short_text( text-013 ).

gr_column ?= gr_columns->get_column( 'IVA' ).

gr_column->set_long_text( text-014 ).

gr_column->set_medium_text( text-014 ).

gr_column->set_short_text( text-015 ).

gr_column ?= gr_columns->get_column( 'TOTAL_AMOUNT' ).

gr_column->set_long_text( text-016 ).

gr_column->set_medium_text( text-016 ).

gr_column->set_short_text( text-017 ).

gr_column ?= gr_columns->get_column( 'CURRENCY' ).

gr_column->set_long_text( text-018 ).

gr_column->set_medium_text( text-018 ).

gr_column->set_short_text( text-018 ).

gr_column ?= gr_columns->get_column( 'ZINTERNAL_REFNO' ).

gr_column->set_long_text( text-019 ).

gr_column->set_medium_text( text-019 ).

gr_column->set_short_text( text-019 ).

gr_column ?= gr_columns->get_column( 'MATERIAL_AMOUNT' ).

gr_column->set_long_text( text-020 ).

gr_column->set_medium_text( text-020 ).

gr_column->set_short_text( text-021 ).

gr_column ?= gr_columns->get_column( 'LABOUR_VALUE' ).

gr_column->set_long_text( text-022 ).

gr_column->set_medium_text( text-022 ).

gr_column->set_short_text( text-023 ).

gr_column ?= gr_columns->get_column( 'FAILURE_COST' ).

gr_column->set_long_text( text-024 ).

gr_column->set_medium_text( text-024 ).

gr_column->set_short_text( text-021 ).

gr_sorts = gr_salv_table->get_sorts( ).

gr_sorts->add_sort( columnname = 'AMOUNT' subtotal = abap_true ). "for subtotal

gr_agg = gr_salv_table->get_aggregations( ).

gr_agg->add_aggregation( 'AMOUNT' ).

CATCH cx_salv_not_found cx_salv_data_error cx_salv_existing.

ENDTRY .

    • Set top of page

CREATE OBJECT lv_header.

lv_h_label = lv_header->create_label( row = 1 column = 1 ).

lv_h_label->set_text( text-001 ).

lv_h_label = lv_header->create_label( row = 1 column = 5 ).

lv_h_label->set_text( text-002 ).

lv_h_label = lv_header->create_label( row = 1 column = 14 ).

lv_h_label->set_text( text-003 ).

lv_h_flow = lv_header->create_flow( row = 3 column = 04 ).

lv_h_flow->create_text( text = text-004 ).

lv_h_flow = lv_header->create_flow( row = 3 column = 05 ).

lv_h_flow->create_text( text = text-005 ).

lv_h_flow = lv_header->create_flow( row = 3 column = 06 ).

lv_h_flow->create_text( text = name ).

  • set the top of list using the header for Online.

gr_salv_table->set_top_of_list( lv_header ).

  • ALV Display

gr_salv_table->display( ).

ENDFORM . " DISPLAY_SIMPLE_ALV

3 REPLIES 3

Former Member
0 Kudos

can you post your code formatted as code.

Edited by: Jamie Bullen on Dec 7, 2009 3:57 PM

naimesh_patel
Active Contributor
0 Kudos

You need to use the aggregations using the class CL_SALV_AGGREGATIONS. Do a search for this class.

PS - We have limit of 2500 characters of a post.

Regards,

Naimesh Patel

Former Member
0 Kudos

Hi Sridevi,

To get the grand total, you need to pass the SORT itab to the function module. You need to populate the internal table with the fields on which you want the total or subtotal. If you donu2019t pass this table, you wonu2019t get it.

For ex:

ls_sort_wa-spos = 1.

ls_sort_wa-fieldname = gs_plant-werks.

ls_sort_wa-up = 'X'.

ls_sort_wa-subtot = 'X'.

APPEND ls_sort_wa TO gt_sort.

So the above code, gives the sub total plant wise.

and if you want the sum(grand total) you can set the DO_SUM to u2018Xu2019 for that particular field in the field catalog.

So with this approach, you can get the sub total and grand total for a particular field.

If you donu2019t want the subtotal, just set DO_SUM, you will get the total.

Thanks,

Srini.