cancel
Showing results for 
Search instead for 
Did you mean: 

regarding alv function of summing up the values of columns.

Former Member
0 Kudos

hi friends:

could you please tell me how to sum up the values of columns.

for example, there are columns of room rent, expense of cell phone call,

expense of taxi fee.

thank you very much

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Do you want to know the steps an end user can perform to create this summation on columns at runtime via configuration or do you want a code sample of how to set this programatically?

Former Member
0 Kudos

actually I just heard it could be done programingly, could you please tell me how to configure it ?

Edited by: jingying Sony on Jun 8, 2010 6:41 AM

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

To configure summation at runtime. You first go into the settings dialog:

http://www.flickr.com/photos/tjung/4682009168/

Then you have a Calculation Tab where any fields that are suitable for some sort of calculation are listed.

http://www.flickr.com/photos/tjung/4682009184/in/photostream/

If you don't see the Calculation Tab, you might need to allow it via code in the initialization of the ALV model. You might try this code to activate the calculation configuration options:

DATA: l_ref_cmp_usage TYPE REF TO if_wd_component_usage.
  l_ref_cmp_usage =   wd_this->wd_cpuse_alv( ).
  IF l_ref_cmp_usage->has_active_component( ) IS INITIAL.
    l_ref_cmp_usage->create_component( ).
  ENDIF.

  DATA l_salv_wd_table TYPE REF TO iwci_salv_wd_table.
  l_salv_wd_table = wd_this->wd_cpifc_alv( ).
  DATA l_table TYPE REF TO cl_salv_wd_config_table.
  l_table = l_salv_wd_table->get_model( ).

  l_table->if_salv_wd_std_functions~set_count_records_allowed( abap_true ).
  l_table->if_salv_wd_std_functions~set_aggregation_allowed( abap_true ).

Former Member
0 Kudos

Hi Thomas :

thank you very much for your reply, but seems that configuration of alv can't meet the requirement, because I have to sum up more than one column, for example, sum up room rent( 1000) and cell phone call expense(100), so there sould be a total value of 1100.

can you please give some suggestions to accomplish it by programming?

Person room rent cell phone

A1 1000 200

A2 1500 300

A3 2000 400

subtotal 4500 900

total 5400

thanks again!

Edited by: jingying Sony on Jun 9, 2010 7:21 AM

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> Hi Thomas :

>

> thank you very much for your reply, but seems that configuration of alv can't meet the requirement, because I have to sum up more than one column, for example, sum up room rent( 1000) and cell phone call expense(100), so there sould be a total value of 1100.

> can you please give some suggestions to accomplish it by programming?

>

> Person room rent cell phone

> A1 1000 200

> A2 1500 300

> A3 2000 400

> subtotal 4500 900

> total 5400

>

> thanks again!

>

> Edited by: jingying Sony on Jun 9, 2010 7:21 AM

There is no built in functionality to total cross-column like that. You would need need to add another attribute to the context and caculate the addition of the two columns within your internal table before you bind it to the context.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Refer to the SAP help on [Calculation (Aggregation)|http://help.sap.com/saphelp_nw70/helpdata/en/5c/cf9e94c2054990a87b1ed409415f23/content.htm] and use the method CREATE_AGGR_RULE of class CL_SALV_WD_AGGR_RULE.

For the coding prospective check ot the Thread[Webdynpro ABAP - ALV how can i display Total of Column|;.

Hope it helps.

Former Member
0 Kudos

hi For calculating one more coloum . try this logic

write this piece of code in wddoinit

data : lt_column type salv_wd_t_column_ref,
         ls_column type salv_wd_s_column_ref,
         lo_aggr_rule TYPE REF TO cl_salv_wd_aggr_rule.

* display columns in correct order
  lr_column_settings ?= wd_this->lr_config.
  lt_column = lr_column_settings->get_columns( ).
loop at lt_column into ls_column.

    case ls_column-id.
      when 'ROOM_RENT'.
* aggregate field
        call method lr_config->if_salv_wd_field_settings~get_field
          exporting
            fieldname = 'ROOM_RENT'
          receiving
            value     = lr_room_rent_total.

* create aggregate rule as total
        call method lr_field_amnt->if_salv_wd_aggr~create_aggr_rule
          exporting
            aggregation_type = if_salv_wd_c_aggregation=>aggrtype_total
          receiving
            value            = lv_aggr_rule.

      when 'CALL'.
* aggregate field
        call method lr_config->if_salv_wd_field_settings~get_field
          exporting
            fieldname = 'CALL'
          receiving
            value     = lr_call_AVG.

* create aggregate rule as total
        call method lr_field_amnt->if_salv_wd_aggr~create_aggr_rule
          exporting
            aggregation_type = if_salv_wd_c_aggregation=>AGGRTYPE_AVERAGE
          receiving
            value            = lv_aggr_rule.
 
    endcase.
endloop.

Regards

Chinnaiya

Former Member
0 Kudos

I am trying your code, could you please tell me how you declare variable lr_field_amnt?

Former Member
0 Kudos

Hi,

DATA:

lo_field_settings TYPE REF TO if_salv_wd_field_settings,

lo_field TYPE REF TO cl_salv_wd_field,

lo_aggr_rule TYPE REF TO cl_salv_wd_aggr_rule.

lo_table = lo_interfacecontroller->get_model( ).

lo_field_settings ?= lo_table.

**get field and create aggregation rule of type total

lo_field = lo_field_settings->get_field( 'PRAMT' ).

lo_field->if_salv_wd_aggr~create_aggr_rule( ).

lo_aggr_rule = lo_field->if_salv_wd_aggr~get_aggr_rule( ).

lo_aggr_rule->set_aggregation_type( if_salv_wd_c_aggregation=>aggrtype_total ).

use this code to sum up the particular column.

where PRAMT is the field name for which you want to calculate the sum.

Hope this will help you.

Thanks & Regards,

Arvind

Edited by: Arvind Patel on Jun 7, 2010 11:06 AM