cancel
Showing results for 
Search instead for 
Did you mean: 

ALV Subtotal

Former Member
0 Kudos

Hi,

I have a ALV table and I want to sum some fileds data as a subtotal. I have seen some examples on the forum but I don't understand how I can use it . Can anybody explain any further details?

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

My problem is solved. All answers were very helpful.

Former Member
0 Kudos

Hi Raul,

I have had an error on the CALL METHOD wd_this->alv_config_fields->get_fields RECEIVING value = lt_field.When I look AT THE error message from st22 transaction , it said that, Access via 'NULL' object reference not possible. I think, method hasn't reached to ALV. Maybe I used your method in a wrong place but I have only WDDOINIT(initial method). I didn't configur my ALV. I have only ALV table element and Context. I binded Context to ALV table.There is no ALV configuration in my application. What can I do? Please, I need more help

Former Member
0 Kudos

Hi,

Have you declared and initialized your ALV model? Assuming your ALV model is l_alv_model, you can directly access the config fields as l_alv_model->IF_SALV_WD_FIELD_SETTINGS. Hope this solves your problem.

Regards,

Nithya

Madhu2004
Active Contributor
0 Kudos

hai,

i have the code below and i could get the result as sub total for each billing document in this example.Write this code hwere u are instantiating the ALV(prefarably wddoint).

To get the l_value:

go to code wizard and first instantiate the used component and then call the methos in used componenet i.e call the method get_model( ).

after that you write the code below.

...Set Aggregation and Group Aggregation Values

DATA:

lr_field_settings TYPE REF TO if_salv_wd_field_settings.

lr_field_settings ?= l_value.

lr_field_settings->set_group_aggr_displayed( abap_true ).

*...Sort Field Billing Document

DATA:

lr_field TYPE REF TO cl_salv_wd_field,

lr_sort_rule TYPE REF TO cl_salv_wd_sort_rule,

lr_aggr_rule TYPE REF TO cl_salv_wd_aggr_rule.

lr_field_settings ?= l_value.

lr_field = lr_field_settings->get_field( 'BILL_DOC' ).

lr_field->if_salv_wd_sort~set_group_aggregation_allowed( abap_true ).

lr_field->if_salv_wd_sort~create_sort_rule( ).

lr_sort_rule = lr_field->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 ).

*...Aggregate Field Amount

lr_field = lr_field_settings->get_field( 'AMOUNT_OUTPUT' ).

lr_field->if_salv_wd_aggr~create_aggr_rule( ).

lr_aggr_rule = lr_field->if_salv_wd_aggr~get_aggr_rule( ).

lr_aggr_rule->set_aggregation_type( if_salv_wd_c_aggregation=>aggrtype_total ).

Cheers,

Madhu

Former Member
0 Kudos

hi mehmet,

here is my alv configuration ...this includes get_model...

DATA lo_cmp_usage TYPE REF TO if_wd_component_usage.

lo_cmp_usage = wd_this->wd_cpuse_alv( ).

IF lo_cmp_usage->has_active_component( ) IS INITIAL.

lo_cmp_usage->create_component( ).

ENDIF.

DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .

lo_interfacecontroller = wd_this->wd_cpifc_alv( ).

  • DATA lo_value TYPE REF TO cl_salv_wd_config_table.

wd_this->alv_config_table = lo_interfacecontroller->get_model(

).

lr_table_settings ?= wd_this->alv_config_table.

Former Member
0 Kudos

Hi

Your answer is working but I still have two problems.

Problem 1)For example,When I aggregated AMOUNT_OUTPUT column, everyyhing is nice.However, When I changed aggregate column in the code, application still aggregate according to old column.

Problem 2) I want to aggregate several columns at the same time.For example, first column is AMOUNT_OUTPUT, second column is unit_Output, third column is total_output. I want to get subtotal all these columns.

Former Member
0 Kudos

hi mehmet,

if your problem is solved please award 10 points and close the thread.

Thanks and regards

Rahul

Former Member
0 Kudos

Hi,

For displaying subtotals first you need to sort the table based on some field and then just enable the aggregation for the column you want .Check out this sample code:

      • Sorting

wd_this->alv_config_fields ?= wd_this->alv_config_table.

DATA: lt_field TYPE salv_wd_t_field_ref.

DATA: ls_field like LINE OF lt_field.

data : lr_sort_rule TYPE REF TO CL_SALV_WD_SORT_RULE.

data : lr_aggr_rule TYPE REF TO CL_SALV_WD_AGGR_RULE.

CALL METHOD wd_this->alv_config_fields->get_fields

RECEIVING

value = lt_field.

READ TABLE lt_field into ls_field with key fieldname = 'SEMESTER'.

CALL METHOD ls_field-r_field->if_salv_wd_sort~create_sort_rule

exporting

GROUP_AGGREGATION = abap_true

RECEIVING

VALUE = lr_sort_rule

.

clear ls_field.

LOOP AT lt_field into ls_field.

CASE ls_field-fieldname.

WHEN 'AVG' OR '' OR 'MARKS'.

CALL METHOD ls_field-r_field->if_salv_wd_aggr~create_aggr_rule

RECEIVING

VALUE = lr_aggr_rule

.

WHEN OTHERS.

ENDCASE.

ENDLOOP.

In the above example i am sorting the alv based on semester and then displaying the total for MARKS or AVERAGE...these are nothing but columns for which you want to have aggregation(subtotal) displayed..

Please award points if answer was helpful.

Former Member
0 Kudos

Hi Rahul,

I have implemented your code to my application and unfortunately it's not work.Probably, reason of this problem is caused by me because I didn't understand some points.So, I have two question to you.

Q1)Should I use this code in the initail metod or sort method.

Q2)I have an error message that is "alv_config_fields is unkown".What should I do for define alv_config_field ?

Former Member
0 Kudos

Hi Mehmut,

Answer to Q1:

I have used in the method where i configure my ALV.If you are doing this in init method then do it there.

Or if your requirement is to diplay when you sort it then use it in the sort method.

Answer to Q2:

alv_config_fields is of type IF_SALV_WD_FIELD_SETTINGS.Just declare it in your method and it should work fine.

Please inform whether it worked for you or you still facing problems

Former Member
0 Kudos

Hi Rahul,

I am new web dynpro for ABAP and your explanation doesn't clear for me.You have been using alv_config_field in the wd_this->alv_config_fields but wd_this is an attribute and I don't know how I can define alv_config_fields in the wd_this ? When I define as "data: alv_config_fields TYPE REF TO IF_SALV_WD_FIELD_SETTINGS" in the code, I can't call it from wd_this attribute. I still have an error message that is "alv_config_fields is unkown".Please, how I can implment your code.If you can give me more details I will be very happy.

Former Member
0 Kudos

hi mehmut,

i got it.You have starting trouble

To get rid of the error just delete wd_this when you use alv_config_fields...

this is because you have defined alv_config_fields as data in your method and not an attribute in the view.

However if you want to use it the way i have then go to your view.There click on the "Attributes" tab.Create the alv_config_fields attribute there with the Associated type as IF_SALV_WD_FIELD_SETTINGS.

let me know if you still have doubts