on 05-27-2011 2:48 PM
Hai all,
Am using ALV table and I am having amount field in it. I want to sum all the amount values and should display that Sum.
How can I do the sum of these values. Am not fetching these values from any table. am giving that values in the Webdynpro screen in the alv table.
Please give some suggestions,
Thanks in advance,
Nalla.B
Hi Nalla,
Please check this wiki..
http://wiki.sdn.sap.com/wiki/display/Snippets/TotalsAndSubtotalsinALV+Webdynpros
Also check this..
Cheers,
Kris.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hai kris,
I am not getting any value for ALV table from db table, I am entering all the values in the alv table and saving it in the webdynpro screen itself and I have to calculate the total amount and I have to populate the same in a Field in the same screen.
I am not able to get the total in alv table. I have used the following code Pleae Give me some suggestions.
If am wrong correct me.
data:
lr_comp_alv type ref to if_wd_component_usage,
lr_comp_if_alv type ref to iwci_salv_wd_table,
lr_config type ref to cl_salv_wd_config_table.
"data: lr_column_settings type ref to if_salv_wd_column_settings.
"data: lr_column type ref to cl_salv_wd_column.
data: lr_column_header type ref to cl_salv_wd_column_header.
data : lt_column type salv_wd_t_column_ref,
ls_column type salv_wd_s_column_ref.
data: lr_field_amnt type ref to cl_salv_wd_field.
data: lv_aggr_rule type ref to cl_salv_wd_aggr_rule.
data: lr_sort_rule type ref to cl_salv_wd_sort_rule.
loop at lt_column into ls_column.
case ls_column-id.
when 'AMOUNT'.
aggregate field
call method lr_config->if_salv_wd_field_settings~get_field
exporting
fieldname = 'AMOUNT'
receiving
value = lr_field_amnt.
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.
endcase.
endloop.
Thanks in advance,
Nalla.B
Hi Nalla,
Try this..
data:
lr_comp_alv type ref to if_wd_component_usage,
lr_comp_if_alv type ref to iwci_salv_wd_table,
lr_config type ref to cl_salv_wd_config_table.
"data: lr_column_settings type ref to if_salv_wd_column_settings.
"data: lr_column type ref to cl_salv_wd_column.
data: lr_column_header type ref to cl_salv_wd_column_header.
data : lt_column type salv_wd_t_column_ref,
ls_column type salv_wd_s_column_ref.
data: lr_field_amnt type ref to cl_salv_wd_field.
data: lv_aggr_rule type ref to cl_salv_wd_aggr_rule.
data: lr_sort_rule type ref to cl_salv_wd_sort_rule.
lr_field_amnt = lr_field_settings->get_field( 'AMOUNT ').
lr_field_amnt->if_salv_wd_sort~set_group_aggregation_allowed( abap_true ).
lr_field_amnt->if_salv_wd_sort~create_sort_rule( ).
lr_sort_rule = lr_field_amnt->if_salv_wd_sort~get_sort_rule( ).
lr_sort_rule->set_sort_order( if_salv_wd_c_sort=>sort_order_ascending ).
lr_sort_rule->set_group_aggregation( abap_true ).
loop at lt_column into ls_column.
case ls_column-id.
when 'AMOUNT'.
* aggregate field
call method lr_config->if_salv_wd_field_settings~get_field
exporting
fieldname = 'AMOUNT'
receiving
value = lr_field_amnt.
* create aggregate rule as total
lr_field_amnt->if_salv_wd_aggr~create_aggr_rule( ).
lv_aggr_rule = lr_field_amnt->if_salv_wd_aggr~get_aggr_rule( ).
lv_aggr_rule->set_aggregation_type( if_salv_wd_c_aggregation=>aggrtype_total ).
Cheers,
Kris.
hai kris,
Actually i got error in this line as lr_field_settings as unknown
lr_field_amnt = lr_field_settings->get_field( 'AMOUNT ').
I have declared it as
data: lr_field_settings type ref to if_salv_wd_field_settings..
Is that any wrong in it??
I will check in st22 and revert back to u.
Thanks,
Nalla.B
hai Kris,
Am using the following coding from sdn for total calculation in ALV, Am not able to get that total row in my ALV table.
Please Help in getting it.
DATA: lo_cmp_usage TYPE ref to if_wd_component_usage.
DATA: lr_salv_wd_table TYPE REF TO iwci_salv_wd_table.
"DATA: lr_column_settings TYPE REF TO if_salv_wd_column_settings,
"DATA: lr_column TYPE REF TO cl_salv_wd_column.
DATA: lt_column TYPE salv_wd_t_column_ref,
ls_column TYPE salv_wd_s_column_ref.
DATA: lr_function_settings TYPE REF TO CL_SALV_WD_CONFIG_TABLE.
DATA: lr_field_settings TYPE REF TO IF_SALV_WD_FIELD_SETTINGS,
lr_field_curr TYPE REF TO CL_SALV_WD_FIELD,
lr_field_amnt TYPE REF TO CL_SALV_WD_FIELD.
DATA: lv_aggr_rule TYPE REF TO CL_SALV_WD_AGGR_RULE.
DATA: lr_sort_rule TYPE REF TO CL_SALV_WD_SORT_RULE.
*create an instance of ALV component
lo_cmp_usage = wd_this->wd_cpuse_ALV( ).
if not initialized, then initialize
if lo_cmp_usage->has_active_component( ) is initial.
lo_cmp_usage->create_component( ).
endif.
" get ALV component
lr_salv_wd_table = wd_this->wd_cpifc_ALV( ).
lr_function_settings = lr_salv_wd_table->get_model( ).
get reference to column settings
lr_column_settings ?= lr_function_settings.
get all columns
lt_column = lr_column_settings->get_columns( ).
loop at columns
loop at lt_column into ls_column.
CASE ls_column-id. when 'AMOUNT'.
for PRICE aggregate field
CALL METHOD LR_FUNCTION_SETTINGS->IF_SALV_WD_FIELD_SETTINGS~GET_FIELD
EXPORTING
FIELDNAME = 'AMOUNT'
RECEIVING
VALUE = lr_field_amnt.
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.
sub totals based on contract currency.
CALL METHOD lr_field_amnt->IF_SALV_WD_SORT~CREATE_SORT_RULE
EXPORTING
SORT_ORDER = IF_SALV_WD_C_SORT=>SORT_ORDER_ASCENDING
GROUP_AGGREGATION = ABAP_TRUE
RECEIVING VALUE = lr_sort_rule.
*hide others when OTHERS.
ls_column-r_column->set_visible( if_wdl_core=>visibility_none ).
endcase.
endloop.
Thanks in Advance,
Nalla.B
Hi,
Try to use this Configuration ALV code in WDDOINIT for exemple :
DATA: alv_config_table TYPE REF TO cl_salv_wd_config_table,
wd_table_usage TYPE REF TO if_wd_component_usage,
lr_table_settings TYPE REF TO if_salv_wd_table_settings,
wd_table TYPE REF TO iwci_salv_wd_table.
DATA: lr_field TYPE REF TO cl_salv_wd_field.
wd_table_usage = wd_this->wd_cpuse_alv( ).
IF wd_table_usage->has_active_component( ) IS INITIAL.
wd_table_usage->create_component( ).
ENDIF.
" Get ALV component
wd_table = wd_this->wd_cpifc_alv( ). " alv is the name of the using standar componant ALV
alv_config_table = wd_table->get_model( ).
" Set the UI elements.
lr_table_settings ?= alv_config_table.
lr_table_settings->set_read_only( abap_false ).
lr_table_settings->set_data_check( 01 ).
" Sum
lr_field = alv_config_table->if_salv_wd_field_settings~get_field( 'FIELD_NAME' ) . "The column name for which total needs to be done.
lr_field->if_salv_wd_aggr~create_aggr_rule( aggregation_type =
if_salv_wd_c_aggregation=>aggrtype_total ).
Hope this help
Best regards
Jalal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
77 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.