<?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 please check my code... in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264283#M148622</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here is what my code does: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;after appending to itab, it loops through itab and checks the first record of every instance of a new sernr. So when the sernr satisfies the IF conditon, it now move those records through another itab. the example below satisfies the condition since it's first record satisfies the IF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      sernr             bwart&lt;/P&gt;&lt;P&gt;      123456             702&lt;/P&gt;&lt;P&gt;      123456             701&lt;/P&gt;&lt;P&gt;      123456             711&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but my problem is this, if it loops through another sernr where its first record does not satisfy the condition like the example below it must ignore the first record and the following records of the same sernr must be moved.&lt;/P&gt;&lt;P&gt;I edited my code and it works but here is the catch, when I use the same test data it NOW INSERTS THE FIRST RECORD WHEN IT SHOULDNT. Help would really be appreciated and comments too. Thanks you guys!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      sernr               bwart&lt;/P&gt;&lt;P&gt;     654321               701   --&amp;gt; ignore/delete&lt;/P&gt;&lt;P&gt;     654321               702   ---&amp;gt; move to itab&lt;/P&gt;&lt;P&gt;     654321               701   ---&amp;gt; move to itab&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here is my code btw.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: l_sernr like t_ztm0019_tmp-sernr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*get all records from table ztm0019 and append to itab.&lt;/P&gt;&lt;P&gt;  SELECT * FROM ztm0019&lt;/P&gt;&lt;P&gt;  APPENDING TABLE t_ztm0019.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*populate itab t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;  t_ztm0019_tmp[] = t_ztm0019[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*sort itab according to latest date and time grouped by serial no.&lt;/P&gt;&lt;P&gt;  SORT t_ztm0019_tmp BY sernr datum DESCENDING uzeit DESCENDING.&lt;/P&gt;&lt;P&gt;  SORT t_ztm0019 BY sernr datum DESCENDING uzeit DESCENDING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  LOOP AT t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    AT NEW sernr.&lt;/P&gt;&lt;P&gt;      l_sernr = t_ztm0019_tmp-sernr.&lt;/P&gt;&lt;P&gt;      READ TABLE t_ztm0019_tmp INDEX sy-tabix.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;if condition is true, move to itab t_ztm_acc_variance.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;      IF t_ztm0019_tmp-bwart EQ '702'&lt;/P&gt;&lt;P&gt;      OR t_ztm0019_tmp-bwart EQ '708'&lt;/P&gt;&lt;P&gt;      OR t_ztm0019_tmp-bwart EQ '712'&lt;/P&gt;&lt;P&gt;      OR t_ztm0019_tmp-bwart EQ '718'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        LOOP AT t_ztm0019 WHERE sernr = t_ztm0019_tmp-sernr&lt;/P&gt;&lt;P&gt;                            and bwart = t_ztm0019_tmp-bwart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          APPEND t_ztm0019 TO t_ztm_acc_variance.&lt;/P&gt;&lt;P&gt;          CLEAR  t_ztm0019.&lt;/P&gt;&lt;P&gt;          DELETE t_ztm0019.&lt;/P&gt;&lt;P&gt;        ENDLOOP.&lt;/P&gt;&lt;P&gt;*if condition is false, check for new sernr.&lt;/P&gt;&lt;P&gt;      ELSE.&lt;/P&gt;&lt;P&gt;       READ TABLE t_ztm0019_tmp INDEX sy-tabix.&lt;/P&gt;&lt;P&gt;       delete t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       LOOP AT t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;        IF t_ztm0019_tmp-sernr = l_sernr.&lt;/P&gt;&lt;P&gt;          APPEND t_ztm0019_tmp TO t_ztm_acc_variance.&lt;/P&gt;&lt;P&gt;          CLEAR t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;          delete t_ztm0019_tmp.&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;&lt;/P&gt;&lt;P&gt;      ENDIF.&lt;/P&gt;&lt;P&gt;      CONTINUE.      " Go for next SERNR&lt;/P&gt;&lt;P&gt;    ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*inserts or updates records in db table ztm_acc_variance based on itab&lt;/P&gt;&lt;P&gt;  MODIFY ztm_acc_variance FROM TABLE t_ztm_acc_variance.&lt;/P&gt;&lt;P&gt;*insert or update unaccounted variances from itab&lt;/P&gt;&lt;P&gt;  MODIFY ztm0019 FROM TABLE t_ztm0019.&lt;/P&gt;&lt;P&gt;*deletes records from db table ztm0019 based on matching entries in itab&lt;/P&gt;&lt;P&gt;  DELETE ztm0019 FROM TABLE t_ztm_acc_variance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 06 Mar 2006 09:47:05 GMT</pubDate>
    <dc:creator>aris_hidalgo</dc:creator>
    <dc:date>2006-03-06T09:47:05Z</dc:date>
    <item>
      <title>please check my code...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264283#M148622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here is what my code does: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;after appending to itab, it loops through itab and checks the first record of every instance of a new sernr. So when the sernr satisfies the IF conditon, it now move those records through another itab. the example below satisfies the condition since it's first record satisfies the IF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      sernr             bwart&lt;/P&gt;&lt;P&gt;      123456             702&lt;/P&gt;&lt;P&gt;      123456             701&lt;/P&gt;&lt;P&gt;      123456             711&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but my problem is this, if it loops through another sernr where its first record does not satisfy the condition like the example below it must ignore the first record and the following records of the same sernr must be moved.&lt;/P&gt;&lt;P&gt;I edited my code and it works but here is the catch, when I use the same test data it NOW INSERTS THE FIRST RECORD WHEN IT SHOULDNT. Help would really be appreciated and comments too. Thanks you guys!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      sernr               bwart&lt;/P&gt;&lt;P&gt;     654321               701   --&amp;gt; ignore/delete&lt;/P&gt;&lt;P&gt;     654321               702   ---&amp;gt; move to itab&lt;/P&gt;&lt;P&gt;     654321               701   ---&amp;gt; move to itab&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here is my code btw.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: l_sernr like t_ztm0019_tmp-sernr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*get all records from table ztm0019 and append to itab.&lt;/P&gt;&lt;P&gt;  SELECT * FROM ztm0019&lt;/P&gt;&lt;P&gt;  APPENDING TABLE t_ztm0019.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*populate itab t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;  t_ztm0019_tmp[] = t_ztm0019[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*sort itab according to latest date and time grouped by serial no.&lt;/P&gt;&lt;P&gt;  SORT t_ztm0019_tmp BY sernr datum DESCENDING uzeit DESCENDING.&lt;/P&gt;&lt;P&gt;  SORT t_ztm0019 BY sernr datum DESCENDING uzeit DESCENDING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  LOOP AT t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    AT NEW sernr.&lt;/P&gt;&lt;P&gt;      l_sernr = t_ztm0019_tmp-sernr.&lt;/P&gt;&lt;P&gt;      READ TABLE t_ztm0019_tmp INDEX sy-tabix.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;if condition is true, move to itab t_ztm_acc_variance.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;      IF t_ztm0019_tmp-bwart EQ '702'&lt;/P&gt;&lt;P&gt;      OR t_ztm0019_tmp-bwart EQ '708'&lt;/P&gt;&lt;P&gt;      OR t_ztm0019_tmp-bwart EQ '712'&lt;/P&gt;&lt;P&gt;      OR t_ztm0019_tmp-bwart EQ '718'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;        LOOP AT t_ztm0019 WHERE sernr = t_ztm0019_tmp-sernr&lt;/P&gt;&lt;P&gt;                            and bwart = t_ztm0019_tmp-bwart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          APPEND t_ztm0019 TO t_ztm_acc_variance.&lt;/P&gt;&lt;P&gt;          CLEAR  t_ztm0019.&lt;/P&gt;&lt;P&gt;          DELETE t_ztm0019.&lt;/P&gt;&lt;P&gt;        ENDLOOP.&lt;/P&gt;&lt;P&gt;*if condition is false, check for new sernr.&lt;/P&gt;&lt;P&gt;      ELSE.&lt;/P&gt;&lt;P&gt;       READ TABLE t_ztm0019_tmp INDEX sy-tabix.&lt;/P&gt;&lt;P&gt;       delete t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       LOOP AT t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;        IF t_ztm0019_tmp-sernr = l_sernr.&lt;/P&gt;&lt;P&gt;          APPEND t_ztm0019_tmp TO t_ztm_acc_variance.&lt;/P&gt;&lt;P&gt;          CLEAR t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;          delete t_ztm0019_tmp.&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;&lt;/P&gt;&lt;P&gt;      ENDIF.&lt;/P&gt;&lt;P&gt;      CONTINUE.      " Go for next SERNR&lt;/P&gt;&lt;P&gt;    ENDAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*inserts or updates records in db table ztm_acc_variance based on itab&lt;/P&gt;&lt;P&gt;  MODIFY ztm_acc_variance FROM TABLE t_ztm_acc_variance.&lt;/P&gt;&lt;P&gt;*insert or update unaccounted variances from itab&lt;/P&gt;&lt;P&gt;  MODIFY ztm0019 FROM TABLE t_ztm0019.&lt;/P&gt;&lt;P&gt;*deletes records from db table ztm0019 based on matching entries in itab&lt;/P&gt;&lt;P&gt;  DELETE ztm0019 FROM TABLE t_ztm_acc_variance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 09:47:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264283#M148622</guid>
      <dc:creator>aris_hidalgo</dc:creator>
      <dc:date>2006-03-06T09:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: please check my code...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264284#M148623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Use sort and then use DELETE ADJACENT DUPLICATES after sort. This will be helpful.&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;vinod&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 10:13:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264284#M148623</guid>
      <dc:creator>vinod_gunaware2</dc:creator>
      <dc:date>2006-03-06T10:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: please check my code...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264285#M148624</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;READ TABLE t_ztm0019_tmp INDEX sy-tabix.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;if condition is true, move to itab t_ztm_acc_variance.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;IF t_ztm0019_tmp-bwart EQ '702'&lt;/P&gt;&lt;P&gt;OR t_ztm0019_tmp-bwart EQ '708'&lt;/P&gt;&lt;P&gt;OR t_ztm0019_tmp-bwart EQ '712'&lt;/P&gt;&lt;P&gt;OR t_ztm0019_tmp-bwart EQ '718'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT t_ztm0019 WHERE sernr = t_ztm0019_tmp-sernr&lt;/P&gt;&lt;P&gt;and bwart = t_ztm0019_tmp-bwart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND t_ztm0019 TO t_ztm_acc_variance.&lt;/P&gt;&lt;P&gt;CLEAR t_ztm0019.&lt;/P&gt;&lt;P&gt;DELETE t_ztm0019.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;*if condition is false, check for new sernr.&lt;/P&gt;&lt;P&gt;ELSE.&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;*No separate Read needded here.The foolowing will delete the current record if the condition not satisfied&lt;/P&gt;&lt;P&gt;delete t_ztm0019_tmp where sernr = t_ztm0019_tmp-sernr&lt;/P&gt;&lt;P&gt;bwart = t_ztm0019_tmp-bwart &lt;/P&gt;&lt;P&gt;uzeit = t_ztm0019-uzeit.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;LOOP AT t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;IF t_ztm0019_tmp-sernr = l_sernr.&lt;/P&gt;&lt;P&gt;APPEND t_ztm0019_tmp TO t_ztm_acc_variance.&lt;/P&gt;&lt;P&gt;CLEAR t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;delete t_ztm0019_tmp.&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;&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;Message was edited by: Jayanthi Jayaraman&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 10:15:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264285#M148624</guid>
      <dc:creator>jayanthi_jayaraman</dc:creator>
      <dc:date>2006-03-06T10:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: please check my code...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264286#M148625</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ELSE.&lt;/P&gt;&lt;P&gt;READ TABLE t_ztm0019_tmp INDEX sy-tabix.&lt;/P&gt;&lt;P&gt;delete adjacent duplicate from  t_ztm0019_tmp comparing sernr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;IF t_ztm0019_tmp-sernr = l_sernr.&lt;/P&gt;&lt;P&gt;APPEND t_ztm0019_tmp TO t_ztm_acc_variance.&lt;/P&gt;&lt;P&gt;CLEAR t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;delete t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 10:21:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264286#M148625</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-06T10:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: please check my code...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264287#M148626</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi viray,&lt;/P&gt;&lt;P&gt;  if you want to do so..&lt;/P&gt;&lt;P&gt; after AT NEW sernr..&lt;/P&gt;&lt;P&gt; the bwart field wont be available...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT * FROM ztm0019
APPENDING TABLE t_ztm0019.

*populate itab t_ztm0019_tmp.
t_ztm0019_tmp[] = t_ztm0019[].

*sort itab according to latest date and time grouped by serial no.
SORT t_ztm0019_tmp BY sernr datum DESCENDING uzeit DESCENDING.
SORT t_ztm0019 BY sernr datum DESCENDING uzeit DESCENDING.
data : cnt type i, flag type i.

LOOP AT t_ztm0019_tmp.


ON CHANGE OF sernr.
l_sernr = t_ztm0019_tmp-sernr.
IF t_ztm0019_tmp-bwart EQ '702'
 OR t_ztm0019_tmp-bwart EQ '708'
 OR t_ztm0019_tmp-bwart EQ '712'
 OR t_ztm0019_tmp-bwart EQ '718'.
flag = 1.
else.
 flag = 0.
endif.
ENDON.
*condition matches for the first record itself..
&amp;lt;b&amp;gt;if flag = 1.
*move the single record.
 MOVE t_ztm0019_tmp TO t_ztm_acc_variance.
 APPEND t_ztm_acc_variance.
 FLAG = 0.
else.
 loop at t_ztm0019 where sernr = t_ztm0019_tmp-sernr.
  if  cnt eq 1.
   move t_ztm0019 to t_ztm_acc_variance.
   append t_ztm_acc_variance.
  endif.
   cnt = 1.
  endif.
endloop.&amp;lt;/b&amp;gt;
cnt = 0.
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then continue your logic..   &lt;/P&gt;&lt;P&gt;this might work..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;satesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 10:23:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264287#M148626</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-06T10:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: please check my code...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264288#M148627</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've tried to simplify your prog:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT t_ztm0019 ASSIGNING &amp;lt;f&amp;gt;.

  CLEAR del.

  AT NEW sernr.
    IF NOT &amp;lt;f&amp;gt;-bwart  IN s_bwart.
      del = 'X'.
    ENDIF.
  ENDAT.

  IF del = 'X'.
    DELETE  t_ztm0019 INDEX sy-tabix.
  ENDIF.

ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Andreas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 10:23:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264288#M148627</guid>
      <dc:creator>andreas_mann3</dc:creator>
      <dc:date>2006-03-06T10:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: please check my code...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264289#M148628</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI viraylab&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: l_sernr like t_ztm0019_tmp-sernr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*get all records from table ztm0019 and append to itab.&lt;/P&gt;&lt;P&gt;SELECT * FROM ztm0019&lt;/P&gt;&lt;P&gt;APPENDING TABLE t_ztm0019.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*populate itab t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;t_ztm0019_tmp[] = t_ztm0019[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*sort itab according to latest date and time grouped by serial no.&lt;/P&gt;&lt;P&gt;SORT t_ztm0019_tmp BY sernr datum DESCENDING uzeit DESCENDING.&lt;/P&gt;&lt;P&gt;SORT t_ztm0019 BY sernr datum DESCENDING uzeit DESCENDING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT t_ztm0019_tmp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AT NEW sernr.&lt;/P&gt;&lt;P&gt;l_sernr = t_ztm0019_tmp-sernr.&lt;/P&gt;&lt;P&gt;IF t_ztm0019_tmp-bwart EQ '702'&lt;/P&gt;&lt;P&gt;OR t_ztm0019_tmp-bwart EQ '708'&lt;/P&gt;&lt;P&gt;OR t_ztm0019_tmp-bwart EQ '712'&lt;/P&gt;&lt;P&gt;OR t_ztm0019_tmp-bwart EQ '718'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT t_ztm0019 WHERE sernr = t_ztm0019_tmp-sernr&lt;/P&gt;&lt;P&gt;and bwart = t_ztm0019_tmp-bwart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND t_ztm0019 TO t_ztm_acc_variance.&lt;/P&gt;&lt;P&gt;CLEAR t_ztm0019.&lt;/P&gt;&lt;P&gt;DELETE t_ztm0019.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ELSE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;delete t_ztm0019 where index = sy-tabix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT t_ztm0019 where sernr eq t_ztm0019_tmp-sernr and bwart eq t_ztm0019_tmp-bwart.&lt;/P&gt;&lt;P&gt;APPEND t_ztm0019 TO t_ztm_acc_variance.&lt;/P&gt;&lt;P&gt;CLEAR t_ztm0019.&lt;/P&gt;&lt;P&gt;delete t_ztm0019.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;kishore&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 10:29:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264289#M148628</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-06T10:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: please check my code...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264290#M148629</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Viraylab,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As u have indicated when second set of records come in as per ur logic it enter into else condition and deletes the first record. Then it moves the records into t_ztm_acc_variance table and deletes lines from t_ztm0019_tmp. However u also need to delete recordds from t_ztm0019 table as this is the source used for inserting records into ztm0019.&lt;/P&gt;&lt;P&gt;MODIFY ztm0019 FROM TABLE t_ztm0019.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Abhijit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 10:57:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264290#M148629</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-06T10:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: please check my code...</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264291#M148630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Viray,&lt;/P&gt;&lt;P&gt; A small change in the previous code..&lt;/P&gt;&lt;P&gt; since i found it a little wrong.&lt;/P&gt;&lt;P&gt; hop this one works..&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; 
SELECT * FROM ztm0019 INTO TABLE t_ztm0019.

*populate itab t_ztm0019_tmp.
t_ztm0019_tmp[] = t_ztm0019[].

*sort itab according to latest date and time grouped by serial no.
SORT t_ztm0019_tmp BY sernr .
SORT t_ztm0019 BY sernr .
data : cnt type i, flag type i.

LOOP AT t_ztm0019_tmp.


ON CHANGE OF t_ztm0019_tmp-sernr.
*l_sernr = t_ztm0019_tmp-sernr.
IF t_ztm0019_tmp-bwart EQ '702'
 OR t_ztm0019_tmp-bwart EQ '708'
 OR t_ztm0019_tmp-bwart EQ '712'
 OR t_ztm0019_tmp-bwart EQ '718'.
flag = 1.
else.
 flag = 0.
endif.
ENDON.
*condition matches for the first record itself..
if flag = 1.
*move the single record.
 MOVE t_ztm0019_tmp TO t_ztm_acc_variance.
 APPEND t_ztm_acc_variance.
 FLAG = 0.
else.
 loop at t_ztm0019 where sernr = t_ztm0019_tmp-sernr.
  if  cnt eq 1.
   move t_ztm0019 to t_ztm_acc_variance.
   append t_ztm_acc_variance.
  endif.
   cnt = 1.
 endloop.
  endif.

cnt = 0.
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;satesh&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Mar 2006 11:50:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-check-my-code/m-p/1264291#M148630</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-03-06T11:50:30Z</dc:date>
    </item>
  </channel>
</rss>

