0
votes

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)?

2
Did you display your ALV with the class CL_GUI_ALV_GRID? If yes, did you define a column with one character + the flag CHECKBOX = 'X' in the field catalog? If yes, did you call the method CHECK_CHANGED_DATA so that to transfer the inputs from the ALV grid to the internal table?Sandra Rossi
@SandraRossi Why does the check_changed_data method exactly what I thought the get_actual_view method would do? So that kind of is the solution now I guess.Suimon
The checkboxes are like any input fields. CHECK_CHANGED_DATA is required to get all the ALV inputs back to the internal table used.Sandra Rossi
Similar to this questionfutu

2 Answers

1
votes

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( ).
-1
votes

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