<?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: Looping at internal table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513285#M568439</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alvaro, thanks for the prompt response. however i am at the basic level of abap and could not understand much of the field symbol logic that you have posted. could you please write the same using the table names that I have given.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 Jul 2007 20:22:02 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-07-06T20:22:02Z</dc:date>
    <item>
      <title>Looping at internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513283#M568437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I work on SAP BW and need guidance on the functionality from the below code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;l_s_datapak_line[] = datapak[].&lt;/P&gt;&lt;P&gt;    l_s_datapak[] = datapak[].&lt;/P&gt;&lt;P&gt;    sort l_s_datapak_line by pernr endda descending.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; loop at l_s_datapak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   read table l_s_datapak_line with key pernr = l_s_datapak-pernr&lt;/P&gt;&lt;P&gt;   endda = '99991231'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;   if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;pernr = l_s_datapak_line-pernr.&lt;/P&gt;&lt;P&gt;        curr_compcode = l_s_datapak_line-bukrs.&lt;/P&gt;&lt;P&gt;        curr_job = l_s_datapak_line-stell.&lt;/P&gt;&lt;P&gt;        curr_mastcctr = l_s_datapak_line-kostl.&lt;/P&gt;&lt;P&gt;        curr_orgunit = l_s_datapak_line-orgeh.&lt;/P&gt;&lt;P&gt;        curr_persarea = l_s_datapak_line-werks.&lt;/P&gt;&lt;P&gt;        curr_perssubarea = l_s_datapak_line-BTRTL.&lt;/P&gt;&lt;P&gt;        curr_position = l_s_datapak_line-plans.&lt;/P&gt;&lt;P&gt;        curr_chief = l_s_datapak_line-zzchiefpernr.&lt;/P&gt;&lt;P&gt;        curr_supervisor = l_s_datapak_line-zzsupervisor.&lt;/P&gt;&lt;P&gt;        modify i_curr index i_index.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;       exit.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;      endif.&lt;/P&gt;&lt;P&gt;    endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the above code, I want the loop to run only once for each pernr. If there are 10 records in l_s_datapak with pernr = 100, then the loop would run 100 times although there would be only one record in l_s_datapak_line with endda = '99991231'. I want the loop to run only once , assign the values and then l_s_datapak-pernr should become 101. How do I do it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help is highly appreciated and thanks for the help in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2007 19:55:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513283#M568437</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-06T19:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Looping at internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513284#M568438</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;PRE&gt;&lt;CODE&gt;
  LOOP AT T_NPEDI ASSIGNING &amp;lt;NPEDI&amp;gt;.
    IF W_NPEDI NE &amp;lt;NPEDI&amp;gt;-NPEDI.
      W_NPEDI = &amp;lt;NPEDI&amp;gt;-NPEDI.
    ELSE.
      CONTINUE.
    ENDIF.
*Do logic....
ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greetings,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Blag.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2007 20:08:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513284#M568438</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-06T20:08:19Z</dc:date>
    </item>
    <item>
      <title>Re: Looping at internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513285#M568439</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alvaro, thanks for the prompt response. however i am at the basic level of abap and could not understand much of the field symbol logic that you have posted. could you please write the same using the table names that I have given.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2007 20:22:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513285#M568439</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-06T20:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: Looping at internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513286#M568440</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;Use Control Break statements i.e. AT NEW....ENDAT as shown below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;l_s_datapak_line[] = datapak[].&lt;/P&gt;&lt;P&gt;l_s_datapak[] = datapak[].&lt;/P&gt;&lt;P&gt;sort l_s_datapak_line by pernr endda descending.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at l_s_datapak.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;AT NEW pernr.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;read table l_s_datapak_line with key pernr = l_s_datapak-pernr&lt;/P&gt;&lt;P&gt;endda = '99991231'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;pernr = l_s_datapak_line-pernr.&lt;/P&gt;&lt;P&gt;curr_compcode = l_s_datapak_line-bukrs.&lt;/P&gt;&lt;P&gt;curr_job = l_s_datapak_line-stell.&lt;/P&gt;&lt;P&gt;curr_mastcctr = l_s_datapak_line-kostl.&lt;/P&gt;&lt;P&gt;curr_orgunit = l_s_datapak_line-orgeh.&lt;/P&gt;&lt;P&gt;curr_persarea = l_s_datapak_line-werks.&lt;/P&gt;&lt;P&gt;curr_perssubarea = l_s_datapak_line-BTRTL.&lt;/P&gt;&lt;P&gt;curr_position = l_s_datapak_line-plans.&lt;/P&gt;&lt;P&gt;curr_chief = l_s_datapak_line-zzchiefpernr.&lt;/P&gt;&lt;P&gt;curr_supervisor = l_s_datapak_line-zzsupervisor.&lt;/P&gt;&lt;P&gt;modify i_curr index i_index.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;exit.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;ENDAT.&amp;lt;/b&amp;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;Reward points if the answer is helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mukul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2007 20:22:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513286#M568440</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-06T20:22:45Z</dc:date>
    </item>
    <item>
      <title>Re: Looping at internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513287#M568441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure -:)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
l_s_datapak_line[] = datapak[].
l_s_datapak[] = datapak[].
sort l_s_datapak_line by pernr endda descending.

loop at l_s_datapak.

*----ADD THIS LOGIC----*
if w_pernr ne l_s_datapak-pernr.
w_pernr = l_s_datapak-pernr.
else.
continue.
endif.
*----ADD THIS LOGIC----*

read table l_s_datapak_line with key pernr = l_s_datapak-pernr
endda = '99991231'.

if sy-subrc = 0.
pernr = l_s_datapak_line-pernr.
curr_compcode = l_s_datapak_line-bukrs.
curr_job = l_s_datapak_line-stell.
curr_mastcctr = l_s_datapak_line-kostl.
curr_orgunit = l_s_datapak_line-orgeh.
curr_persarea = l_s_datapak_line-werks.
curr_perssubarea = l_s_datapak_line-BTRTL.
curr_position = l_s_datapak_line-plans.
curr_chief = l_s_datapak_line-zzchiefpernr.
curr_supervisor = l_s_datapak_line-zzsupervisor.
modify i_curr index i_index.
* exit.
endif.
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Done -;)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Greetings,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Blag.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2007 20:26:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513287#M568441</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-06T20:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Looping at internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513288#M568442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not sure I understood the requirement here. Both l_s_datapak_line and l_s_datapak have the same records (since both are filled from datapak). If the purpose is to get the current employee record out of datapak, why don't you simply do this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;l_s_datapak[] = datapak[].&lt;/P&gt;&lt;P&gt;SORT l_s_datapak BY pernr endda DESCENDING.&lt;/P&gt;&lt;P&gt;DELETE ADJACENT DUPLICATES FROM l_s_datapak COMPARING pernr.&lt;/P&gt;&lt;P&gt;*-- Now l_s_datapak has only unique pernr records with only the record that has &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  the greatest end date. But we are interested only in those PERNR records that &lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  have an end date of '99991231'.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;LOOP AT l_s_datapak WHERE endda = '99991231'.&lt;/P&gt;&lt;P&gt;pernr = l_s_datapak-pernr.&lt;/P&gt;&lt;P&gt;curr_compcode = l_s_datapak-bukrs.&lt;/P&gt;&lt;P&gt;curr_job = l_s_datapak-stell.&lt;/P&gt;&lt;P&gt;curr_mastcctr = l_s_datapak-kostl.&lt;/P&gt;&lt;P&gt;curr_orgunit = l_s_datapak-orgeh.&lt;/P&gt;&lt;P&gt;curr_persarea = l_s_datapak-werks.&lt;/P&gt;&lt;P&gt;curr_perssubarea = l_s_datapak-BTRTL.&lt;/P&gt;&lt;P&gt;curr_position = l_s_datapak-plans.&lt;/P&gt;&lt;P&gt;curr_chief = l_s_datapak-zzchiefpernr.&lt;/P&gt;&lt;P&gt;curr_supervisor = l_s_datapak-zzsupervisor.&lt;/P&gt;&lt;P&gt;modify i_curr index i_index.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: &lt;/P&gt;&lt;P&gt;        Srinivas Adavi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2007 20:32:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513288#M568442</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-06T20:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Looping at internal table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513289#M568443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Srinivas, thanks a lot, my issue is almost resolved. I am not able to test it as the system is down, but looking at the code i am sure that it will work. thanks !!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Points awarded too !!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2007 21:22:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/looping-at-internal-table/m-p/2513289#M568443</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-07-06T21:22:26Z</dc:date>
    </item>
  </channel>
</rss>

