<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Updating database table using ALV Grid class CL_ALV_CHANGED_DATA_PROTOCOL in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/updating-database-table-using-alv-grid-class-cl-alv-changed-data-protocol/m-p/4959344#M1156189</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi Ruby,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes we can use that *data reference variable *.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is a variable( something comparable to a pointer ) that points to a int table( table with changed contents ) &lt;/P&gt;&lt;P&gt;which ll be created at run-time based on the data type ot the internal table that we pass to the parameter &lt;STRONG&gt;it_outtab&lt;/STRONG&gt; of method &lt;STRONG&gt;set_table_for_first_display&lt;/STRONG&gt; ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;assign &lt;EM&gt;er_data_changed-&amp;gt;mp_mod_rows-&amp;gt;*&lt;/EM&gt; to a field-symbol and use it...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check the below code for example -&amp;gt; method &lt;STRONG&gt;refresh_changed_data&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;screen flow logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;PROCESS BEFORE OUTPUT.
  MODULE pbo.

PROCESS AFTER INPUT.
  MODULE pai.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;main program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*----------------------------------------------------------------------*
*       CLASS lcl_event_responder DEFINITION                           *
*----------------------------------------------------------------------*
CLASS lcl_event_responder DEFINITION.
  PUBLIC SECTION.
    DATA  : ls_changed_cell TYPE  lvc_s_modi,
            lv_language     TYPE  spras..
    METHODS refresh_changed_data  FOR EVENT data_changed
                                  OF cl_gui_alv_grid
                                  IMPORTING er_data_changed
                                            e_ucomm.

ENDCLASS.                    "event_responder DEFINITION

TYPES tt_makt TYPE STANDARD TABLE OF makt.

DATA: go_handler         TYPE REF TO lcl_event_responder,
      go_grid            TYPE REF TO cl_gui_alv_grid,
      gt_fieldcat        TYPE lvc_t_fcat,
      gv_language        TYPE spras VALUE 'E',
      gt_outtab          TYPE tt_makt,
      gs_tableline       TYPE LINE OF tt_makt.


FIELD-SYMBOLS : &amp;lt;changed_rows&amp;gt; TYPE tt_makt.

CALL SCREEN 100.

*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.
  SET PF-STATUS 'BASIC'.
  PERFORM create_and_init_alv CHANGING gt_outtab[]
                                       gt_fieldcat.
ENDMODULE.                    "pbo OUTPUT
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE pai INPUT.
  LEAVE PROGRAM.
ENDMODULE.                    "pai INPUT



*&amp;amp;---------------------------------------------------------------------*
FORM create_and_init_alv CHANGING pt_outtab LIKE gt_outtab[]
                                  pt_fieldcat TYPE lvc_t_fcat.

  CHECK go_grid IS NOT BOUND.

  CREATE OBJECT go_grid
    EXPORTING
      i_parent = cl_gui_container=&amp;gt;default_screen.

  PERFORM build_display_table.

  PERFORM build_fieldcat CHANGING pt_fieldcat.

  go_grid-&amp;gt;set_table_for_first_display( CHANGING  it_fieldcatalog      = pt_fieldcat
                                                  it_outtab            = pt_outtab ).

  go_grid-&amp;gt;set_ready_for_input( 1 ).

* raises the 'data_changed' event when we select another cell/any action after changing the data
  go_grid-&amp;gt;register_edit_event( EXPORTING i_event_id = cl_gui_alv_grid=&amp;gt;mc_evt_enter ).

  CREATE OBJECT go_handler.

  SET HANDLER go_handler-&amp;gt;refresh_changed_data FOR go_grid.

ENDFORM.                               "CREATE_AND_INIT_ALV
*&amp;amp;---------------------------------------------------------------------*
FORM build_display_table.
  FREE gt_outtab.
  SELECT * FROM makt UP TO 20 ROWS INTO TABLE gt_outtab WHERE spras EQ gv_language.
ENDFORM.                               "build_display_table
*&amp;amp;---------------------------------------------------------------------*
FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.

  DATA ls_fcat TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name = 'MAKT'
    CHANGING
      ct_fieldcat      = pt_fieldcat.

  LOOP AT pt_fieldcat INTO ls_fcat.
    ls_fcat-edit       = abap_true.
    MODIFY pt_fieldcat FROM ls_fcat.
  ENDLOOP.
ENDFORM.                               "build_fieldcat

*---------------------------------------------------------------------*
*       CLASS event_responder IMPLEMENTATION                          *
*---------------------------------------------------------------------*
CLASS lcl_event_responder IMPLEMENTATION.
  METHOD refresh_changed_data.

    ASSIGN er_data_changed-&amp;gt;mp_mod_rows-&amp;gt;* TO &amp;lt;changed_rows&amp;gt;.

    LOOP AT &amp;lt;changed_rows&amp;gt; INTO gs_tableline.
      BREAK-POINT.
    ENDLOOP.

  ENDMETHOD.                    "click
ENDCLASS.                    "event_responder IMPLEMENTATION&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Jose.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Dec 2008 11:42:00 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-12-15T11:42:00Z</dc:date>
    <item>
      <title>Updating database table using ALV Grid class CL_ALV_CHANGED_DATA_PROTOCOL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/updating-database-table-using-alv-grid-class-cl-alv-changed-data-protocol/m-p/4959343#M1156188</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to use class CL_ALV_CHANGED_DATA_PROTOCOL to update a database table from an ALV grid.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have used program BCALV_EDIT_04 as an example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am able to successfully processed inserted or deleted lines using the attributes &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MT_DELETED_ROWS&lt;/P&gt;&lt;P&gt;MT_INSERTED_ROWS&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but I also want to process modified lines.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was just wondering whether anyone out there has some example code for this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can see that there are the following attributes available &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MT_MOD_CELLS&lt;/P&gt;&lt;P&gt;MP_MOD_ROWS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would ideally like to use MP_MOD_ROWS rather than  MT_MOD_CELLS but it is not clear to me what type MP_MOD_ROWS is.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If anyone has any example code for this sort of thing, please let me know.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Ruby&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Dec 2008 09:36:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/updating-database-table-using-alv-grid-class-cl-alv-changed-data-protocol/m-p/4959343#M1156188</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-15T09:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: Updating database table using ALV Grid class CL_ALV_CHANGED_DATA_PROTOCOL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/updating-database-table-using-alv-grid-class-cl-alv-changed-data-protocol/m-p/4959344#M1156189</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi Ruby,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes we can use that *data reference variable *.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is a variable( something comparable to a pointer ) that points to a int table( table with changed contents ) &lt;/P&gt;&lt;P&gt;which ll be created at run-time based on the data type ot the internal table that we pass to the parameter &lt;STRONG&gt;it_outtab&lt;/STRONG&gt; of method &lt;STRONG&gt;set_table_for_first_display&lt;/STRONG&gt; ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;assign &lt;EM&gt;er_data_changed-&amp;gt;mp_mod_rows-&amp;gt;*&lt;/EM&gt; to a field-symbol and use it...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check the below code for example -&amp;gt; method &lt;STRONG&gt;refresh_changed_data&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;screen flow logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;PROCESS BEFORE OUTPUT.
  MODULE pbo.

PROCESS AFTER INPUT.
  MODULE pai.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;main program.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;*----------------------------------------------------------------------*
*       CLASS lcl_event_responder DEFINITION                           *
*----------------------------------------------------------------------*
CLASS lcl_event_responder DEFINITION.
  PUBLIC SECTION.
    DATA  : ls_changed_cell TYPE  lvc_s_modi,
            lv_language     TYPE  spras..
    METHODS refresh_changed_data  FOR EVENT data_changed
                                  OF cl_gui_alv_grid
                                  IMPORTING er_data_changed
                                            e_ucomm.

ENDCLASS.                    "event_responder DEFINITION

TYPES tt_makt TYPE STANDARD TABLE OF makt.

DATA: go_handler         TYPE REF TO lcl_event_responder,
      go_grid            TYPE REF TO cl_gui_alv_grid,
      gt_fieldcat        TYPE lvc_t_fcat,
      gv_language        TYPE spras VALUE 'E',
      gt_outtab          TYPE tt_makt,
      gs_tableline       TYPE LINE OF tt_makt.


FIELD-SYMBOLS : &amp;lt;changed_rows&amp;gt; TYPE tt_makt.

CALL SCREEN 100.

*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.
  SET PF-STATUS 'BASIC'.
  PERFORM create_and_init_alv CHANGING gt_outtab[]
                                       gt_fieldcat.
ENDMODULE.                    "pbo OUTPUT
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE pai INPUT.
  LEAVE PROGRAM.
ENDMODULE.                    "pai INPUT



*&amp;amp;---------------------------------------------------------------------*
FORM create_and_init_alv CHANGING pt_outtab LIKE gt_outtab[]
                                  pt_fieldcat TYPE lvc_t_fcat.

  CHECK go_grid IS NOT BOUND.

  CREATE OBJECT go_grid
    EXPORTING
      i_parent = cl_gui_container=&amp;gt;default_screen.

  PERFORM build_display_table.

  PERFORM build_fieldcat CHANGING pt_fieldcat.

  go_grid-&amp;gt;set_table_for_first_display( CHANGING  it_fieldcatalog      = pt_fieldcat
                                                  it_outtab            = pt_outtab ).

  go_grid-&amp;gt;set_ready_for_input( 1 ).

* raises the 'data_changed' event when we select another cell/any action after changing the data
  go_grid-&amp;gt;register_edit_event( EXPORTING i_event_id = cl_gui_alv_grid=&amp;gt;mc_evt_enter ).

  CREATE OBJECT go_handler.

  SET HANDLER go_handler-&amp;gt;refresh_changed_data FOR go_grid.

ENDFORM.                               "CREATE_AND_INIT_ALV
*&amp;amp;---------------------------------------------------------------------*
FORM build_display_table.
  FREE gt_outtab.
  SELECT * FROM makt UP TO 20 ROWS INTO TABLE gt_outtab WHERE spras EQ gv_language.
ENDFORM.                               "build_display_table
*&amp;amp;---------------------------------------------------------------------*
FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.

  DATA ls_fcat TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name = 'MAKT'
    CHANGING
      ct_fieldcat      = pt_fieldcat.

  LOOP AT pt_fieldcat INTO ls_fcat.
    ls_fcat-edit       = abap_true.
    MODIFY pt_fieldcat FROM ls_fcat.
  ENDLOOP.
ENDFORM.                               "build_fieldcat

*---------------------------------------------------------------------*
*       CLASS event_responder IMPLEMENTATION                          *
*---------------------------------------------------------------------*
CLASS lcl_event_responder IMPLEMENTATION.
  METHOD refresh_changed_data.

    ASSIGN er_data_changed-&amp;gt;mp_mod_rows-&amp;gt;* TO &amp;lt;changed_rows&amp;gt;.

    LOOP AT &amp;lt;changed_rows&amp;gt; INTO gs_tableline.
      BREAK-POINT.
    ENDLOOP.

  ENDMETHOD.                    "click
ENDCLASS.                    "event_responder IMPLEMENTATION&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Jose.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Dec 2008 11:42:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/updating-database-table-using-alv-grid-class-cl-alv-changed-data-protocol/m-p/4959344#M1156189</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-15T11:42:00Z</dc:date>
    </item>
    <item>
      <title>Re: Updating database table using ALV Grid class CL_ALV_CHANGED_DATA_PROTOCOL</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/updating-database-table-using-alv-grid-class-cl-alv-changed-data-protocol/m-p/4959345#M1156190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use MP_MOD_ROWS with care . Because this will give all the line which are modified in the sequence and it may happen you get the duplicate records in this.Say i have entered 2 lines, first i edit 1st and then 2nd . After that if i edit the first one , then this table will consists for 3 records  which may lead to inconsistencies in the data. So it is better to use as per the sample program from SAP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps you&lt;/P&gt;&lt;P&gt;Raj&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Dec 2008 16:00:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/updating-database-table-using-alv-grid-class-cl-alv-changed-data-protocol/m-p/4959345#M1156190</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-12-15T16:00:09Z</dc:date>
    </item>
  </channel>
</rss>

