<?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 Update Database from editable ALV in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-database-from-editable-alv/m-p/397642#M10020</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm working on a program based on the Model View Controller pattern.&lt;/P&gt;&lt;P&gt;The model selects data from a database table into an internal table and this table is later displayed in an ALV grid by the view.&lt;/P&gt;&lt;P&gt;This is all working fine.&lt;/P&gt;&lt;P&gt;Now I made two columns editable with a field catalog. Now I enabled the "save"-button on the PF-STATUS to save the changes made in the ALV into the database table.&lt;/P&gt;&lt;P&gt;The code isn't working and I just can't find out why.&lt;/P&gt;&lt;P&gt;So this is my method to react on user command (it's a controller-method):&lt;/P&gt;&lt;P&gt; METHOD react_to_user_command.&lt;BR /&gt;
&lt;BR /&gt;    CASE iv_ok_code.&lt;BR /&gt;        WHEN 'BACK'.&lt;BR /&gt;            LEAVE TO SCREEN 0.&lt;BR /&gt;        WHEN 'EXIT'.&lt;BR /&gt;            LEAVE PROGRAM.&lt;BR /&gt;        WHEN 'SAVE'.&lt;BR /&gt;
&lt;BR /&gt;            DATA gt_curto_pds_chg_new TYPE gtab_curto_pds_chg.&lt;BR /&gt;
&lt;BR /&gt;            gt_curto_pds_chg_new = go_controller-&amp;gt;go_view-&amp;gt;get_data( ).&lt;BR /&gt;            go_controller-&amp;gt;go_model-&amp;gt;update_data(&lt;/P&gt;&lt;P&gt;                                         it_curto_pds_chg_new = gt_curto_pds_chg_new ).&lt;BR /&gt;
&lt;BR /&gt;    ENDCASE.&lt;BR /&gt;
 ENDMETHOD.&lt;/P&gt;&lt;P&gt;This is the get_data( )-method:&lt;/P&gt;&lt;P&gt;METHOD get_data.&lt;BR /&gt;    go_alv-&amp;gt;check_changed_data( ).&lt;BR /&gt;    rt_curto_pds_chg = gt_curto_pds_chg.&lt;BR /&gt;
ENDMETHOD.&lt;/P&gt;&lt;P&gt;And this is my update_data( )-method:&lt;/P&gt;&lt;P&gt;METHOD update_data.&lt;/P&gt;&lt;P&gt;    DATA: ls_curto_pds_chg_new TYPE curto_pds_chg,&lt;BR /&gt;               ls_curto_pds_chg TYPE curto_pds_chg.&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;    LOOP AT it_curto_pds_chg_new INTO ls_curto_pds_chg_new.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;        READ TABLE gt_curto_pds_chg&lt;/P&gt;&lt;P&gt;            INTO ls_curto_pds_chg&lt;/P&gt;&lt;P&gt;            WITH KEY ch_id = ls_curto_pds_chg_new-ch_id.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;        IF ls_curto_pds_chg_new &amp;lt;&amp;gt; ls_curto_pds_chg.&lt;BR /&gt;            UPDATE curto_pds_chg FROM ls_curto_pds_chg_new.&lt;BR /&gt;        ENDIF.&lt;BR /&gt;
&lt;BR /&gt;    ENDLOOP.&lt;BR /&gt;
&lt;BR /&gt;
 ENDMETHOD.&lt;/P&gt;&lt;P&gt;Before I implemented the whole update thing I just wrote the WHEN 'SAVE' statement and let it call the method display( ) again just to test if it would show the new or the old table in the ALV. It showed the new table so I thought I could go on and implement the whole thing.&lt;/P&gt;&lt;P&gt;Debugging it now I can see that the table I get from Get_data( ) is already a not updated one and I just don't know why since the table is a changing parameter when building the ALV. I give you my code for the display( )-method as well.&lt;/P&gt;&lt;P&gt;METHOD display.&lt;BR /&gt;
&lt;BR /&gt;    DATA: lt_fieldcat_fm TYPE slis_t_fieldcat_alv, "field catalog table for FM&lt;BR /&gt;               ls_fieldcat_fm TYPE slis_fieldcat_alv, "field catalog structure for loop&lt;BR /&gt;               lt_fieldcat_cl TYPE lvc_t_fcat, "field catalog table for alv method&lt;BR /&gt;               ls_fieldcat_cl TYPE lvc_s_fcat. "field catalog structure for loop&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
* builds a field catalog based on the structure of curto_pds_chg&lt;BR /&gt;    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'&lt;BR /&gt;        EXPORTING&lt;BR /&gt;            i_structure_name = 'CURTO_PDS_CHG'&lt;BR /&gt;        CHANGING&lt;BR /&gt;            ct_fieldcat = lt_fieldcat_fm&lt;BR /&gt;        EXCEPTIONS&lt;BR /&gt;            inconsistent_interface = 1&lt;BR /&gt;            program_error = 2&lt;BR /&gt;            OTHERS = 3.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
* loops the field catalog given from the function module into one&lt;BR /&gt;
* with a structure the alv display method accepts&lt;BR /&gt;    LOOP AT lt_fieldcat_fm INTO ls_fieldcat_fm.&lt;BR /&gt;        MOVE-CORRESPONDING ls_fieldcat_fm TO ls_fieldcat_cl.&lt;BR /&gt;        APPEND ls_fieldcat_cl TO lt_fieldcat_cl.&lt;BR /&gt;    ENDLOOP.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
* makes two columns editable (CHANGE &amp;amp; PROCESS)&lt;BR /&gt;    DATA: ls_fieldcat TYPE REF TO lvc_s_fcat.&lt;BR /&gt;    READ TABLE lt_fieldcat_cl&lt;BR /&gt;        WITH KEY fieldname = 'CHANGE' REFERENCE INTO ls_fieldcat.&lt;BR /&gt;    ls_fieldcat-&amp;gt;edit = 'X'.&lt;BR /&gt;    READ TABLE lt_fieldcat_cl&lt;BR /&gt;        WITH KEY fieldname = 'PROCESS' REFERENCE INTO ls_fieldcat.&lt;BR /&gt;    ls_fieldcat-&amp;gt;edit = 'X'.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
* builds alv grid&lt;BR /&gt;    IF go_container IS INITIAL.&lt;BR /&gt;
&lt;BR /&gt;    CREATE OBJECT go_container&lt;BR /&gt;    EXPORTING&lt;BR /&gt;        container_name = 'CONTAINER'.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;    CREATE OBJECT go_alv&lt;BR /&gt;    EXPORTING&lt;BR /&gt;        i_parent = go_container.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;    CALL METHOD go_alv-&amp;gt;set_table_for_first_display&lt;BR /&gt;        EXPORTING&lt;BR /&gt;            i_structure_name = 'CURTO_PDS_CHG'&lt;BR /&gt;        CHANGING&lt;BR /&gt;            it_outtab = gt_curto_pds_chg&lt;BR /&gt;            it_fieldcatalog = lt_fieldcat_cl.&lt;BR /&gt;        ELSE.&lt;BR /&gt;            go_alv-&amp;gt;refresh_table_display( ).&lt;BR /&gt;        ENDIF.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
 ENDMETHOD.&lt;/P&gt;&lt;P&gt;Can anybody spot the mistake why my database table is not updating?&lt;/P&gt;</description>
    <pubDate>Wed, 15 Feb 2017 13:02:49 GMT</pubDate>
    <dc:creator>d067595</dc:creator>
    <dc:date>2017-02-15T13:02:49Z</dc:date>
    <item>
      <title>Update Database from editable ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-database-from-editable-alv/m-p/397642#M10020</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm working on a program based on the Model View Controller pattern.&lt;/P&gt;&lt;P&gt;The model selects data from a database table into an internal table and this table is later displayed in an ALV grid by the view.&lt;/P&gt;&lt;P&gt;This is all working fine.&lt;/P&gt;&lt;P&gt;Now I made two columns editable with a field catalog. Now I enabled the "save"-button on the PF-STATUS to save the changes made in the ALV into the database table.&lt;/P&gt;&lt;P&gt;The code isn't working and I just can't find out why.&lt;/P&gt;&lt;P&gt;So this is my method to react on user command (it's a controller-method):&lt;/P&gt;&lt;P&gt; METHOD react_to_user_command.&lt;BR /&gt;
&lt;BR /&gt;    CASE iv_ok_code.&lt;BR /&gt;        WHEN 'BACK'.&lt;BR /&gt;            LEAVE TO SCREEN 0.&lt;BR /&gt;        WHEN 'EXIT'.&lt;BR /&gt;            LEAVE PROGRAM.&lt;BR /&gt;        WHEN 'SAVE'.&lt;BR /&gt;
&lt;BR /&gt;            DATA gt_curto_pds_chg_new TYPE gtab_curto_pds_chg.&lt;BR /&gt;
&lt;BR /&gt;            gt_curto_pds_chg_new = go_controller-&amp;gt;go_view-&amp;gt;get_data( ).&lt;BR /&gt;            go_controller-&amp;gt;go_model-&amp;gt;update_data(&lt;/P&gt;&lt;P&gt;                                         it_curto_pds_chg_new = gt_curto_pds_chg_new ).&lt;BR /&gt;
&lt;BR /&gt;    ENDCASE.&lt;BR /&gt;
 ENDMETHOD.&lt;/P&gt;&lt;P&gt;This is the get_data( )-method:&lt;/P&gt;&lt;P&gt;METHOD get_data.&lt;BR /&gt;    go_alv-&amp;gt;check_changed_data( ).&lt;BR /&gt;    rt_curto_pds_chg = gt_curto_pds_chg.&lt;BR /&gt;
ENDMETHOD.&lt;/P&gt;&lt;P&gt;And this is my update_data( )-method:&lt;/P&gt;&lt;P&gt;METHOD update_data.&lt;/P&gt;&lt;P&gt;    DATA: ls_curto_pds_chg_new TYPE curto_pds_chg,&lt;BR /&gt;               ls_curto_pds_chg TYPE curto_pds_chg.&lt;BR /&gt;
&lt;BR /&gt;&lt;BR /&gt;    LOOP AT it_curto_pds_chg_new INTO ls_curto_pds_chg_new.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;        READ TABLE gt_curto_pds_chg&lt;/P&gt;&lt;P&gt;            INTO ls_curto_pds_chg&lt;/P&gt;&lt;P&gt;            WITH KEY ch_id = ls_curto_pds_chg_new-ch_id.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;        IF ls_curto_pds_chg_new &amp;lt;&amp;gt; ls_curto_pds_chg.&lt;BR /&gt;            UPDATE curto_pds_chg FROM ls_curto_pds_chg_new.&lt;BR /&gt;        ENDIF.&lt;BR /&gt;
&lt;BR /&gt;    ENDLOOP.&lt;BR /&gt;
&lt;BR /&gt;
 ENDMETHOD.&lt;/P&gt;&lt;P&gt;Before I implemented the whole update thing I just wrote the WHEN 'SAVE' statement and let it call the method display( ) again just to test if it would show the new or the old table in the ALV. It showed the new table so I thought I could go on and implement the whole thing.&lt;/P&gt;&lt;P&gt;Debugging it now I can see that the table I get from Get_data( ) is already a not updated one and I just don't know why since the table is a changing parameter when building the ALV. I give you my code for the display( )-method as well.&lt;/P&gt;&lt;P&gt;METHOD display.&lt;BR /&gt;
&lt;BR /&gt;    DATA: lt_fieldcat_fm TYPE slis_t_fieldcat_alv, "field catalog table for FM&lt;BR /&gt;               ls_fieldcat_fm TYPE slis_fieldcat_alv, "field catalog structure for loop&lt;BR /&gt;               lt_fieldcat_cl TYPE lvc_t_fcat, "field catalog table for alv method&lt;BR /&gt;               ls_fieldcat_cl TYPE lvc_s_fcat. "field catalog structure for loop&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
* builds a field catalog based on the structure of curto_pds_chg&lt;BR /&gt;    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'&lt;BR /&gt;        EXPORTING&lt;BR /&gt;            i_structure_name = 'CURTO_PDS_CHG'&lt;BR /&gt;        CHANGING&lt;BR /&gt;            ct_fieldcat = lt_fieldcat_fm&lt;BR /&gt;        EXCEPTIONS&lt;BR /&gt;            inconsistent_interface = 1&lt;BR /&gt;            program_error = 2&lt;BR /&gt;            OTHERS = 3.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
* loops the field catalog given from the function module into one&lt;BR /&gt;
* with a structure the alv display method accepts&lt;BR /&gt;    LOOP AT lt_fieldcat_fm INTO ls_fieldcat_fm.&lt;BR /&gt;        MOVE-CORRESPONDING ls_fieldcat_fm TO ls_fieldcat_cl.&lt;BR /&gt;        APPEND ls_fieldcat_cl TO lt_fieldcat_cl.&lt;BR /&gt;    ENDLOOP.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
* makes two columns editable (CHANGE &amp;amp; PROCESS)&lt;BR /&gt;    DATA: ls_fieldcat TYPE REF TO lvc_s_fcat.&lt;BR /&gt;    READ TABLE lt_fieldcat_cl&lt;BR /&gt;        WITH KEY fieldname = 'CHANGE' REFERENCE INTO ls_fieldcat.&lt;BR /&gt;    ls_fieldcat-&amp;gt;edit = 'X'.&lt;BR /&gt;    READ TABLE lt_fieldcat_cl&lt;BR /&gt;        WITH KEY fieldname = 'PROCESS' REFERENCE INTO ls_fieldcat.&lt;BR /&gt;    ls_fieldcat-&amp;gt;edit = 'X'.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
* builds alv grid&lt;BR /&gt;    IF go_container IS INITIAL.&lt;BR /&gt;
&lt;BR /&gt;    CREATE OBJECT go_container&lt;BR /&gt;    EXPORTING&lt;BR /&gt;        container_name = 'CONTAINER'.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;    CREATE OBJECT go_alv&lt;BR /&gt;    EXPORTING&lt;BR /&gt;        i_parent = go_container.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;    CALL METHOD go_alv-&amp;gt;set_table_for_first_display&lt;BR /&gt;        EXPORTING&lt;BR /&gt;            i_structure_name = 'CURTO_PDS_CHG'&lt;BR /&gt;        CHANGING&lt;BR /&gt;            it_outtab = gt_curto_pds_chg&lt;BR /&gt;            it_fieldcatalog = lt_fieldcat_cl.&lt;BR /&gt;        ELSE.&lt;BR /&gt;            go_alv-&amp;gt;refresh_table_display( ).&lt;BR /&gt;        ENDIF.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
 ENDMETHOD.&lt;/P&gt;&lt;P&gt;Can anybody spot the mistake why my database table is not updating?&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2017 13:02:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-database-from-editable-alv/m-p/397642#M10020</guid>
      <dc:creator>d067595</dc:creator>
      <dc:date>2017-02-15T13:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Update Database from editable ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-database-from-editable-alv/m-p/397643#M10021</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;make another internal table which can hold the data before you display.&lt;/P&gt;&lt;P&gt;In PBO:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;Write the code to register the edit and the changes you have made on the editable field will reflect on the internal table which you passed to display in grid alv.

CALL METHOD o_grid_alv-&amp;gt;register_edit_even
  EXPORTING i_event_id = cl_gui_alv_grid=&amp;gt;mc_evt_modified&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;the "save"-button on the PF-STATUS will be handled in PAI.&lt;/P&gt;&lt;P&gt;in PAI :&lt;/P&gt;&lt;P&gt;case sy-ucomm.&lt;/P&gt;&lt;P&gt;when 'SAVE'.&lt;/P&gt;&lt;P&gt;call method check_data_changed.&lt;/P&gt;&lt;P&gt;then compare the two internal table and update the database table with the changed records.&lt;/P&gt;&lt;P&gt;endcase.&lt;/P&gt;&lt;P&gt;you can refer the following link &lt;/P&gt;&lt;P&gt;&lt;A href="https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=37472" target="test_blank"&gt;https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=37472&lt;/A&gt;&lt;/P&gt;&lt;P&gt;thank you!!&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2017 13:42:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-database-from-editable-alv/m-p/397643#M10021</guid>
      <dc:creator>Chintu6august</dc:creator>
      <dc:date>2017-02-15T13:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: Update Database from editable ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-database-from-editable-alv/m-p/397644#M10022</link>
      <description>&lt;P&gt;Thank you those two lines of code totally solved my problem! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2017 14:56:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-database-from-editable-alv/m-p/397644#M10022</guid>
      <dc:creator>d067595</dc:creator>
      <dc:date>2017-02-15T14:56:01Z</dc:date>
    </item>
  </channel>
</rss>

