<?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 ALV, event DATA_CHANGED, avoid insert of duplicate key in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488180#M1653008</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to implement edit functionality of an internal table with ALV based on class CL_GUI_ALV_GRID. Some fields of internal table are key fields and the combination of them should be unique. The user has a possibility to add a new record (all fields in new record are editable) or change values in an existing record (only non-key fields are editable). So far so good, it works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm doing a validation of entered data in the event DATA_CHANGED. In this event I'm checking if the new record is a duplicate combination of existing key fields. If yes, then all fields of the new record are reported as error with ADD_PROTOCOL_ENTRY method. This removes all entries related to this row from MT_GOOD_CELLS table and this is ok for me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My problem: after validation ALV inserts such empty row in my internal table and next time, when the user makes a correction, this record is an update and not a new record (there is no entry in MT_INSERTED_ROWS). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Question: Is there a possibility to avoid ALV inserting a new record when all its cells are bad?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Annie&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Jan 2012 08:44:09 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2012-01-06T08:44:09Z</dc:date>
    <item>
      <title>ALV, event DATA_CHANGED, avoid insert of duplicate key</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488180#M1653008</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to implement edit functionality of an internal table with ALV based on class CL_GUI_ALV_GRID. Some fields of internal table are key fields and the combination of them should be unique. The user has a possibility to add a new record (all fields in new record are editable) or change values in an existing record (only non-key fields are editable). So far so good, it works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm doing a validation of entered data in the event DATA_CHANGED. In this event I'm checking if the new record is a duplicate combination of existing key fields. If yes, then all fields of the new record are reported as error with ADD_PROTOCOL_ENTRY method. This removes all entries related to this row from MT_GOOD_CELLS table and this is ok for me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My problem: after validation ALV inserts such empty row in my internal table and next time, when the user makes a correction, this record is an update and not a new record (there is no entry in MT_INSERTED_ROWS). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Question: Is there a possibility to avoid ALV inserting a new record when all its cells are bad?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Annie&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2012 08:44:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488180#M1653008</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-06T08:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: ALV, event DATA_CHANGED, avoid insert of duplicate key</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488181#M1653009</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 did the same ALV and event handle. We use this ALV to edit/insert records in the Z table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My solution was to create two internal tables, one for inserted records and other to update records.&lt;/P&gt;&lt;P&gt;If user change the empty row, it was a update row to ALV, but a new line in output table. Then i did a select to check if the updated ALV row exists. When user press the SAVE button, the program process the records to update and the records to insert.  I did not find a way to block the empty row create.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2012 10:45:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488181#M1653009</guid>
      <dc:creator>rodrigo_paisante3</dc:creator>
      <dc:date>2012-01-06T10:45:41Z</dc:date>
    </item>
    <item>
      <title>Re: ALV, event DATA_CHANGED, avoid insert of duplicate key</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488182#M1653010</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 dont know how to avoid addition of empty row,&lt;/P&gt;&lt;P&gt;But to fix your issue,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Whenever  ADD_PROTOCOL_ENTRY catches error,&lt;/P&gt;&lt;P&gt;you can delete the row from internal table with key as initial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Harsh Bansal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jan 2012 10:56:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488182#M1653010</guid>
      <dc:creator>Harsh_Bansal</dc:creator>
      <dc:date>2012-01-06T10:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: ALV, event DATA_CHANGED, avoid insert of duplicate key</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488183#M1653011</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;As far as i have understood your problem,you can try the following to avoid the insertion of an empty row:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you must be creating an empty row,just set a flag say flag_create = 'X'.&lt;/P&gt;&lt;P&gt;Then when you are performing the validation then if there is an error then check for this flag that is :&lt;/P&gt;&lt;P&gt;if flag_create = 'X'.&lt;/P&gt;&lt;P&gt;then delete from the internal table based on sy-tabix.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;This way the new row that got appended with wrong values will get deleted and the code will not consider this as an updated row.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kindly &amp;lt;&amp;lt;deleted&amp;gt; if useful.:)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __default_attr="red" __jive_macro_name="color"&gt;Follow the rules of engagement&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Vijay Babu Dudla on Jan 9, 2012 7:07 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 09 Jan 2012 11:22:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488183#M1653011</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-09T11:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: ALV, event DATA_CHANGED, avoid insert of duplicate key</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488184#M1653012</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for all answers. If I delete the empty rows from the internal table, the new inputs are stored in MT_INSERTED_ROWS as I wanted. Then I've to deal with next problems, which I haven't expected, &lt;/P&gt;&lt;P&gt;for example if user entered two new rows: first row is wrong (1) and the second is ok (2). ALV will do both inserts, &lt;/P&gt;&lt;P&gt;then I'm deleting the empty one (1), and next time the corrected row (1) overwrites the row, which was inserted previously (2). &lt;/P&gt;&lt;P&gt;I think, I've to implement it without removing empty rows. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers, &lt;/P&gt;&lt;P&gt;Annie&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jan 2012 13:38:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488184#M1653012</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-12T13:38:23Z</dc:date>
    </item>
    <item>
      <title>Re: ALV, event DATA_CHANGED, avoid insert of duplicate key</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488185#M1653013</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 think its happening because you are deleting the rows with sy-tabix.And since you are looping and then deleting so everytime the sy-tabix value is remaining the same.Hence its getting overwritten.&lt;/P&gt;&lt;P&gt;For this you can try setting another flag as soon as one line is deleted like below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at internal table into work area.&lt;/P&gt;&lt;P&gt;if flag_delete is initial.&lt;/P&gt;&lt;P&gt;delete from the internal table based on sy-tabix.&lt;/P&gt;&lt;P&gt;flag_delete = 'X'.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is just a format that you can try implementing in your logic.&lt;/P&gt;&lt;P&gt;I hope it serves useful to you.:)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jan 2012 14:12:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/alv-event-data-changed-avoid-insert-of-duplicate-key/m-p/8488185#M1653013</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2012-01-12T14:12:44Z</dc:date>
    </item>
  </channel>
</rss>

