cancel
Showing results for 
Search instead for 
Did you mean: 

Totaal in alv table

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

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

Former Member
0 Kudos

Hai Laxmikanth,

Can u pls tell me the type of this variable lr_config..

How can i declare this can u pls tell me. Then i can be able to check with ur function module.

Now am getting lr_config is unknown error.

Thanks In Advance,

Nalla.B

former_member199125
Active Contributor
0 Kudos

lr_config is similar to lr_function_settings in your program.

and And did you declare ALV component as used component in VIEW properties?

Thanks and Regards

Srinivas

Former Member
0 Kudos

Hai Laxmikanth,

I tried with ur FM and lr_config of type DATA: lr_config type ref to cl_salv_wd_config_table.

I am getting Null object error.

Its not working.

Former Member
0 Kudos

Hi Nalla,

This is also same code as above, lr_config is of type CL_SALV_WD_CONFIG_TABLE

lr_config TYPE REF TO CL_SALV_WD_CONFIG_TABLE.

Cheers,

Kris.

Former Member
0 Kudos

Hai Laxmikanth,

I tried with ur FM and lr_config of type DATA: lr_config type ref to cl_salv_wd_config_table.

I am getting Null object error.

Its not working.

former_member199125
Active Contributor
0 Kudos

kissnas,

I think we have mention alv component as used component in view properties for any alv functionality . Am i correct?

I think nalla didn't do that thing

Regards

Srinivas

Former Member
0 Kudos

Hi Sana and Nalla,

Yes we have to use in veiw properties.

Nalla please check once in your view properties,

Check in view properties you have two inputs one for alv component another for INTERFACECONTROLLER.

cheers,

Kris.

Former Member
0 Kudos

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

0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Nalla,

Try like this, create one button say total, first get read all data entered in alv table after that use your code to claculate total, which is i posted in previous.

Cheers,

Kris.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Nalla,

You declar attribute of same type what you are using in ALV table.

Cheers,

Kris.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

former_member199125
Active Contributor
0 Kudos

Nalla,

Assign the lv_aggr_rule value to claimed amount attribute using set_Attribute( export name = att name value = lv_Aggr_rule )

Regards

SRrinivas

Former Member
0 Kudos

Hai Srinivas,

I did ur suggestion early am getting error as

lv_aggr_rule ca not be converted. I have given claimed amount of type PAD_AMT7S.

TYPE CONFLICT BETWEEN THESE TWO VALUES.

I hav opened a new thread for this issue. Pls Give some suggestion.

Thanks in Advance,

Nalla.B

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Nalla,

Code is perfectly working. May be somewhere you did some mistake.

Cheers,

Kris.

Former Member
0 Kudos

hai kris,

Do i need any context attribute for total in main view. I didnt specified anything rite nw... Is it needed.

Pls correct me if am wrong,

Thanks in Advance,

Nalla.B

Former Member
0 Kudos

Hi

No you dont required any attribute.

Cheers,

Kris.

former_member199125
Active Contributor
0 Kudos

hi nalla,

Are you sure you pass the correct field name in "get filed" method ?

Once you get the total in lv_aggr_rul, set this value to required filed in your view, so that same total value will display in that text view.

Regards

Srinivas

Regards

Srinivas

Former Member
0 Kudos

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

former_member199125
Active Contributor
0 Kudos

nalla,

the suggestion means, the amount field should be type of numeric...

And AMOUNT is field name or attribute name? or is column header?

Regards

Srinivas

Former Member
0 Kudos

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

former_member199125
Active Contributor
0 Kudos

And AMOUNT field column heading name?

Regards

Srinvias

Former Member
0 Kudos

Hai Srinivas,

My Context attribute name is AMOUNT

DB table field name is AMOUNT

Table Header name is AMOUNT.

Then alos am not getiing it.. Is thr ant idea whr i have gone wrong???

Pls help,

Thanks in Advance,

Nalla.B

former_member199125
Active Contributor
0 Kudos

Hi nalla,

code seems fine.

And did you declare ALV component as used component in VIEW properties?

Regards

Srinivas