<?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 statement inside a Loop in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068813#M94166</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;Anybody knows how I can improve this code? It doesnt seem to be working right since i'm supposed to loop through it_zplan and use the value in it_zplan-seqnr to update a custom table zplan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      LOOP AT it_zplan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        UPDATE zplan&lt;/P&gt;&lt;P&gt;          SET seqnr = it_zplan-seqnr&lt;/P&gt;&lt;P&gt;          WHERE gjahr = it_zplan-gjahr AND&lt;/P&gt;&lt;P&gt;                versn = it_zplan-versn AND&lt;/P&gt;&lt;P&gt;                kostl = it_zplan-kostl AND&lt;/P&gt;&lt;P&gt;                ctype = it_zplan-ctype AND&lt;/P&gt;&lt;P&gt;                emgrp = it_zplan-emgrp AND&lt;/P&gt;&lt;P&gt;                pernr = it_zplan-pernr.&lt;/P&gt;&lt;P&gt;      ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks. Useful answer will be rewarded.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 02 Dec 2005 17:49:57 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2005-12-02T17:49:57Z</dc:date>
    <item>
      <title>Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068813#M94166</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;Anybody knows how I can improve this code? It doesnt seem to be working right since i'm supposed to loop through it_zplan and use the value in it_zplan-seqnr to update a custom table zplan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      LOOP AT it_zplan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        UPDATE zplan&lt;/P&gt;&lt;P&gt;          SET seqnr = it_zplan-seqnr&lt;/P&gt;&lt;P&gt;          WHERE gjahr = it_zplan-gjahr AND&lt;/P&gt;&lt;P&gt;                versn = it_zplan-versn AND&lt;/P&gt;&lt;P&gt;                kostl = it_zplan-kostl AND&lt;/P&gt;&lt;P&gt;                ctype = it_zplan-ctype AND&lt;/P&gt;&lt;P&gt;                emgrp = it_zplan-emgrp AND&lt;/P&gt;&lt;P&gt;                pernr = it_zplan-pernr.&lt;/P&gt;&lt;P&gt;      ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks. Useful answer will be rewarded.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 17:49:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068813#M94166</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-02T17:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068814#M94167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is ZPLAN and IT_ZPLAN have the same structure?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I never use the UPDATE statement, so I can't offer anything on that.  I use modify.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;report zrich_0001.



data: it_zplan type table of zplan.
data: wa_zplan like line of it_zplan.


loop at it_zplan into wa_zplan.
  modify zplan from wa_zplan.
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 17:53:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068814#M94167</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-02T17:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068815#M94168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;  We should not use UPDATE statement inside a loop. It won't work properly. Sometimes it may even cause a dump.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try to use Modify instead of Update. Modify will update the database table and can be used within a Loop...EndLoop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  Pl. reward points if useful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 17:54:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068815#M94168</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-02T17:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068816#M94169</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 tried this but the table was not updated since they dont have the same value in the key fields, seqnr is one of the key fields that will be updated inside the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;my table has these keys&lt;/P&gt;&lt;P&gt;1. pernr&lt;/P&gt;&lt;P&gt;2. seqnr&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;currently seqnr is empty&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 17:59:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068816#M94169</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-02T17:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068817#M94170</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ricky, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use the following code.&lt;/P&gt;&lt;P&gt;LOOP AT it_zplan.&lt;/P&gt;&lt;P&gt;modify zplan from it_zplan.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OR &lt;/P&gt;&lt;P&gt;you can directly use &lt;/P&gt;&lt;P&gt;modify zplan from table it_zplan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lokesh&lt;/P&gt;&lt;P&gt;Please reward appropriate points&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 18:03:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068817#M94170</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-02T18:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068818#M94171</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think that when you change the key, a new record is created instead of modifing the existing.  This happens when you are updating a field that is part of the key.  Do you want to get rid of the old record when you update?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 18:04:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068818#M94171</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-02T18:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068819#M94172</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;lt;b&amp;gt;&amp;lt;u&amp;gt;You cannot update key fields&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;. You have to delete the record and add the new record with the updated key field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Srinivas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 18:05:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068819#M94172</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-02T18:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068820#M94173</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can do something like this....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;


report zrich_0001.


data: it_zplan type table of zplan.
data: wa_zplan like line of it_zplan.

loop at it_zplan into wa_zplan.

* Modify will create the new record.
  modify zplan from wa_zplan.

* Now delete the old record.
  clear wa_zplan-seqnr.
  delete zplan from wa_zplan.

endloop.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 18:07:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068820#M94173</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-02T18:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068821#M94174</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, this is the one i would like to happen:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;old values:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PERNR SEQNR&lt;/P&gt;&lt;P&gt;0001  000&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;should be replaced with new values&lt;/P&gt;&lt;P&gt;PERNR SEQNR&lt;/P&gt;&lt;P&gt;0001  value in it_zplan-seqnr&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 18:08:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068821#M94174</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-02T18:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068822#M94175</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Following the coding above then.  It works good for me. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 18:12:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068822#M94175</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2005-12-02T18:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068823#M94176</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;try the below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : it_zplan_mod type standard table of ZPLAN with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT it_zplan.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select single * into it_zplan_mod &lt;/P&gt;&lt;P&gt;where gjahr = it_zplan-gjahr AND&lt;/P&gt;&lt;P&gt;versn = it_zplan-versn AND&lt;/P&gt;&lt;P&gt;kostl = it_zplan-kostl AND&lt;/P&gt;&lt;P&gt;ctype = it_zplan-ctype AND&lt;/P&gt;&lt;P&gt;emgrp = it_zplan-emgrp AND&lt;/P&gt;&lt;P&gt;pernr = it_zplan-pernr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it_zplan_mod-seqnr = it_zplan-seqnr.&lt;/P&gt;&lt;P&gt;modify it_zplan_mod.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;delete from zplan&lt;/P&gt;&lt;P&gt;where gjahr = it_zplan-gjahr AND&lt;/P&gt;&lt;P&gt;versn = it_zplan-versn AND&lt;/P&gt;&lt;P&gt;kostl = it_zplan-kostl AND&lt;/P&gt;&lt;P&gt;ctype = it_zplan-ctype AND&lt;/P&gt;&lt;P&gt;emgrp = it_zplan-emgrp AND&lt;/P&gt;&lt;P&gt;pernr = it_zplan-pernr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MODIFY zplan from it_zplan_mod.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Pl. award appropriate points.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 18:16:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068823#M94176</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-02T18:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068824#M94177</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ricky,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Which HR Table are you trying to Update? SEQNR can be updated on some tables eventhough it is part of the key.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Suresh Datti&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S. was I so dumb not see that it was a custom table?will blame it on Friday...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Suresh Datti&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 18:16:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068824#M94177</guid>
      <dc:creator>suresh_datti</dc:creator>
      <dc:date>2005-12-02T18:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068825#M94178</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 used the solution given by Rich Heilman and it worked perfectly. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for all who replied.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ricky&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 18:34:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068825#M94178</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-02T18:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: Update statement inside a Loop</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068826#M94179</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ricky,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As Srinivas said, you can never change the values of key fields of a record.(RDBMS concepts are at stake, if anything of that sort, ever happens!!!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;Though its good to know that, you were able to solve your problem, it points to a poor design of your custom table.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Raj&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Dec 2005 18:38:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/update-statement-inside-a-loop/m-p/1068826#M94179</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-12-02T18:38:35Z</dc:date>
    </item>
  </channel>
</rss>

