Skip to Content
avatar image
Former Member

ALV Subtotal

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?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Jun 25, 2007 at 04:38 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • avatar image
    Former Member
    Jun 27, 2007 at 06:46 AM

    hi mehmet,

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

    Thanks and regards

    Rahul

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 28, 2007 at 11:27 AM

    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 😉

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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.

  • avatar image
    Former Member
    Jul 12, 2007 at 04:17 PM

    My problem is solved. All answers were very helpful.

    Add comment
    10|10000 characters needed characters exceeded