<?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: Catching failed db inserts in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020115#M960587</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use ACCEPTING DUPLICATE KEYS &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;INSERT zSTOCKOUT FROM TABLE itab_stockouts ACCEPTING DUPLICATE KEYS .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please reward points.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Romit&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Romit Kewalramani on Jun 18, 2008 2:41 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 18 Jun 2008 00:34:30 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-06-18T00:34:30Z</dc:date>
    <item>
      <title>Catching failed db inserts</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020114#M960586</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;A quickie...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I use the statement &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;INSERT zSTOCKOUT FROM TABLE itab_stockouts.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;how would I avoid a short dump if the table already contains a row with the unique key?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried following the statement by sy-subrc NE 0, but it still short dumps before it even evaluates my statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't want to go through the whole itab to do a check first if I can help it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Charl&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2008 00:17:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020114#M960586</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-18T00:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Catching failed db inserts</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020115#M960587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use ACCEPTING DUPLICATE KEYS &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;INSERT zSTOCKOUT FROM TABLE itab_stockouts ACCEPTING DUPLICATE KEYS .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please reward points.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Romit&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Romit Kewalramani on Jun 18, 2008 2:41 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2008 00:34:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020115#M960587</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-18T00:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Catching failed db inserts</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020116#M960588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;The best way use the Modify statement .&lt;/P&gt;&lt;P&gt;If it finds the keys then it will update the record or it will inser a new record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this will help you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Help children of U.N World Food Program by rewarding them and encourage others to answer your queries&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2008 06:30:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020116#M960588</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-18T06:30:54Z</dc:date>
    </item>
    <item>
      <title>Re: Catching failed db inserts</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020117#M960589</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;Its better to do with MODIFY statemnt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Modify acts both as insert and update&lt;/P&gt;&lt;P&gt;if a row exists it acts as update otherwise as update&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope i am clear&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;prasanth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2008 06:40:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020117#M960589</guid>
      <dc:creator>prasanth_kasturi</dc:creator>
      <dc:date>2008-06-18T06:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Catching failed db inserts</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020118#M960590</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So there is no way to capture the error without a short dump?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't really need it to modify. If it is there it doesn't need to do anything.&lt;/P&gt;&lt;P&gt;Thanks for the suggestions though&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2008 06:49:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020118#M960590</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-18T06:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: Catching failed db inserts</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020119#M960591</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; So there is no way to capture the error without a short dump?&lt;/P&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;P&gt;&amp;gt; I don't really need it to modify. If it is there it doesn't need to do anything.&lt;/P&gt;&lt;P&gt;&amp;gt; Thanks for the suggestions though&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You can use a TRY ..... ENDTRY to catch the exception eg&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
* For use with class based exception CX_SY_OPEN_SQL_DB.
  DATA:
  ex_check_os       TYPE REF TO cx_sy_open_sql_db,
  ex_check_rs       TYPE REF TO cx_sy_native_sql_error,
  ex_result(200)    TYPE C,
  ex_text           TYPE STRING.

  CLEAR: ex_check_os, ex_text.
   SORT gt_zswift_map BY ebeln swift_line_no.
   TRY.
     INSERT zswift_map
     FROM TABLE gt_zswift_map.
     CATCH CX_SY_OPEN_SQL_DB INTO ex_check_os.
     ex_text = ex_check_os-&amp;gt;get_text( ).
     ROLLBACK WORK.
     w_stop_job = 'X'.
     CONCATENATE 'ERROR' ex_text INTO ex_text SEPARATED BY SPACE.
     MESSAGE ex_text TYPE 'I'.
     IF w_stop_job = 'X'.
        RETURN.
     ENDIF.
   ENDTRY.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The other way of avoiding a dump would be to check for the existence of a record before trying to insert it, which is effectively (I would think) what MODIFY does.  I would NEVER use ACCEPTING DUPLICATE ENTRIES, because I think you need to know whether a record is new or if it already exists.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2008 09:00:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020119#M960591</guid>
      <dc:creator>christine_evans</dc:creator>
      <dc:date>2008-06-18T09:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Catching failed db inserts</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020120#M960592</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I like this TRY command, never seen it before.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That will work I think.&lt;/P&gt;&lt;P&gt;I'll give it a shot and read up about the command in general.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Although I am still puzzled why the help says INSERT sets sy-subrc to 4 when a duplicate is found, but you can't do anything about it.&lt;/P&gt;&lt;P&gt;Bet that try command will solve many such situations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again, that does it for me.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jun 2008 13:04:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/catching-failed-db-inserts/m-p/4020120#M960592</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-18T13:04:10Z</dc:date>
    </item>
  </channel>
</rss>

