<?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: Update table and insert  on the same time in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251603#M1383794</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Marcin&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you think that i need to use select single (inside loop )  for every user since i can have table with have 100000 users ?&lt;/P&gt;&lt;P&gt;performance is very important in this case &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;another thing that i consider is to use for the design 2 DB tables since i can have user with 5 records of data  &lt;/P&gt;&lt;P&gt;like &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;user1  data1&lt;/P&gt;&lt;P&gt;user1  data2&lt;/P&gt;&lt;P&gt;user1  data3 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;one for the user and another table with user and his entries (like header and lines ) what do you think ? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Chris Teb on Nov 13, 2009 9:25 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Nov 2009 08:24:37 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-11-13T08:24:37Z</dc:date>
    <item>
      <title>Update table and insert  on the same time</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251601#M1383792</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI All ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have Z DB table which i need to to update via program and i need to use the following process .&lt;/P&gt;&lt;P&gt;1. Assume the table have already user with his data and the process don't have changes in  the user data -&amp;gt;dont do anything &lt;/P&gt;&lt;P&gt; 2. If the user have new data -&amp;gt; mark the old entry as not valid and insert new entry &lt;/P&gt;&lt;P&gt; 3. if there is new user is coming on the update process insert him to the new table and mark the entry as valid &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The DB table have this fields as :&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;1. mandt  "key
2. uuid     "key
3. user 
4 . user data 
5 . time stemp
6. valid_entry  " yes or no&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the the best solution to handle this issue ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Nov 2009 08:03:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251601#M1383792</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-13T08:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Update table and insert  on the same time</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251602#M1383793</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you have answered the question yourself by describing the process step by step. Simply transfer the logic to the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
select * ....  where ...  "check existence of data for the user
if sy-subrc ne 0 .   "if data doesn't exists
   if new_user = 'X'.
      "new user is coming, new data requeired
       insert ... "insert data with field valid_entry = 'YES'.  
    else.
      "old user, but new data
      update .... set valid_entry = 'NO'.  "first update old entry to invalid
      insert    .... "then insert new data with valid_entry = 'YES'.
    endif.
endif.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This should suffice&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Nov 2009 08:12:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251602#M1383793</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2009-11-13T08:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: Update table and insert  on the same time</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251603#M1383794</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Marcin&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you think that i need to use select single (inside loop )  for every user since i can have table with have 100000 users ?&lt;/P&gt;&lt;P&gt;performance is very important in this case &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;another thing that i consider is to use for the design 2 DB tables since i can have user with 5 records of data  &lt;/P&gt;&lt;P&gt;like &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;user1  data1&lt;/P&gt;&lt;P&gt;user1  data2&lt;/P&gt;&lt;P&gt;user1  data3 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;one for the user and another table with user and his entries (like header and lines ) what do you think ? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Chris Teb on Nov 13, 2009 9:25 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Nov 2009 08:24:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251603#M1383794</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-13T08:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: Update table and insert  on the same time</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251604#M1383795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Chris,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not needed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Select the records in a single shot using SELECT ... INTO TABLE itab. SORT it by the key fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. LOOP AT required table &amp;amp; use READ TABLE itab ... BINARY SEARCH with the key fields to read the data from the internal table &amp;amp; proceed as suggested by Marcin.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this is clear.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Suhas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Nov 2009 08:30:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251604#M1383795</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2009-11-13T08:30:04Z</dc:date>
    </item>
    <item>
      <title>Re: Update table and insert  on the same time</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251605#M1383796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, I think as far as performance is concerned, you should avoid select statement within loop. This is because for every single record from internal table with user, there has to be established separate session with DB. This has impact on the performace which is low then.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suggest to get these data at once with &lt;STRONG&gt;select ... for all entries...into table ...&lt;/STRONG&gt; (so you connect with DB only once) and you store all the record locally in internal table. Then simply loop at that table and check each record for existence. That will certainly improve the performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Marcin&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;another thing that i consider is to use for the design 2 DB tables since i can have user with 5 records of data&lt;/P&gt;&lt;P&gt;like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;user1 data1&lt;/P&gt;&lt;P&gt;user1 data2&lt;/P&gt;&lt;P&gt;user1 data3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;one for the user and another table with user and his entries (like header and lines ) what do you think ? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This is ok from design perspective, but I think it introduces new table to handle with. If there is no to much data about user to store, there is not point in creating separate table to hold that information. Conversely if data about user is huge (like 10-20 fields) you can have them in some "header" table like you said.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Marcin Pciak on Nov 13, 2009 9:36 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Nov 2009 08:32:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251605#M1383796</guid>
      <dc:creator>MarcinPciak</dc:creator>
      <dc:date>2009-11-13T08:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Update table and insert  on the same time</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251606#M1383797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;Select * from Ztable into wa_ztable where uuid = id.

    if sy-subrc = 0.  ""already existing user.

        if wa_ztable &amp;lt;&amp;gt; user_data.  ""the user data is different from the database entry.

           wa_ztable-valid_entry = 'N'.

           update ztable from wa_table transporting all fields. "making the record as not a valid entry

           update ztable from user_data transporting all fields.  " inserting a new record.

        endif.

     else.

       update ztable from user_data transporting all fields.  " inserting a new record.

     endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Nov 2009 08:32:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-table-and-insert-on-the-same-time/m-p/6251606#M1383797</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-11-13T08:32:25Z</dc:date>
    </item>
  </channel>
</rss>

