on 05-31-2011 7:23 AM
hai all,
I want to sum the value of amount in alv table and i have to assign the value ti a text view in my screen.
I have created this code inside a method called create_total.
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 AMOUNT 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.
*hide others when OTHERS.
"ls_column-r_column->set_visible( if_wdl_core=>visibility_none ).
endcase.
endloop.
and I have called this inside wddoinit using'
wd_this->create_total( ).
but am not getting that total row in my alv table.
Pls help me in solving this and how to assign this total value to a field n my screen.
Thanks in advance,
Nalla.B
Hi Nalla
Ple chk this function module.
It will Help u.
I hope.
aggregate field
call method lr_config->if_salv_wd_field_settings~get_field
exporting
fieldname = ' ' " total Value field Name'
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.
Regards
Laxmikanth K
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 have declared ALV component in View properties.
If i didnt give that means I would not get ALV table in my screen rite???
Am getting ALV table with all my fields are editable only that total row alone am not getting.....
Also for ur info am not getting any value from Db table inside my ALV table I am entering all the values in my Alv table.
I want the total to be calculated based on the entered amount value in my Alv table.
I knw knw wr i did some mistake... I may did some small mistake If u hav any idea pls correct me.
Thanks in advance,
Nalla.B
Hi Nalla.
I hope this code will be helpful for u.
data: lr_node_info type ref to if_wd_context_node_info,
lr_node type ref to if_wd_context_node,
wa_value_set type wdr_context_attr_value,
lt_value_set type table of wdr_context_attr_value.
Instantiate the ALV Component
lr_alv_usage = wd_this->wd_cpuse_alv_display1( ).
if lr_alv_usage->has_active_component( ) is initial.
lr_alv_usage->create_component( ).
endif.
Get reference to model
lr_if_controller = wd_this->wd_cpifc_alv_display1( ).
lr_config = lr_if_controller->get_model( ).
To get the dropdowns displayed you need to set the table to editable by using below statement
lr_config->if_salv_wd_table_settings~set_read_only( abap_false ).
Set the UI elements.
lr_column_settings ?= lr_config.
lt_column = lr_column_settings->get_columns( ).
loop at lt_column into ls_column.
case ls_column-id.
when 'WK_DMBTR1'.
aggregate field
call method lr_config->if_salv_wd_field_settings~get_field
exporting
fieldname = ' ' // ur field name.'
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.
Hai laxmikanth,
Ur Solution is very helpful. But its displaying total only if am getting data frm DB table.
But my req is that I want to type all the details in the alv table and the total has to be calculated based on the amount which am going to enter.. I tried ur code but it is going giving total wen am entering data in the ALV table.
Ex: In my alv table I am having the coloumns.
Bill no Bill date City Amount
Based on the amount am going to be entered I want the total to be calculated dynamically in the alv table....
Is it possible or not???
Pls give some suggestion
Thanks in Advance,
Nalla.B
hai Kris,
Am getting the total now I have created a drop down to get that total value. Its working now. But am not ablt to assign that lv_aggr_rule to the attribute of type PAD_AMT7S. I am getting error of type conflict.
As per our pervious discussion lv_aggr_rule will hold the total value rit???
How can i convert it into the req data type.'
Pls give some suggestions....
Thanks in advance,
Nalla.B
Hai Kris,
Am not able to get ur point. Can u pls explain me n detail?
lv_aggr_rule is of below type..
lv_aggr_rule type ref to cl_salv_wd_aggr_rule
Claimed amount is my attribute of type PAD_AMT7S..
I have to set this value lv_aggr_rule to the attribute Claimed amount..
Is it possible???
How can i convet this data type????
Pls help.
Thanks in Advance,
Nalla.B
Hai Kris,
Am not able to get ur point. Can u pls explain me n detail?
lv_aggr_rule is of below type..
lv_aggr_rule type ref to cl_salv_wd_aggr_rule
Claimed amount is my attribute of type PAD_AMT7S..
I have to set this value lv_aggr_rule to the attribute Claimed amount..
Is it possible???
How can i convet this data type????
Pls help.
Thanks in Advance,
Nalla.B
Hi Nalla,
You have another open thread same question. Please close that.
I am getting Total value, I checked your code it is working. Just change field name and use same code.
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 'CUMU_VAL'. // Use your Field name
* for AMOUNT aggregate field
CALL METHOD LR_FUNCTION_SETTINGS->IF_SALV_WD_FIELD_SETTINGS~GET_FIELD
EXPORTING
FIELDNAME = 'CUMU_VAL' // Your Field name
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.
*hide others when OTHERS.
"ls_column-r_column->set_visible( if_wdl_core=>visibility_none ).
endcase.
endloop.
how to assign this total value to a field n my screen.
You want total in seperate area or in ALV itself, By default you get total in ALV automatically.
If you want to display in some other place
Store total in one local variable and pass this to another which you want to display in view using set_attribute.
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 have tried with ur code am not able to get the total value.
I have tried this coding both inside wddoint and by using a method call in wddoint using
wd_this->create_total().
I have made all the fields of the alv table as editable and using that insert and append row i will insert row but am bot able to see that yellow row for total.
I dnt knw where i have gone wrong can u pls correct me???
Thanks in advance.
Nalla.B
hai srinivas,
Am passing the name of the attribute in the context as 'AMOUNT'.
Still am not getting the total value. I dnt knw wr i had gone wrong.
This is one of the suggestions which i got reg this
Remember one thing though u follow all these steps keep in mind the value in the internal table which u want as total should be of type 'I'. or else it wil not sum the values. It happend the same with me as well before. Please check,
If u hav any idea or suggestion pls tell me.
Thanks in Advance,
Nalla.B
hai srinivas,
I am getting amount from my db table of type PAD_AMT7S. ( currency )
My db table field name, my context attribute name everything is AMOUNT only still am not getting it.
I have declared the amount of type PAD_AMT7S. is anythng wrong in ti should it be int or wat???
If u hav any idea pls help.
Thanks in Advance,
Nalla.B
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.