cancel
Showing results for 
Search instead for 
Did you mean: 

Total for an editable column (ALV)

danilo_cardoso
Participant
0 Kudos

Hi experts!

I developed an WD ALV and I need to display totals for a column.

The problem is, this column is editable, the user could to put some values in some rows of the table and when he press ENTER Key, all values ​​entered should be added and displayed in Total.

How can to do this?

Thx in advance.

Danilo

Accepted Solutions (0)

Answers (1)

Answers (1)

Aisurya
Participant
0 Kudos

Hi Dear ,

When u press the Enter key after the calculation for that column , u have to refresh or reload the all the contents of the ALV to context for that ALV where it is binded.

Check the below code :


data:
  lr_comp_alv    type ref to if_wd_component_usage,
  lr_comp_if_alv type ref to iwci_salv_wd_table,
  lr_config      type ref to cl_salv_wd_config_table.

  data: lr_column_settings type ref to if_salv_wd_column_settings,
        lr_column          type ref to cl_salv_wd_column,
        lr_column_header   type ref to cl_salv_wd_column_header.

  data : lt_column type salv_wd_t_column_ref,
         ls_column type salv_wd_s_column_ref.

  data:  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.
  data  fs_flight      like line of ls_sflight.   


*... ALV Component Usage
  lr_comp_alv = wd_this->wd_cpuse_alv_test( ).

  if lr_comp_alv->has_active_component( ) is initial.
    lr_comp_alv->create_component( ).
  endif.

  lr_comp_if_alv = wd_this->wd_cpifc_alv_test( ).

*... Configure ALV
  lr_config = lr_comp_if_alv->get_model( ).


 call method lr_config->if_salv_wd_table_settings~set_selection_mode
    exporting
      value = cl_wd_table=>e_selection_mode-multi_no_lead.

  lt_column = lr_column_settings->get_columns( ).   
loop at lt_column into ls_column.

    case ls_column-id.   
      when 'PRICE'.  " this is the column id where u want the total
* aggregate field
        call method lr_config->if_salv_wd_field_settings~get_field
          exporting
            fieldname = 'PRICE' "  this is the column name
          receiving
            value     = lr_field_amnt.

* create aggregate rule as total (if u need subtotal also...)

        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.

endmethod.   

Regards

Aisurya puhan

Edited by: Aisurya Puhan on Jun 29, 2011 8:06 PM

danilo_cardoso
Participant
0 Kudos

Hi!

When th ENTER key is pressed two methods are triggered: WDBEFOREACTION and WDAFTERACTION.

What I needed to do was call the context of my alv again and do the BIND_TABLE again.

Anyway, thank you very much for your answer.

Regards.

Danilo

Aisurya
Participant
0 Kudos

Hello Dear ,

WDAFTERACTION is right one...

Regards

Aisurya