Search code examples
abapalv

ALV data_changed with deleted rows


I want to access cell value in my ALV OOPS instance for a deleted row.

LOOP AT er_data_changed->mt_deleted_rows INTO ls_del.
  CALL METHOD er_data_changed->get_cell_value
    EXPORTING
      i_row_id    = ls_del-row_id
      i_fieldname = 'FIPEX'
    IMPORTING
      e_value     = lv-fipex.
ENDLOOP.

but lv-fipex is always blank. Why get_cell_value doesn't work with deleted rows? What can I use for this?


Solution

  • This method seems to return data only if you modify a particular cell or cells of a row. In order to achieve what you want read directly from the internal table used as CHANGING parameter in the call of method SET_TABLE_FOR_FIRST_DISPLAY. The actual deletion occurs after the event DATA_CHANGED so you can do that as the data to be deleted are still in the internal table.

    Look at this example (you have to create the screen and status 100 by yourself).

    REPORT ZZZ.
    
    CLASS lcl_main DEFINITION FINAL CREATE PRIVATE.
      PUBLIC SECTION.
        CLASS-METHODS:
          main,
          on_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
            IMPORTING
              er_data_changed,
          on_double_click FOR EVENT double_click OF cl_gui_alv_grid
            IMPORTING
              es_row_no.
      PRIVATE SECTION.
        CLASS-DATA:
          st_t000 TYPE STANDARD TABLE OF t000 WITH EMPTY KEY.
    ENDCLASS.
    
    MODULE status_0100 OUTPUT.
      SET PF-STATUS '100'.
      lcl_main=>main( ).
    ENDMODULE.
    
    MODULE user_command_0100 INPUT.
      IF sy-ucomm = 'BACK'.
        LEAVE TO SCREEN 0.
      ENDIF.
    ENDMODULE.
    
    CLASS lcl_main IMPLEMENTATION.
      METHOD on_double_click.
        ASSERT 1 = 1.
      ENDMETHOD.
    
      METHOD on_data_changed.
        DATA: l_value TYPE t000-ort01.
        LOOP AT er_data_changed->mt_deleted_rows ASSIGNING FIELD-SYMBOL(<fs_deleted_row>).
    *      er_data_changed->get_cell_value(
    *        EXPORTING
    *          i_row_id = <fs_deleted_row>-row_id
    *          i_fieldname = 'ORT01'
    *        IMPORTING
    *          e_value = l_value
    *      ).
          l_value = st_t000[ <fs_deleted_row>-row_id ]-ort01.
        ENDLOOP.
      ENDMETHOD.
    
      METHOD main.
        DATA(lo_gui_container) = NEW cl_gui_custom_container( container_name = 'CONTAINER' ).
        DATA(lo_gui_alv_grid) = NEW cl_gui_alv_grid( i_parent = lo_gui_container ).
    
        SELECT * FROM t000 INTO TABLE st_t000 UP TO 20 ROWS.
    
        lo_gui_alv_grid->set_ready_for_input( 1 ).
    
        SET HANDLER on_data_changed FOR lo_gui_alv_grid.
        SET HANDLER on_double_click FOR lo_gui_alv_grid.
    
        lo_gui_alv_grid->set_table_for_first_display(
          EXPORTING
            i_structure_name = 'T000'
          CHANGING
            it_outtab = st_t000
          EXCEPTIONS
            invalid_parameter_combination = 1
            program_error = 2
            too_many_lines = 3
            OTHERS = 99
        ).
        ASSERT sy-subrc = 0.
      ENDMETHOD.
    ENDCLASS.
    
    START-OF-SELECTION.
      CALL SCREEN 100.