Application Development 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: 

CALL METHOD, get_selected_rows, How to get all the rows that were modifed?

Former Member
0 Kudos

Hello,

I am using an example where materials and creation date are displayed in ALV. The material creation date can be edited. After a date has been changed, I hit the save button to update mara. This works fine when the date is changed AND the changed row is selected. Is there any way to find out all the rows that were modified without selecting the rows that were changed?

Current process - Change date(s), select rows where date was changed, save, update mara

To be process - Change date(s), save, update mara

Thanks.

CALL METHOD ref_grid->get_selected_rows

IMPORTING

et_index_rows = i_selected_rows.

*--- Through the index capturing the values of selected rows

LOOP AT i_selected_rows INTO w_selected_rows.

READ TABLE it_tab INTO wa_it_tab INDEX w_selected_rows-index.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING wa_it_tab TO w_modified.

APPEND w_modified TO i_modified.

ENDIF.

ENDLOOP.

MODIFY mara FROM TABLE i_modified.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi ,

Try with this if it solves your problem

If you are using Objects for your ALV, you need an event receiver and a

method to check if data changed. OO ALV has an event called DATA_CHANGED.

class lcl_event_receiver definition.

public section.

methods: handle_data_changed

for event data_changed of cl_gui_alv_grid

importing er_data_changed.

endclass.

class lcl_event_receiver implementation.

method handle_data_changed.

perform data_changed using er_data_changed.

endmethod.

endclass.

FORM data_changed USING rr_data_changed TYPE REF TO

cl_alv_changed_data_protocol.

DATA: ls_mod_cells TYPE lvc_s_modi.

DATA: ls_cells TYPE lvc_s_modi,

l_rv0 LIKE i_forc_entry-revised_volume0,

LOOP AT rr_data_changed->mt_good_cells INTO ls_mod_cells.

CASE ls_mod_cells-fieldname.

WHEN 'FIELD1'.

          • This Method below returns your new value *****

CALL METHOD rr_data_changed->get_cell_value

EXPORTING i_row_id = ls_mod_cells-row_id

i_fieldname = ls_mod_cells-fieldname

IMPORTING e_value = l_rv0.

.

.

.

.

.

.

ENDCASE.

thanks,

Venkat

12 REPLIES 12

Former Member
0 Kudos

Hi ,

Try with this if it solves your problem

If you are using Objects for your ALV, you need an event receiver and a

method to check if data changed. OO ALV has an event called DATA_CHANGED.

class lcl_event_receiver definition.

public section.

methods: handle_data_changed

for event data_changed of cl_gui_alv_grid

importing er_data_changed.

endclass.

class lcl_event_receiver implementation.

method handle_data_changed.

perform data_changed using er_data_changed.

endmethod.

endclass.

FORM data_changed USING rr_data_changed TYPE REF TO

cl_alv_changed_data_protocol.

DATA: ls_mod_cells TYPE lvc_s_modi.

DATA: ls_cells TYPE lvc_s_modi,

l_rv0 LIKE i_forc_entry-revised_volume0,

LOOP AT rr_data_changed->mt_good_cells INTO ls_mod_cells.

CASE ls_mod_cells-fieldname.

WHEN 'FIELD1'.

          • This Method below returns your new value *****

CALL METHOD rr_data_changed->get_cell_value

EXPORTING i_row_id = ls_mod_cells-row_id

i_fieldname = ls_mod_cells-fieldname

IMPORTING e_value = l_rv0.

.

.

.

.

.

.

ENDCASE.

thanks,

Venkat

Clemenss
Active Contributor
0 Kudos

Hi,

do as venkat suggested.

And do not forget to call the method check_changed_data in PAI so that the event is raised

But you could have already found tons of answers to your question after a little bit search. I.e. see this [wiki|http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=61243570]

Kind regards,

Clemens

Former Member
0 Kudos

Thanks Venkat and Clemens. Unfortunately my issue is not yet resolved. I still have to click on the rows and then SAVE to get the rows that were modified.

I have attached the code. Double click on call screen 100. Create PBO and PAI as follows-

PROCESS BEFORE OUTPUT.

MODULE STATUS_0100.

*

PROCESS AFTER INPUT.

MODULE exit.

Also the containter name on the screen is - CONTAINER

Thanks for your time!

&----


*& Report YKC_ALV_OOPS

*&

&----


*& This prog will help in understanding ALV OOPS

*& EDIT on SAVE

*& Tool bar button addition

&----


REPORT ykc_alv_oops.

TABLES: mara.

DATA: BEGIN OF it_tab OCCURS 0,

matnr LIKE mara-matnr,

ersda LIKE mara-ersda, "creation date

ernam LIKE mara-ernam, "person created

pstat LIKE mara-pstat, "maint stat

lvorm LIKE mara-lvorm, "flg for deletion

mtart LIKE mara-mtart, "mat type

meins LIKE mara-meins, "uom

END OF it_tab.

DATA: wa_it_tab LIKE LINE OF it_tab. "making work area

DATA: i_modified TYPE STANDARD TABLE OF mara,"For getting modified rows

w_modified TYPE mara.

CLASS lcl_events_d0100 DEFINITION DEFERRED.

*class lcl_event_receiver definition deferred.

DATA: event_receiver1 TYPE REF TO lcl_events_d0100,

i_selected_rows TYPE lvc_t_row, "Selected Rows

w_selected_rows TYPE lvc_s_row.

DATA:

o_alv_grid TYPE REF TO cl_gui_alv_grid,

o_alv_cont TYPE REF TO cl_gui_custom_container.

----


  • CLASS lcl_events_d0100 DEFINITION

----


CLASS lcl_events_d0100 DEFINITION.

PUBLIC SECTION.

METHODS

handle_hotspot_click

FOR EVENT hotspot_click OF cl_gui_alv_grid

IMPORTING

e_row_id

e_column_id

es_row_no

sender.

*---code addition for ALV pushbuttons

*--for placing buttons

METHODS handle_toolbar_set

FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING

e_object

e_interactive.

*---user command on clicking a button

METHODS handle_user_command

FOR EVENT user_command OF cl_gui_alv_grid

IMPORTING

e_ucomm.

*---user command for changed data

METHODS: handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.

ENDCLASS. "lcl_events_d0100 DEFINITION

TYPE-POOLS cndp.

DATA ok_code TYPE sy-ucomm.

----


  • FOR VARIANT

----


DATA st_var TYPE disvariant .

DATA save TYPE c.

st_var-report = 'YKC_ALV_OOPS'.

save = 'A'.

----


  • FOR LAYOUT

----


DATA loyo TYPE lvc_s_layo.

loyo-zebra = 'X'.

loyo-detailinit = 'X'.

loyo-info_fname = 'RED'.

----


  • FOR FIELD CATALOG

----


DATA fcat TYPE lvc_t_fcat.

DATA wa_fcat LIKE LINE OF fcat.

*--Declaration for toolbar buttons

DATA : ty_toolbar TYPE stb_button.

DATA : e_object TYPE REF TO cl_alv_event_toolbar_set,

io_alv_toolbar TYPE REF TO cl_alv_event_toolbar_set.

*---custom container

DATA container TYPE REF TO cl_gui_custom_container.

DATA ref_grid TYPE REF TO cl_gui_alv_grid.

CREATE OBJECT container

EXPORTING

container_name = 'CONTAINER'."name of container in module pool

CREATE OBJECT ref_grid

EXPORTING

i_parent = container.

----


  • CLASS lcl_events_d0100 IMPLEMENTATION

----


CLASS lcl_events_d0100 IMPLEMENTATION.

*---method for hotspot

METHOD handle_hotspot_click.

DATA:ls_col_id TYPE lvc_s_col.

READ TABLE it_tab INTO wa_it_tab

INDEX e_row_id-index.

IF sy-subrc = 0.

CHECK ( wa_it_tab-matnr IS NOT INITIAL ).

CASE e_column_id-fieldname.

WHEN 'MATNR'.

LEAVE PROGRAM.

*---put your own logic as per requirement on hotspot click

WHEN OTHERS.

  • do nothing

ENDCASE.

CALL METHOD ref_grid->set_current_cell_via_id

EXPORTING

is_row_id = e_row_id

is_column_id = ls_col_id.

ENDIF.

ENDMETHOD. "handle_hotspot_click

**---method for handling toolbar

METHOD handle_toolbar_set.

CLEAR ty_toolbar.

ty_toolbar-function = 'EDIT'. "name of btn to catch click

ty_toolbar-butn_type = 0.

ty_toolbar-text = 'EDIT'.

APPEND ty_toolbar TO e_object->mt_toolbar.

ENDMETHOD. "handle_toolbar_set

METHOD handle_user_command.

  • DATA: wr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

DATA: lt_rows TYPE lvc_t_row,

lt_index TYPE lvc_s_row-index.

CASE e_ucomm.

WHEN 'EDIT'.

PERFORM save_database.

CALL METHOD ref_grid->refresh_table_display.

ENDCASE.

ENDMETHOD. "handle_user_command

METHOD handle_data_changed.

PERFORM data_changed USING er_data_changed.

ENDMETHOD. "handle_data_changed

ENDCLASS. "lcl_events_d0100 IMPLEMENTATION

  • Reference to the event listener class

DATA: event_receiver TYPE REF TO lcl_events_d0100.

----


  • FORM build_event_listener

----


  • [+] Set the event handler on the ALV Grid

----


FORM build_event_listener.

  • Assigning the event listener to the ALV

CREATE OBJECT event_receiver.

SET HANDLER event_receiver->handle_data_changed FOR o_alv_grid.

SET HANDLER event_receiver->handle_hotspot_click FOR o_alv_grid.

ENDFORM. "build_event_listener

START-OF-SELECTION.

PERFORM get_data.

PERFORM field_catalog.

&----


*& Form get_data

&----


  • text : getting data into internal table

----


FORM get_data .

SELECT matnr ersda ernam pstat lvorm mtart meins

INTO TABLE it_tab

UP TO 10 ROWS

FROM mara.

ENDFORM. " get_data

&----


*& Form field_catalog

&----


  • text :setting field cat

----


FORM field_catalog .

REFRESH fcat.

DATA: lv_pos TYPE i.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'MATNR'.

wa_fcat-coltext = 'Material No'.

wa_fcat-col_pos = lv_pos.

wa_fcat-hotspot = 'X'.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'ERSDA'.

wa_fcat-coltext = 'Creation Date'.

wa_fcat-col_pos = lv_pos.

wa_fcat-edit = 'X'.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'ERNAM'.

wa_fcat-coltext = 'Person Created'.

wa_fcat-col_pos = lv_pos.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'PSTAT'.

wa_fcat-coltext = 'Maint Stat'.

wa_fcat-col_pos = lv_pos.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'LVORM'.

wa_fcat-coltext = 'Flag For Deletion'.

wa_fcat-col_pos = lv_pos.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'MTART'.

wa_fcat-coltext = 'Material Type'.

wa_fcat-col_pos = lv_pos.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

lv_pos = lv_pos + 1.

wa_fcat-fieldname = 'MEINS'.

wa_fcat-coltext = 'UOM'.

wa_fcat-col_pos = lv_pos.

wa_fcat-outputlen = 18.

APPEND wa_fcat TO fcat.

CLEAR wa_fcat.

CREATE OBJECT event_receiver1.

*---setting event handlers

SET HANDLER event_receiver1->handle_toolbar_set FOR ref_grid.

SET HANDLER event_receiver1->handle_user_command FOR ref_grid.

SET HANDLER event_receiver1->handle_hotspot_click FOR ref_grid.

SET HANDLER event_receiver1->handle_data_changed FOR ref_grid.

----


  • ALV GRID DISPLAY

----


CALL METHOD ref_grid->set_table_for_first_display

EXPORTING

is_variant = st_var

i_save = save

is_layout = loyo

CHANGING

it_outtab = it_tab[]

it_fieldcatalog = fcat.

CALL SCREEN 100.

ENDFORM. " field_catalog

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE status_0100 OUTPUT.

  • CREATE OBJECT gr_events_d0100.

*

  • SET HANDLER gr_events_d0100->double_click

*

  • FOR ref_grid.

CALL METHOD ref_grid->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_modified.

SET PF-STATUS 'S100'.

SET TITLEBAR 'XXX'.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module exit INPUT

&----


  • text

----


MODULE exit INPUT.

CASE ok_code.

WHEN 'SAVE'.

PERFORM save_database.

WHEN 'EXIT' .

CLEAR ok_code.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " exit INPUT

&----


*& Form SAVE_DATABASE

&----


  • text : saving into DDIC from internal table

----


  • --> p1 text

  • <-- p2 text

----


FORM save_database .

*--- Getting the selected rows index

CALL METHOD ref_grid->get_selected_rows

IMPORTING

et_index_rows = i_selected_rows.

*--- Through the index capturing the values of selected rows

LOOP AT i_selected_rows INTO w_selected_rows.

READ TABLE it_tab INTO wa_it_tab INDEX w_selected_rows-index.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING wa_it_tab TO w_modified.

APPEND w_modified TO i_modified.

ENDIF.

ENDLOOP.

MODIFY mara FROM TABLE i_modified.

ENDFORM. " SAVE_DATABASE

&----


*& Form DATA_CHANGED

&----


  • text

----


  • -->P_ER_DATA_CHANGED text

----


FORM data_changed USING rr_data_changed TYPE REF TO

cl_alv_changed_data_protocol.

DATA: ls_mod_cells TYPE lvc_s_modi.

DATA: ls_cells TYPE lvc_s_modi.

DATA: lv_value TYPE lvc_value.

LOOP AT rr_data_changed->mt_good_cells INTO ls_mod_cells.

*

CASE ls_mod_cells-fieldname.

WHEN 'FIELD1'.

            • This Method below returns your new value *****

CALL METHOD rr_data_changed->get_cell_value

EXPORTING

i_row_id = ls_mod_cells-row_id

i_fieldname = ls_mod_cells-fieldname

IMPORTING

e_value = lv_value.

*

*.

*.

*.

*.

*.

*.

ENDCASE.

ENDLOOP.

ENDFORM. " DATA_CHANGED

Clemenss
Active Contributor
0 Kudos

Hi Larry,

how can we help you if we can't read the code.

Regards,

Clemens

Former Member
0 Kudos

Please try to post only the relevant sections of the code.

If the post exceeds 2500 characters, then the formatting is disabled.

Shouldn't happen, but...

Cheers,

Julius

Former Member
0 Kudos

Sorry, my bad ... Here is the pertinent sections of the code. I will give it in sections ...

1. Define methods

2. Define implementation

3. Event listener

4. PAI has subroutine - save_database which checks for get_selected_rows

5. subroutine data_changed

The methods - hotspot_click and handle_user_command are working fine. But the data_changed is not recognized, so perform data_changed is not executed.

CLASS lcl_events_d0100 DEFINITION.

PUBLIC SECTION.

METHODS

handle_hotspot_click

METHODS handle_toolbar_set

*---user command on clicking a button

*---user command for changed data

METHODS: handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.

ENDCLASS. "lcl_events_d0100 DEFINITION

2. Implementation of these methods

CLASS lcl_events_d0100 IMPLEMENTATION.

*---method for hotspot

METHOD handle_hotspot_click.

ENDMETHOD. "handle_hotspot_click

**---method for handling toolbar

METHOD handle_toolbar_set.

ENDMETHOD. "handle_toolbar_set

METHOD handle_user_command.

CASE e_ucomm.

WHEN 'EDIT'.

PERFORM save_database.

CALL METHOD ref_grid->refresh_table_display.

ENDCASE.

ENDMETHOD. "handle_user_command

METHOD handle_data_changed.

PERFORM data_changed USING er_data_changed.

ENDMETHOD. "handle_data_changed

ENDCLASS. "lcl_events_d0100 IMPLEMENTATION

Former Member
0 Kudos

3. Build event listener

FORM build_event_listener.

  • Assigning the event listener to the ALV

CREATE OBJECT event_receiver.

SET HANDLER event_receiver->handle_data_changed FOR o_alv_grid.

SET HANDLER event_receiver->handle_hotspot_click FOR o_alv_grid.

ENDFORM. "build_event_listener

CREATE OBJECT event_receiver1.

*---setting event handlers

SET HANDLER event_receiver1->handle_toolbar_set FOR ref_grid.

SET HANDLER event_receiver1->handle_user_command FOR ref_grid.

SET HANDLER event_receiver1->handle_hotspot_click FOR ref_grid.

SET HANDLER event_receiver1->handle_data_changed FOR ref_grid.

4. PAI

MODULE exit INPUT.

CASE ok_code.

WHEN 'SAVE'.

PERFORM save_database.

WHEN 'EXIT' .

CLEAR ok_code.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " exit INPUT

Former Member
0 Kudos

5. save_database

FORM save_database .

*--- Getting the selected rows index

CALL METHOD ref_grid->get_selected_rows

IMPORTING

et_index_rows = i_selected_rows.

*--- Through the index capturing the values of selected rows

LOOP AT i_selected_rows INTO w_selected_rows.

READ TABLE it_tab INTO wa_it_tab INDEX w_selected_rows-index.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING wa_it_tab TO w_modified.

APPEND w_modified TO i_modified.

ENDIF.

ENDLOOP.

MODIFY mara FROM TABLE i_modified.

ENDFORM. " SAVE_DATABASE

6. data_changed

FORM data_changed USING rr_data_changed TYPE REF TO

cl_alv_changed_data_protocol.

DATA: ls_mod_cells TYPE lvc_s_modi.

DATA: ls_cells TYPE lvc_s_modi.

DATA: lv_value TYPE lvc_value.

LOOP AT rr_data_changed->mt_good_cells INTO ls_mod_cells.

CASE ls_mod_cells-fieldname.

WHEN 'FIELD1'.

            • This Method below returns your new value *****

CALL METHOD rr_data_changed->get_cell_value

EXPORTING

i_row_id = ls_mod_cells-row_id

i_fieldname = ls_mod_cells-fieldname

IMPORTING

e_value = lv_value.

ENDCASE.

ENDLOOP.

ENDFORM. " DATA_CHANGED

Former Member
0 Kudos

The code that I have been working with is on WIKI -

http://wiki.sdn.sap.com/wiki/display/ABAP/EditableALVthrough+OOPS

This code gives materials and creation date in an ALV grid. Creation date can be modified. I want to be able to change the dates for several materials, hit the EDIT button and be able to save to mara. RIght now, after modifying the date, I have to highlight the row and then hit EDIT.

Thanks.

Clemenss
Active Contributor
0 Kudos

Hi,

above there is a <_> code button. After selecting the code part of the mesage with the mouse, click it. Then hit the preview tab and check that code looks like formatted code.

The code of the wiki will not help in your case.

But in your data changed handler, right in this portion of code, you can set_selected_cells to highlight them.

CALL METHOD rr_data_changed->get_cell_value
EXPORTING
i_row_id = ls_mod_cells-row_id
i_fieldname = ls_mod_cells-fieldname
IMPORTING
e_value = lv_value.

*§3.Optionally register ENTER to raise event DATA_CHANGED.
    call method gr_alvgrid->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_modified.

called after first_display will always raise the data changed event or PAI when you press ENTER.

Regards,

Clemens

Former Member
0 Kudos

Thanks Clemens. The code is not even getting to the subroutine - data_changed. Let me try some more things ...

Thanks a lot for your help.

Former Member
0 Kudos

Used bcalv_edit_03 as a guide to solve this conundrum.