<?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 Nested Counter Loop in ABAP in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-counter-loop-in-abap/m-p/12228043#M1984216</link>
    <description>&lt;P&gt;Hey everyone,&lt;/P&gt;
  &lt;P&gt;is there a simpler/better way to make a nested counter loop than this?&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;  DATA(XCOUNT) = 0.
  DATA(YCOUNT) = 0.
  DO X TIMES.
    XCOUNT = XCOUNT + 1.
    DO Y TIMES.
      YCOUNT = YCOUNT + 1.
      DO=&amp;gt;SOMETHING( X = XCOUNT Y = YCOUNT ).
    ENDDO.
    YCOUNT = 0.
  ENDDO.
  XCOUNT = 0.&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 10 Nov 2020 13:32:07 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2020-11-10T13:32:07Z</dc:date>
    <item>
      <title>Nested Counter Loop in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-counter-loop-in-abap/m-p/12228043#M1984216</link>
      <description>&lt;P&gt;Hey everyone,&lt;/P&gt;
  &lt;P&gt;is there a simpler/better way to make a nested counter loop than this?&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;  DATA(XCOUNT) = 0.
  DATA(YCOUNT) = 0.
  DO X TIMES.
    XCOUNT = XCOUNT + 1.
    DO Y TIMES.
      YCOUNT = YCOUNT + 1.
      DO=&amp;gt;SOMETHING( X = XCOUNT Y = YCOUNT ).
    ENDDO.
    YCOUNT = 0.
  ENDDO.
  XCOUNT = 0.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 13:32:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-counter-loop-in-abap/m-p/12228043#M1984216</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-11-10T13:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Counter Loop in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-counter-loop-in-abap/m-p/12228044#M1984217</link>
      <description>&lt;P&gt;Hello  Former Member &lt;/P&gt;&lt;P&gt;From SAP Help (https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abapdo.htm): &lt;I&gt;SY-INDEX always refers to the current LOOP&lt;/I&gt;&lt;/P&gt;&lt;P&gt;Which means you could do something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;  DATA(XCOUNT) = 0.
  DO X TIMES.
    XCOUNT = XCOUNT + 1.
    DO Y TIMES.
      DO=&amp;gt;SOMETHING( X = XCOUNT Y = sy-index ).
    ENDDO.
  ENDDO.
  XCOUNT = 0.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You could also store X count in the class:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DO x TIMES.
  do=&amp;gt;set_x( sy-index ).
  DO y TIMES.
    do=&amp;gt;something( y = sy-index ).
  ENDDO.
ENDDO.

METHOD something.
  WRITE: / do=&amp;gt;x.
  WRITE: / y.
ENDMETHOD.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Mateusz&lt;/P&gt;</description>
      <pubDate>Tue, 10 Nov 2020 13:40:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-counter-loop-in-abap/m-p/12228044#M1984217</guid>
      <dc:creator>MateuszAdamus</dc:creator>
      <dc:date>2020-11-10T13:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Counter Loop in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-counter-loop-in-abap/m-p/12228045#M1984218</link>
      <description>&lt;P&gt;Not fundamentally, but xcount and ycount are clearly helper variables and won't have use outside of the code you've posted, so something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA(XCOUNT) = 0.
DO XCOUNT TIMES.
  DATA(YCOUNT) = 0.
  XCOUNT = XCOUNT +1.
  DO YCOUNT TIMES.
      YCOUNT = YCOUNT + 1.
      DO=&amp;gt;SOMETHING( X = XCOUNT Y = YCOUNT ).
  ENDDO.
ENDDO.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;or&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA(XCOUNT) = 0.
DO XCOUNT TIMES.
  XCOUNT = XCOUNT + 1.
  yloop( XCOUNT ).
ENDDO.

METHOD yloop.
  DATA(YCOUNT) = 0.
  DO YCOUNT TIMES.
      YCOUNT = YCOUNT + 1.
      DO=&amp;gt;SOMETHING( I_X = I_X I_Y = YCOUNT ).
  ENDDO.
ENDMETHOD.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Nov 2020 19:15:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-counter-loop-in-abap/m-p/12228045#M1984218</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2020-11-10T19:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Counter Loop in ABAP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-counter-loop-in-abap/m-p/12228046#M1984219</link>
      <description>&lt;P&gt;Your code is so simple to understand that I don't see why you want to improve it. The only weird thing is common to many developers, is the "reset after execution" ("?count = 0"), as it's prone to errors and can be generally avoided. Instead, you should always prefer the "reset before execution" (move DATA(YCOUNT) = 0 before DO Y TIMES, and remove the 2 lines ?count = 0).&lt;/P&gt;&lt;P&gt;But if it's &lt;STRONG&gt;for the fun/NOT a productive code&lt;/STRONG&gt;, you may declare DO=&amp;gt;SOMETHING with a dummy returning parameter and do like this (I use ASSERT here, but I could use anything else, it's just to say that the result is always 1 and has no importance for the objective):&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ASSERT 1 = REDUCE i( INIT i = 1
    FOR xcount = 1 THEN xcount + 1 WHILE xcount &amp;lt;= x
    FOR ycount = 1 THEN ycount + 1 WHILE ycount &amp;lt;= y
    LET dummyresult = DO=&amp;gt;SOMETHING( X = XCOUNT Y = YCOUNT ) IN
    NEXT i = 1 ).&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;WARNING: stunt[wo]men, don't try this at home and at work!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Nov 2020 10:45:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-counter-loop-in-abap/m-p/12228046#M1984219</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-11-11T10:45:36Z</dc:date>
    </item>
  </channel>
</rss>

