cancel
Showing results for 
Search instead for 
Did you mean: 

Row selection is not retrieved on ALV Grid

Former Member

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Can you provide your code here. So that we can see where you went wrong.

Are you using the FM to display ALV Grid.

Thanks.

Former Member
0 Kudos

I'm doin the HARD WAY => OO Dev

look at this: Something the method return <b>NOTHING</b>

<b>ONF4</b>

METHOD onf4 .

  DATA :
          lw_err LIKE LINE OF ati_errors,
** work area of the table of the errorS
          l_stat TYPE zzmdistat,
** status chosen by the end user!
          l_err like lw_err-error,
** error for new erropr
          li_tmp LIKE ati_errors.
** temp table for the errors.

** get the current line!
  READ TABLE ati_errors INTO lw_err INDEX es_row_no-row_id.


  CASE e_fieldname.
    WHEN 'STATUSTXT'.
** say to sap event has been handled!
      er_event_data->m_event_handled = 'X'.

** we found the index
      l_stat = lw_err-status.
      CHECK sy-subrc EQ 0.
** call the function module for the status
      CALL FUNCTION 'ZF_F4_STATUS'
        EXPORTING
          im_role             = at_role
          im_gen              = 'X'
        IMPORTING
          ex_stat             = l_stat
        EXCEPTIONS
          ex_action_cancelled = 1
          OTHERS              = 2.
** function was sucessfull and status is different!
      CHECK sy-subrc EQ 0 AND l_stat NE lw_err-status.
** update status text in table so the end user will see it!!!
      MOVE l_stat TO lw_err-status.
      APPEND lw_err TO li_tmp.
      CALL FUNCTION 'ZF_SET_STATUS_TEXT'
        TABLES
          chi_zvmdi15       = li_tmp
*   IMI_STATUS        =
                .
      READ TABLE li_tmp INTO lw_err INDEX 1.
      MODIFY ati_errors FROM lw_err INDEX es_row_no-row_id.

** reshresh the table of the alv
      CALL METHOD ato_grid->refresh_table_display
        EXCEPTIONS
          finished = 1
          OTHERS   = 2.

    WHEN 'ERRORTXT'.
** say to sap event has been handled!
      er_event_data->m_event_handled = 'X'.

      CALL FUNCTION 'ZF_F4_ERROR'
        IMPORTING
          ex_err              = l_err
        EXCEPTIONS
          ex_action_cancelled = 1
          OTHERS              = 2.
      break sidskai.
** function was sucessfull and error have to be updated!!
      CHECK sy-subrc EQ 0 AND at_role = atc_role_lever.
      lw_err-error = l_err .
      APPEND lw_err TO li_tmp.
** set text of the error!
      CALL FUNCTION 'ZF_SET_ERROR_TEXT'
        TABLES
*   IMI_ERROR         =
          chi_zvmdi15       = li_tmp
                .

      READ TABLE li_tmp INTO lw_err INDEX 1.
      MODIFY ati_errors FROM lw_err INDEX es_row_no-row_id.
** reshresh the table of the alv
      CALL METHOD ato_grid->refresh_table_display
        EXCEPTIONS
          finished = 1
          OTHERS   = 2.

  ENDCASE.

ENDMETHOD.

<b>USER_COMMAND</b>

METHOD user_command .

  DATA : l_answer .
** will store the answer for

  DATA : lw_header TYPE zsvmdi15key.
** used for the History!

  DATA : li_errors TYPE zttmdi_wfreport.
** internal table for the error!


  DATA : li_15 TYPE STANDARD TABLE OF zvmdi15.
** internal table for the Mass creation
  DATA : lw_15 LIKE LINE OF li_15.
** record of table 15

  DATA :
         l_stat TYPE zzmdistat,
** status chosen by user :)
         li_rows TYPE lvc_t_row ,
** table of selected rows!
         lw_row LIKE LINE OF li_rows,
** work area of the row!
         li_tmp TYPE zttmdi_wfreport,
** temporary table
         lw_tmp LIKE LINE OF li_tmp,
** work area of li_tmp
         lw_error LIKE LINE OF ati_errors.
** work area of the errors.


  CASE e_ucomm.
    WHEN 'SAVE'.
      CALL FUNCTION 'ZF_GET_DIFF'
        TABLES
          imi_old   = ati_errors_bck
          imi_new   = ati_errors
          exi_modif = li_errors.

      CALL FUNCTION 'ZF_SAVE'
        TABLES
          chi_tab = li_errors.

      IF li_errors[] IS INITIAL.
        ati_errors_bck[] = ati_errors[].
      ENDIF.

    WHEN 'BACK'.
      CALL FUNCTION 'ZF_GET_DIFF'
        TABLES
          imi_old   = ati_errors_bck
          imi_new   = ati_errors
          exi_modif = li_errors.
      IF NOT li_errors[] IS INITIAL.
        CALL FUNCTION 'C14A_POPUP_SAVE_WITH_CANCEL'
          IMPORTING
            e_answer = l_answer.
        CASE l_answer.
          WHEN 'J'.
            CALL FUNCTION 'ZF_SAVE'
              TABLES
                chi_tab = li_errors.
        ENDCASE.
      ENDIF.
      CHECK l_answer NE 'A'.
      LEAVE TO SCREEN 0.

    WHEN 'MASS_CH'.
** get selected rows!
*If none message the user!
      CALL METHOD ato_grid->get_selected_rows
        IMPORTING
          et_index_rows = li_rows.
** no rows have been selected.
      IF li_rows[] IS INITIAL.
        MESSAGE e398(00) WITH 'No Rows selected : Action cancelled !'.
      ELSE.
** f4 for the status!
        CALL FUNCTION 'ZF_F4_STATUS'
          EXPORTING
            im_role             = at_role
            im_gen              = 'X'
          IMPORTING
            ex_stat             = l_stat
          EXCEPTIONS
            ex_action_cancelled = 1
            OTHERS              = 2.
        IF l_stat NE space.
** get all rows!
          LOOP AT li_rows INTO lw_row.
            READ TABLE ati_errors INTO lw_error INDEX lw_row-index.
            MOVE l_stat TO lw_error-status.
            APPEND lw_error TO li_tmp.
          ENDLOOP.
** replace the status in the old table
          CALL FUNCTION 'ZF_SET_STATUS_TEXT'
            TABLES
              chi_zvmdi15 = li_tmp.
** set the new exception
          CALL FUNCTION 'ZF_SET_EXCPT_COLOR'
            EXPORTING
              im_role     = at_role
            TABLES
              chi_zvmdi15 = li_tmp.

** replace old value of ati_errors from li_tmp.
          LOOP AT li_rows INTO lw_row.
            READ TABLE li_tmp INTO lw_tmp INDEX sy-tabix.
            MODIFY ati_errors
               FROM lw_tmp
               INDEX lw_row-index
               TRANSPORTING status statustxt exception
               .
          ENDLOOP.
** reshresh the table of the alv
          CALL METHOD ato_grid->refresh_table_display
            EXCEPTIONS
              finished = 1
              OTHERS   = 2.
        ENDIF.
      ENDIF.
    WHEN 'DUPLICATE'.
** get selected rows!
*If none message the user!
      CALL METHOD ato_grid->get_selected_rows
        IMPORTING
          et_index_rows = li_rows.

      DESCRIBE TABLE li_rows.
      IF sy-tfill = 1.
        READ TABLE li_rows INTO lw_row INDEX 1.
        READ TABLE ati_errors INTO lw_error INDEX lw_row-index.
        MOVE-CORRESPONDING lw_error TO lw_15.
        CALL FUNCTION 'ZF_CREATE_ERROR'
          EXPORTING
            im_role               = at_role
            imw_record            = lw_15
            im_simulate           = 'X'
          IMPORTING
            exw_zvmdi15           = lw_15
          EXCEPTIONS
            ex_creation_cancelled = 1
            empty_field           = 2
            no_auto_log           = 3
            existing_error        = 4
            OTHERS                = 5.

        CASE sy-subrc .
          WHEN 0.
            MOVE-CORRESPONDING lw_15 TO lw_error.
            APPEND lw_error TO li_errors.
            PERFORM fill_in_txt IN PROGRAM zvl_mdi_errorwf_plant
                        USING
                            at_role
                        CHANGING
                           li_errors.
            APPEND LINES OF li_errors TO ati_errors.
** reshresh the table of the alv
            CALL METHOD ato_grid->refresh_table_display
              EXCEPTIONS
                finished = 1
                OTHERS   = 2.
          WHEN 4.
            MESSAGE s398(00) WITH 'Existing error :'
                                  ' Use change status !'.
        ENDCASE.
      ELSE.
        MESSAGE s398(00) WITH 'Only one row can be duplicated :'
                              ' Action cancelled !'.
      ENDIF.

    WHEN 'CREATE'.
      CALL FUNCTION 'ZF_CREATE_ERROR'
        EXPORTING
          im_role               = at_role
          im_simulate           = 'X'
        IMPORTING
          exw_zvmdi15           = lw_15
        EXCEPTIONS
          ex_creation_cancelled = 1
          empty_field           = 2
          no_auto_log           = 3
          existing_error        = 4
          OTHERS                = 5.

      CASE sy-subrc .
        WHEN 0.
          MOVE-CORRESPONDING lw_15 TO lw_error.
          APPEND lw_error TO li_errors.
          PERFORM fill_in_txt IN PROGRAM zvl_mdi_errorwf_plant
                      USING
                          at_role
                      CHANGING
                         li_errors.
          APPEND LINES OF li_errors TO ati_errors.
** reshresh the table of the alv
          CALL METHOD ato_grid->refresh_table_display
            EXCEPTIONS
              finished = 1
              OTHERS   = 2.
        WHEN 4.
          MESSAGE s398(00) WITH 'Existing error :'
                                ' Use change status !'.
      ENDCASE.
** Mass Create!
    WHEN 'MCREATE'.
      CALL FUNCTION 'ZF_MASS_CREATE_ERROR'
        EXPORTING
          im_role               = at_role
          im_simulate           = 'X'
        TABLES
          exi_zvmdi15           = li_15
        EXCEPTIONS
          ex_creation_cancelled = 1
          empty_field           = 2
          no_auto_log           = 3
          existing_error        = 4
          OTHERS                = 5.
      LOOP AT li_15 INTO lw_15.
        MOVE-CORRESPONDING lw_15 TO lw_error.
        APPEND lw_error TO li_errors.
      ENDLOOP.
      CHECK sy-subrc EQ 0.
      PERFORM fill_in_txt IN PROGRAM zvl_mdi_errorwf_plant
                  USING
                      at_role
                  CHANGING
                     li_errors.
      APPEND LINES OF li_errors TO ati_errors.
** reshresh the table of the alv
      CALL METHOD ato_grid->refresh_table_display
        EXCEPTIONS
          finished = 1
          OTHERS   = 2.
    WHEN 'HISTORY'.
** get selected rows!
*If none message the user!
      CALL METHOD ato_grid->get_selected_rows
        IMPORTING
          et_index_rows = li_rows.

** no line selected -> Get cusor line!
      IF li_rows[] IS INITIAL.
        CALL METHOD ato_grid->get_current_cell
          IMPORTING
            es_row_id = lw_row.

        IF sy-subrc EQ 0 AND NOT lw_row IS INITIAL.
** and read the error for this line!
          APPEND lw_row TO li_rows.
        ENDIF.
      ENDIF.
      DESCRIBE TABLE li_rows.
      IF sy-tfill = 1.
** get the id of the selected row
        READ TABLE li_rows INTO lw_row INDEX 1.
** and read the error for this line!
        READ TABLE ati_errors INTO lw_error INDEX lw_row-index.
** fill in the header and show the popup!
        MOVE-CORRESPONDING lw_error TO lw_header.
        CALL FUNCTION 'ZF_POPUP_HISTORY'
          EXPORTING
            imw_error              = lw_header
*   IM_START_COL           = 25
*   IM_START_ROW           = 6
         EXCEPTIONS
           exc_not_existing       = 1
           exc_no_history         = 2
           OTHERS                 = 3
                  .
      ELSE.
        MESSAGE s398(00) WITH 'Only one row of History :'
                              ' Action cancelled !'.
      ENDIF.



  ENDCASE.

  CALL METHOD cl_gui_cfw=>flush
    EXCEPTIONS
      cntl_system_error = 1
      cntl_error        = 2
      OTHERS            = 3.


ENDMETHOD.

hymavathi_oruganti
Active Contributor
0 Kudos

1. y r u calling flush???

2. if u select a row and then if u press f4, there u r refreshing table display, so it may be the reason for not catching.

the problem may with refreshing and flushing in wrong places.

check it once

Former Member
0 Kudos

do you think I should remove it or place it in the top of the method ?

hymavathi_oruganti
Active Contributor
0 Kudos

i think u can remove that flush.

refresh, u check not to interrupt get_selected_rows.