Skip to Content
0

Editable OOPS ALV Grid - Issue with updated rows

Feb 13 at 04:46 PM

70

avatar image
Former Member

Trying to get into ALV after a long time away...and I have a problem.

I have build an editable ALV that works fine. Fields are output as I want them, as well as the ones that I want being editable. It's basically a custom table that I'll save back to the database when I'm done. My problem is that when I hit the save button - my internal table doesn't pick up the changes that I made to the data and I don't know what to save back to the database. Here's where I build the grid...

*&---------------------------------------------------------------------*
*&      Form  CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM create_and_init_alv CHANGING pt_outtab LIKE gt_outtab[]
                                  pt_fieldcat TYPE lvc_t_fcat
                                  pt_exclude TYPE ui_functions.

  CREATE OBJECT g_custom_container
    EXPORTING
      container_name = g_container.
  CREATE OBJECT g_grid
    EXPORTING
      i_parent = g_custom_container.

* Build fieldcat and set column team
* edit enabled. Assign a handle for the dropdown listbox.
  PERFORM build_fieldcat CHANGING pt_fieldcat.

* Optionally restrict generic functions to 'change only'.
*   (The user shall not be able to add new lines).
  PERFORM exclude_tb_functions CHANGING pt_exclude.

ENDFORM.                               "CREATE_AND_INIT_ALV

And this is where I fill the grid

*&---------------------------------------------------------------------*
*      Form  REFRESH_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_OUTTAB  text
*----------------------------------------------------------------------*
FORM refresh_data  USING    pa_initial LIKE wa_initial
                   CHANGING pt_outtab LIKE gt_outtab[]
                            pt_fieldcat TYPE lvc_t_fcat
                            pt_exclude TYPE ui_functions.


*Get the data from the database table.  Set the base to compare after
  CLEAR pt_outtab.
  SELECT * FROM ztable INTO TABLE pt_outtab.
  IF sy-subrc NE 0.
  ELSE.
    gt_outtab2 = pt_outtab.
  ENDIF.

  IF pa_initial = '1'.
    g_grid->register_edit_event( i_event_id = cl_gui_alv_grid=>mc_evt_enter ).
    CALL METHOD g_grid->set_table_for_first_display
      EXPORTING
        it_toolbar_excluding = pt_exclude
      CHANGING
        it_fieldcatalog      = pt_fieldcat
        it_outtab            = pt_outtab.

* Set editable cells to ready for input initially
    CALL METHOD g_grid->set_ready_for_input
      EXPORTING
        i_ready_for_input = 1.
  ELSE.
    CALL METHOD g_grid->refresh_table_display.
  ENDIF.
ENDFORM.

So I would expect that I would be able to access updated date in the same table that I sent to the ALV - GT_OUTTAB? Unfortunately, getting the old values in the table instead of new values I edit? So the save doesn't doe anything??

 FORM save_total_updates CHANGING pt_outtab LIKE gt_outtab[]
                                pt_outtab2 LIKE gt_outtab[].

  CLEAR gt_modified.

  LOOP AT pt_outtab INTO gs_modified.
  READ TABLE pt_outtab2 WITH KEY resrc = gs_modified-resrc INTO gs_original.
    IF sy-subrc = 0.
      IF gs_modified NE gs_original.
        APPEND gs_modified TO gt_modified.
      ENDIF.
    ENDIF.
  ENDLOOP.

  MODIFY ztable FROM TABLE gt_modified.
  IF sy-subrc = 0.
    MESSAGE 'VALUES SAVED' TYPE 'I'.
  ELSE.
    MESSAGE 'Error Saving Values' TYPE 'I'.
  ENDIF.
ENDFORM.
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Krishna Murthy Feb 14 at 04:13 AM
0

hi

first register two events of alv grid class

those are MC_EVT_ENTER
MC_EVT_MODIFIED

using method REGISTER_EDIT_EVENT

after above you should also handle one more event i.e DATA_CHANGED_FINISHED

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

You put me on the right path here. In addition - called the method CL_GUI_ALV_GRID -> CHECK_CHANGED_DATA . this method does Verification of Changes and Triggers Event DATA_CHANGED.

0
Sandra Rossi Feb 13 at 09:35 PM
1

Use the method G_GRID->CHECK_CHANGED_DATA( )

Share
10 |10000 characters needed characters left characters exceeded