Read ALV changes after user input?

谁都会走 提交于 2020-12-08 02:22:47

问题


I've got a report which outputs the data of my internal table via an ALV grid. The output itself consists of some information and two check boxes for each row. The user can check these boxes if necessary and now I need to read the table back in order to know what boxes were checked. The corresponding rows will be processed differently afterwards depending on which of the two boxes got checked.

I already tried the method get_actual_view, which I don't know how to use correct and the method get_selected_rows, which seems to get the index of the row selected by the user, but not its contents.

How can I read the table back after the user checked the boxes (and press a button to continue, which would trigger the coding in the report to read the data, process it and write it back into the grid)?


回答1:


You need to call the method CHECK_CHANGED_DATA of CL_GUI_ALV_GRID to transfer the inputs from the ALV grid to the internal table (it works for all kinds of input fields in the ALV, i.e. not limited to checkboxes).

Minimal example (add a break-point before/after CHECK_CHANGED_DATA, run the program, edit some data, for instance the smoker checkbox, and see how the input is reflected into the internal table; NB: if the demo table SBOOK is empty, run the program SAPBC_DATA_GENERATOR) - it compiles with ABAP 7.40 and + :

REPORT.
DATA go_alv TYPE REF TO cl_gui_alv_grid.
DATA gt_sbook TYPE TABLE OF sbook.

PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  DATA: lt_fcat TYPE lvc_t_fcat,
        ls_fcat TYPE lvc_s_fcat.
  IF go_alv IS NOT BOUND.
    CREATE OBJECT go_alv
      EXPORTING
        i_parent = cl_gui_container=>screen0.
    SELECT * FROM sbook UP TO 100 ROWS INTO TABLE gt_sbook.
    lt_fcat = CORRESPONDING #( CAST cl_abap_structdescr(
          cl_abap_structdescr=>describe_by_name( 'SBOOK' ) )->get_ddic_field_list( ) ).
    ls_fcat-checkbox = abap_true.
    MODIFY lt_fcat FROM ls_fcat TRANSPORTING checkbox WHERE fieldname = 'SMOKER'.
    go_alv->set_table_for_first_display(
        EXPORTING
          is_layout        = VALUE #( edit = 'X' )
        CHANGING
          it_fieldcatalog  = lt_fcat
          it_outtab        = gt_sbook ).
  ENDIF.

AT SELECTION-SCREEN ON EXIT-COMMAND.
  go_alv->check_changed_data( ). " <=== transfer screen data to GT_SBOOK
  go_alv->free( ).



回答2:


The best method is to display output in ALV by using CL_GUI_ALV_GRID.

For change in ALV grid,

You have to register event DATA_CHANGED and will help you write your code in case of data change.

For Selected rows, You have to create checkbox field in the itab, will help you drive selected rows.

If you want to transfer screen changes to itab then you have to call method check_changed_data for transferring changes from screen to itab at PAI event.

For some scenarios, if you want to know any change in row contents then you have to create one more field data_change character type having length 1. You can flag this field in appropriate event if there is change in contents of itab.

regards,

Umar Abdullah



来源:https://stackoverflow.com/questions/54763326/read-alv-changes-after-user-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!