Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to update sum in editable alv column at a single click or with enter button?

former_member308418
Participant
0 Kudos
2,859

Dear All,

I am working with Classical ALV in which i have an editable column of amount field. The problem is when i am changing the value of field the change makes no change is the sum. I tried with sdn help but the value changes at double click. What i need, is to change the sum with pressing the enter key.

Please help me in this regard.

With best regards.

9 REPLIES 9

asim_isik
Active Participant
0 Kudos
839

do you have to use enter ? what about you make sum when you just fill your data without enter ?

class lcl_event_receiver definition.

  public section.

    methods:

* Handle Data Changed

    handle_data_changed

    for event data_changed of cl_gui_alv_grid

    importing er_data_changed.

endclass.                    "lcl_event DEFINITION


class lcl_event_receiver implementation.

  method handle_data_changed.

    data: ls_good type lvc_s_modi.

    data: ls_stable type lvc_s_stbl.

    ls_stable-row = 'X'.

    ls_stable-col = ''.

    loop at er_data_changed->mt_good_cells into ls_good.

      case ls_good-fieldname.

        when 'AMOUNT'.

          read table gt_obj into gs_obj index ls_good-row_id.

          if sy-subrc eq 0.

            "make your calculation here

            modify gt_obj index ls_good-row_id

              from gs_obj transporting amount.

          endif.

     endcase.

      call method g_alvgrid->refresh_table_display

        exporting

          is_stable      = ls_stable

          i_soft_refresh = 'X'.

    endloop.

  endmethod.                    "handle_data_changed

endclass.


0 Kudos
839

Deactivate the I_SOFT_REFRESH (set to space) else

This parameter is used only in exceptional cases. If you set this parameter, any totals created, any sort order defined and any filters set for the data displayed remain unchanged when the grid control is refreshed. This makes sense, for example, if you have not modified the data of the data table and want to refresh the grid control only with regard to layout or field catalog changes.


Regards,

Raymond

0 Kudos
839

Dear Asim,

Thanks a lot for your reply. But i am using classical ALV and not familiar with OOP..

Best regards.

asim_isik
Active Participant
0 Kudos
839

did u try to set enter in pf status ?

make this ENTER and catch sy-ucomm in pai

0 Kudos
839

Hello Sir,

I am trying to learn OOP ALV. And tried this portion of coding to do sum with ENTER key. But still it not sums when i change any value and press enter. It sums up if we press REFRESH button in Application bar. But i dont want to press REFRESH button. I want that update in sum with pressing ENTER key in keyboard. Please help me.

Note I am using fieldcat-do_sum for summing up a column value.

Former Member
0 Kudos
839

Hi,

in the routine user_command, check if any value is changed or entered, if the condition comes true add all the rows in the group and modify the total cell.

Please find the link below :

ALV Standard Sum Total Or Subtotal - ABAP Development - SCN Wiki

below code might be helpful:

CONSTANTS : c_formname_subtotal_text TYPE slis_formname VALUE

'SUBTOTAL_TEXT'.

DATA: l_s_event TYPE slis_alv_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type     = 4

IMPORTING

et_events       = i_event

EXCEPTIONS

list_type_wrong = 0

OTHERS          = 0.

* Subtotal

READ TABLE i_event  INTO l_s_event

WITH KEY name = slis_ev_subtotal_text.

IF sy-subrc = 0.

MOVE c_formname_subtotal_text TO l_s_event-form.

MODIFY i_event FROM l_s_event INDEX sy-tabix.

ENDIF.

Thanks & Regards,

Akshay Ruia

0 Kudos
839

Thanks Akshay. I tried this one also but there is no change in the sum. Another requirement is that, sum will change after pressing ENTER button in the keyboard, i, e each time i change a value and press ENTER button, the sum will change. But as per i know ENTER button has no default sy-ucomm. It triggers PAI event when we press ENTER in keyboard. So, need to write my code for ENTER in PAI module. But i am not using any screen here, its a simple ALV. Plz tell me how to do that.

With best regards.

0 Kudos
839

Hi,

Can you post your complete code.

W'l test let you know.

Thanks & Regards,

Akshay Ruia

0 Kudos
839

The code snippet is given below.



FORM get_event.

   CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
     EXPORTING
       i_list_type     = 0
     IMPORTING
       et_events       = it_events
     EXCEPTIONS
       list_type_wrong = 1
       OTHERS          = 2.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.

   CLEAR lt_event.

   READ TABLE it_events WITH KEY name = slis_ev_user_command INTO lt_event.

   IF sy-subrc = 0.

     MOVE 'USER_COMMAND' TO lt_event-form.

     MODIFY it_events INDEX sy-tabix FROM lt_event.

   ENDIF.

ENDFORM.     



Thanks & regards.