3

I want to get the value of the select cells in ALV, I tried get_selected_cells method, but the value field is INITIAL.

What's wrong in this method?

FORM delete_livraison .
  DATA: lt_cells  TYPE lvc_t_cell,
        ls_cells  TYPE lvc_s_cell,
        lv_probl  TYPE xfeld.

  gr_alvpl->get_selected_cells(  IMPORTING et_cell = lt_cells ).

  LOOP AT lt_cells INTO ls_cells.
    IF ls_cells-col_id+0(3) NE 'DAY'.
*      lv_probl = 'X'.
    ENDIF.
    IF ls_cells-value IS INITIAL.
      lv_probl  = 'X'.
    ENDIF.
  ENDLOOP.

  IF lv_probl EQ 'X'.
    MESSAGE s029 DISPLAY LIKE 'E'.
  ENDIF.
ENDFORM.

Thanks.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
shmoolki
  • 1,551
  • 8
  • 34
  • 57

2 Answers2

1

get_select_cells is the wrong method for your task, it returns only index user selected in a row, not the value selected.

To get selected values use get_selected_cells( ) and/or get_selected_rows( ) and together with data internal table:

CALL METHOD mo_grid->get_selected_cells
  IMPORTING
    et_cell = lt_cells.

CALL METHOD mo_grid->get_selected_rows
  IMPORTING
    et_row_no = lt_rows.

IF lt_rows IS INITIAL.
  IF lt_cells[] IS INITIAL.
    EXIT.
  ENDIF.

  READ TABLE lt_cells INTO ls_cell INDEX 1.
  IF sy-subrc = 0.
    ls_row-row_id = ls_cell-row_id-index.
    APPEND ls_row TO lt_rows.
  ENDIF.
ENDIF.
    
 LOOP AT lt_rows INTO ls_row.
  READ TABLE <lt_lines> ASSIGNING <ls_line> INDEX ls_row-row_id.
  IF sy-subrc = 0.
    APPEND <ls_line> TO et_lines.
  ENDIF.
ENDLOOP.
Suncatcher
  • 10,355
  • 10
  • 52
  • 90
0

Try calling CL_GUI_CFW=>FLUSH( ). after GET_SELECTED_CELLS, but before evaluating the results. For the technical background, I'd recommend this document - a must-read for control programming.

Also be aware that GET_SELECTED_CELLS will return the position of the selected cells, not the content.

vwegert
  • 18,371
  • 3
  • 37
  • 55