ALV data_changed 已删除行

ALV data_changed with deleted rows

我想访问我的 ALV OOPS 实例中已删除行的单元格值。

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.

lv-fipex 始终为空白。为什么 get_cell_value 不适用于已删除的行?我可以为此使用什么?

此方法似乎 return 数据仅当您修改特定单元格或一行单元格时。为了实现您想要的内容,直接从内部 table 读取用作方法 SET_TABLE_FOR_FIRST_DISPLAY 调用中的 CHANGING 参数。实际删除发生在事件 DATA_CHANGED 之后,因此您可以这样做,因为要删除的数据仍在内部 table.

看这个例子(你必须自己创建屏幕和状态100)。

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.