cancel
Showing results for 
Search instead for 
Did you mean: 

Arithmetic Operation in ALV

Former Member
0 Kudos

Hi Friends ,

I need to make all the arithmetic operation in ALV TABLE like sum , subtraction ,deletion etc..

How can i do this one ,

Can any one help to solve this problem

Thanks & Regards

Sankar.M

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Can you be more specifc.

Summation is possible - Refer this

Regards,

Lekha.

Answers (1)

Answers (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Please describe more what you need to do. If you want to perform arithmetic operations, you can always do this on the source data while still in an ABAP internal table before binding to the context. Otherswise the ALV had the built-in functions to allow columnar Total, Minimum, Maximum, and Mean Value calculation via the Calculation Tab in the Settings dialog. Use the following ALV settings to activate this option in the settings:

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 ,

I need to calculate the sum , and subtract the values and add two values like that .

I don't know how can i perform these steps

can you tell me the proper steps for this problem

Thanks

Sankar.M

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> Hi thomas ,

>

>

> I need to calculate the sum , and subtract the values and add two values like that .

>

> I don't know how can i perform these steps

>

> can you tell me the proper steps for this problem

>

>

> Thanks

>

> Sankar.M

As already described, you can add a columnar sum option via the code given and then activate the option per column in the layout settings dialog.

For other calculations, you should perform these in ABAP code on the internal table data before data binding to the context. Are you asking how you perform arithmetic operations in ABAP? Arthmetic operators are keywords in the language. For instance i fyou want to subtract two columns and store the values in a third for all records in an internal table, you would do something like this:

field-symbols: <Wa_itab> like line of itab.
loop at itab assigning <wa_itab>.
   <wa_itab>-col3 = <wa_itab>-col1 - <wa_itab>-col2.
endloop.

Former Member
0 Kudos

Hi thomas

I used the following code what you given in the init method,

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 ).

but it displays the error

mthod wd_cpuse_alv( ). is unknown or protected or private

what should i do ?

Thanks & Regards

Sankar.M

Former Member
0 Kudos

Hi,

First add the ALV in your properties tab of that view as component usage. then you will not get that error.

Click on properties tab and click on CREATE and include the ALV in that.

Regards,

Lekha.

Former Member
0 Kudos

Hi lekha ,

I did this thing perfectly , but this case the calculation button is inside of the setting ,

that means after clicking the setting button only we get that total sum all the things .

can we get that calculation button directly instead of clicking the setting button to get calculation ?

Thanks

Sankar.M

Former Member
0 Kudos

Hi,

I did not get your doubt.

When you check the link i have provided, you can see the Total for those columns.

For ex: if you change some data and want the SUM for that column. Refer the above link.

But to get the total, you need to hit 'ENTER' key or any event so that SUMMATION is shown for that column.

Regards

Lekha

Former Member
0 Kudos

hi thanks for your reply,

i am not asking that one ,

when i run application , in that page there are two two buttons on ALV TABLE ,

1. filter

2. setting

after clicking the setting button then only i get that calculation button then i do all operation .

Instead of this one can i get that calculation button in the alv in front ? instead of clicking the setting button .....

now got it ?

Thanks

Sankar.M

Former Member
0 Kudos

Hi,

I think there is no option for that.

You have design custom button and have to handle those calcuations by urself.

Regards,

Lekha.

Former Member
0 Kudos

Hi lekha

ok thanks for your reply , could you tell me the proper steps for making that total,min,max by coding ?

becoze im very new to WDA.

Thanks

Sankar.M