on 06-07-2010 9:44 AM
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ).
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
>
> 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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.