<?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 DB table with logic in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451439#M1413875</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;What i did is &lt;/P&gt;&lt;P&gt;1. copy the data to new internal table (read before update )&lt;/P&gt;&lt;P&gt;2. Run for all the users (i have tabe it_unq_bnames which store all the users unique ) &lt;/P&gt;&lt;P&gt;3. Do loop on the copy db table and &lt;/P&gt;&lt;P&gt; Do read on the new data (it_new_usrs_data ) with key .&lt;/P&gt;&lt;P&gt;4.Update new table (lt_modif) which update the end table on DB &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question if it's good way to this or if there is another way to do that ,&lt;/P&gt;&lt;P&gt;performance is very important ?&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;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;**----Read before update ----*

  SELECT *
   FROM Zd_r_data
    INTO TABLE lt_copy_db
    WHERE valid EQ abap_true.
*---Update table

  LOOP AT it_unq_bnames INTO ls_unq_bnames.
    LOOP AT lt_copy_db ASSIGNING &amp;lt;fs_copy_db&amp;gt;.
      READ TABLE it_new_usrs_data ASSIGNING &amp;lt;fs_rs_new&amp;gt; WITH KEY
         bname = &amp;lt;fs_copy_db&amp;gt;-bname
         agr_name = &amp;lt;fs_copy_db&amp;gt;-agr_name
      IF sy-subrc EQ 0.
        ls_modif_rs-agr_name = &amp;lt;fs_copy_db&amp;gt;-agr_name.
        ls_modif_rs-bname = &amp;lt;fs_copy_db&amp;gt;-bname.
        ls_modif_rs-id = &amp;lt;fs_copy_db&amp;gt;-id.
        ls_modif_rs-last_update = &amp;lt;fs_copy_db&amp;gt;-last_update.
        ls_modif_rs-mandt = &amp;lt;fs_copy_db&amp;gt;-mandt.
        ls_modif_rs-valid = abap_true.
      ELSE.
        ls_modif_rs-agr_name = &amp;lt;fs_copy_db&amp;gt;-agr_name.
        ls_modif_rs-bname = &amp;lt;fs_copy_db&amp;gt;-bname.
        ls_modif_rs-id = &amp;lt;fs_copy_db&amp;gt;-id.
        ls_modif_rs-last_update = &amp;lt;fs_copy_db&amp;gt;-last_update.
        ls_modif_rs-mandt = &amp;lt;fs_copy_db&amp;gt;-mandt.
        ls_modif_rs-valid = abap_false.
      ENDIF.
      APPEND ls_modif_rs TO lt_modif.
    ENDLOOP.
  ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Chris Teb on Jan 6, 2010 9:48 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 Jan 2010 13:58:26 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2010-01-06T13:58:26Z</dc:date>
    <item>
      <title>Update DB table with logic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451432#M1413868</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 table with records in DB which i need to modify from internal table via job.&lt;/P&gt;&lt;P&gt;if we start from scratch (fill the db table in the first time ) all the records should be valid &lt;/P&gt;&lt;P&gt;(column valid mark as abap_true) &lt;/P&gt;&lt;P&gt;in the next run if new data will come to the table the records should be valid automatically &lt;/P&gt;&lt;P&gt;and if some records are not occur in the second run the record in the table should be not valid &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what is the best way to do that .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i give an example &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in the first run i have users in the itab ( that update the db) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;users    roles   valid_flag &lt;/P&gt;&lt;P&gt;user1    rol1      X&lt;/P&gt;&lt;P&gt;user1    rol2      X&lt;/P&gt;&lt;P&gt;user1    rol3      X&lt;/P&gt;&lt;P&gt;user2    rol1      X&lt;/P&gt;&lt;P&gt;user2    rol2      X&lt;/P&gt;&lt;P&gt;user2    rol3      X&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This what i have in the internal table and what should be in the db table also .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in the next run i have in the itab&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;user1    rol1      X&lt;/P&gt;&lt;P&gt;user1    rol2      X&lt;/P&gt;&lt;P&gt;user1    rol4      X&lt;/P&gt;&lt;P&gt;user2    rol1      X&lt;/P&gt;&lt;P&gt;user2    rol5      X&lt;/P&gt;&lt;P&gt;user2    rol6      X&lt;/P&gt;&lt;P&gt;user3    rol1      X&lt;/P&gt;&lt;P&gt;user3    rol5      X&lt;/P&gt;&lt;P&gt;user3    rol3      X&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so after the following run the table should look like .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;users    roles   valid_flag &lt;/P&gt;&lt;P&gt;user1    rol1      X&lt;/P&gt;&lt;P&gt;user1    rol2      X&lt;/P&gt;&lt;P&gt;user1    rol3      &lt;/P&gt;&lt;P&gt;user1    rol4      X&lt;/P&gt;&lt;P&gt;user2    rol1      X&lt;/P&gt;&lt;P&gt;user2    rol2     &lt;/P&gt;&lt;P&gt;user2    rol3      &lt;/P&gt;&lt;P&gt;user2    rol5      X&lt;/P&gt;&lt;P&gt;user2    rol6      X&lt;/P&gt;&lt;P&gt;user3    rol1      X&lt;/P&gt;&lt;P&gt;user3    rol5      X&lt;/P&gt;&lt;P&gt;user3    rol3      X&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The old records are not deleted there are just mark as not valid and if we have new records &lt;/P&gt;&lt;P&gt;they are inserted to the table with valid flag .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the best way to do that .&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>Mon, 04 Jan 2010 13:02:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451432#M1413868</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-04T13:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: Update DB table with logic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451433#M1413869</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Chris,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it depends on the table size: If it's not too much you can read the whole table to internal table in memory, preferedly hashed or sorted table, then apply the logic creating one internal table for new records to be inserted and another one for records to be updated, finally use INSERT or UPDATE FROM TABLE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is no BEST method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jan 2010 13:51:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451433#M1413869</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2010-01-04T13:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Update DB table with logic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451434#M1413870</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;Update the DB table either insert  or update by using Update function module. Create a new function module and use that to update the table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jayaram&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jan 2010 13:54:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451434#M1413870</guid>
      <dc:creator>Jay71</dc:creator>
      <dc:date>2010-01-04T13:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Update DB table with logic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451435#M1413871</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Clemens ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you help with the logic since i want to do read before update to internal table and do some compression between the table and i dont know how to proceed .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jan 2010 18:08:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451435#M1413871</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-04T18:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: Update DB table with logic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451436#M1413872</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Chris,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I already gave the logic. The coding is done by you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Jan 2010 18:11:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451436#M1413872</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2010-01-04T18:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Update DB table with logic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451437#M1413873</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 am facing problems with the code there is someone that can help with this code ?&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jan 2010 06:15:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451437#M1413873</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-05T06:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Update DB table with logic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451438#M1413874</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear Chris,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you are facing problems with the code, then where is the problem? If you are facing problems with writing the code, then this is not the right place to ask people to do the job you get paid for. This could be misunderstood as a misuse of this forum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clemens&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jan 2010 07:54:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451438#M1413874</guid>
      <dc:creator>Clemenss</dc:creator>
      <dc:date>2010-01-05T07:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Update DB table with logic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451439#M1413875</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;What i did is &lt;/P&gt;&lt;P&gt;1. copy the data to new internal table (read before update )&lt;/P&gt;&lt;P&gt;2. Run for all the users (i have tabe it_unq_bnames which store all the users unique ) &lt;/P&gt;&lt;P&gt;3. Do loop on the copy db table and &lt;/P&gt;&lt;P&gt; Do read on the new data (it_new_usrs_data ) with key .&lt;/P&gt;&lt;P&gt;4.Update new table (lt_modif) which update the end table on DB &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question if it's good way to this or if there is another way to do that ,&lt;/P&gt;&lt;P&gt;performance is very important ?&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;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;**----Read before update ----*

  SELECT *
   FROM Zd_r_data
    INTO TABLE lt_copy_db
    WHERE valid EQ abap_true.
*---Update table

  LOOP AT it_unq_bnames INTO ls_unq_bnames.
    LOOP AT lt_copy_db ASSIGNING &amp;lt;fs_copy_db&amp;gt;.
      READ TABLE it_new_usrs_data ASSIGNING &amp;lt;fs_rs_new&amp;gt; WITH KEY
         bname = &amp;lt;fs_copy_db&amp;gt;-bname
         agr_name = &amp;lt;fs_copy_db&amp;gt;-agr_name
      IF sy-subrc EQ 0.
        ls_modif_rs-agr_name = &amp;lt;fs_copy_db&amp;gt;-agr_name.
        ls_modif_rs-bname = &amp;lt;fs_copy_db&amp;gt;-bname.
        ls_modif_rs-id = &amp;lt;fs_copy_db&amp;gt;-id.
        ls_modif_rs-last_update = &amp;lt;fs_copy_db&amp;gt;-last_update.
        ls_modif_rs-mandt = &amp;lt;fs_copy_db&amp;gt;-mandt.
        ls_modif_rs-valid = abap_true.
      ELSE.
        ls_modif_rs-agr_name = &amp;lt;fs_copy_db&amp;gt;-agr_name.
        ls_modif_rs-bname = &amp;lt;fs_copy_db&amp;gt;-bname.
        ls_modif_rs-id = &amp;lt;fs_copy_db&amp;gt;-id.
        ls_modif_rs-last_update = &amp;lt;fs_copy_db&amp;gt;-last_update.
        ls_modif_rs-mandt = &amp;lt;fs_copy_db&amp;gt;-mandt.
        ls_modif_rs-valid = abap_false.
      ENDIF.
      APPEND ls_modif_rs TO lt_modif.
    ENDLOOP.
  ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Chris Teb on Jan 6, 2010 9:48 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jan 2010 13:58:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451439#M1413875</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-06T13:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Update DB table with logic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451440#M1413876</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Chris,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    Wht I understood from ur query is u need the data to be updated which does not exist in internal table and insert the data tht is in the IT, if it is so then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at it into wa.&lt;/P&gt;&lt;P&gt;   select single * from zdb_table where user = wa-user and roll = wa-roll.&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;   wa-valid = ' '.&lt;/P&gt;&lt;P&gt;modify zdb_table from wa.&lt;/P&gt;&lt;P&gt;else.&lt;/P&gt;&lt;P&gt;insert wa to zdb_table.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Anmol&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jan 2010 21:14:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451440#M1413876</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-06T21:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Update DB table with logic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451441#M1413877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Anmol&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;its not that simple ...&lt;/P&gt;&lt;P&gt;I have table with records in DB which i need to modify from internal table via job.&lt;/P&gt;&lt;P&gt;if we start from scratch (fill the DB table in the first time ) all the records should be &lt;STRONG&gt;valid&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;(column valid mark as abap_true)&lt;/P&gt;&lt;P&gt;in the next run if new data will come to the table (it_new_usrs_data)  the &lt;STRONG&gt;new records should be valid automatically&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;and if some records are not occur (in it_new_usrs_data ) in the second run the record in the DB  table should be not valid .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see the the example in my first post .&lt;/P&gt;&lt;P&gt;What i want to avoid the select single in loop because of performance  the DB table can store more than 100000 records ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you have diff idea ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in the first run i have users in the itab ( that update the DB)&lt;/P&gt;&lt;P&gt;Assume that after the first run i this is the DB table that i read in the second run with the select to lt_copy_db&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;users roles valid_flag&lt;/P&gt;&lt;P&gt;user1 rol1 X&lt;/P&gt;&lt;P&gt;user1 rol2 X&lt;/P&gt;&lt;P&gt;user1 rol3 X&lt;/P&gt;&lt;P&gt;user2 rol1 X&lt;/P&gt;&lt;P&gt;user2 rol2 X&lt;/P&gt;&lt;P&gt;user2 rol3 X&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the next run of the job  i have in the internal table it_new_usrs_data&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;user1 rol1 X&lt;/P&gt;&lt;P&gt;user1 rol2 X&lt;/P&gt;&lt;P&gt;user1 rol4 X&lt;/P&gt;&lt;P&gt;user2 rol1 X&lt;/P&gt;&lt;P&gt;user2 rol5 X&lt;/P&gt;&lt;P&gt;user2 rol6 X&lt;/P&gt;&lt;P&gt;user3 rol1 X&lt;/P&gt;&lt;P&gt;user3 rol5 X&lt;/P&gt;&lt;P&gt;user3 rol3 X&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so after the following run the DB  table should look like .&lt;/P&gt;&lt;P&gt;The o_ld records are not deleted_ &lt;U&gt;there are just mark as not valid&lt;/U&gt; and if we have &lt;U&gt;new&lt;/U&gt; records&lt;/P&gt;&lt;P&gt;they are inserted to the table with &lt;U&gt;valid flag&lt;/U&gt; .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;users roles valid_flag&lt;/P&gt;&lt;P&gt;user1 rol1 X&lt;/P&gt;&lt;P&gt;user1 rol2 X&lt;/P&gt;&lt;P&gt;user1 rol3&lt;/P&gt;&lt;P&gt;user1 rol4 X&lt;/P&gt;&lt;P&gt;user2 rol1 X&lt;/P&gt;&lt;P&gt;user2 rol2&lt;/P&gt;&lt;P&gt;user2 rol3&lt;/P&gt;&lt;P&gt;user2 rol5 X&lt;/P&gt;&lt;P&gt;user2 rol6 X&lt;/P&gt;&lt;P&gt;user3 rol1 X&lt;/P&gt;&lt;P&gt;user3 rol5 X&lt;/P&gt;&lt;P&gt;user3 rol3 X&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &lt;/P&gt;&lt;P&gt;Chris&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Chris Teb on Jan 6, 2010 10:58 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jan 2010 21:52:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451441#M1413877</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-01-06T21:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Update DB table with logic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451442#M1413878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Chris,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. First, you need to find the records which are in the db but not in your internal table. Store these records in a separate internal table &lt;STRONG&gt;difference_tab&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;2. Loop through the it_new_users_data and whatever records found in the db table, update them as valid. If the record is not found, insert them as valid records. You can use MODIFY statement which would ensure either modify or insert for such records.&lt;/P&gt;&lt;P&gt;3. Finally update all records in the difference_tab as invalid in the db table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Before worrying about performance, first choose the reliable logic which would work in all scenarios. After successful first round of testing, carry-out performance testing and tune if necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As it is already pointed out, implementing code for above logic is your responsibility and you should not expect other forum members to work for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;Suresh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jan 2010 23:26:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-db-table-with-logic/m-p/6451442#M1413878</guid>
      <dc:creator>SureshRa</dc:creator>
      <dc:date>2010-01-06T23:26:30Z</dc:date>
    </item>
  </channel>
</rss>

