<?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: Increment variable dynamically in LOOP in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273796#M1217366</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;USE:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;PERFORM: sy-tabix OF sub1 sub2 sub3.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;as the value of sy-tabix increases value subroutine will be executed.&lt;/P&gt;&lt;P&gt;Ex:&lt;/P&gt;&lt;P&gt;When SY-tabix = 1---&amp;gt;SUB1&lt;/P&gt;&lt;P&gt;When 2-----&amp;gt;SUB2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF t_second,
var1 TYPE c,
var2 TYPE c,
var3 TYPE c,
END OF t_second.

DATA : gt_second TYPE TABLE OF t_second,
wa_second TYPE t_second,
wa_first(20) TYPE c,
gt_first TYPE TABLE OF t_second.

wa_first = 'TEST'.
append wa_first to gt_first.

wa_first = 'TEST'.
append wa_first to gt_first.

wa_first = 'TEST'.
append wa_first to gt_first.
LOOP AT gt_first INTO wa_first.

  PERFORM: sy-tabix OF sub1 sub2 sub3.

*   MOVE: wa_first TO wa_second-var1.  " &amp;lt;---- in the 2nd loop i want to make this var1 to var2 and so on.

  APPEND wa_first TO gt_second.
  CLEAR wa_first.
ENDLOOP.

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  sub1
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub1.

  MOVE: wa_first TO wa_second-var1.
ENDFORM.                                                    "sub1

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  sub2
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub2.
  MOVE: wa_first TO wa_second-var2.
ENDFORM.                                                    "sub2

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  sub3
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub3.
  MOVE: wa_first TO wa_second-var3.
ENDFORM.                                                    "sub3&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;Gurpreet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 01 Mar 2009 08:16:33 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-03-01T08:16:33Z</dc:date>
    <item>
      <title>Increment variable dynamically in LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273795#M1217365</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 a situation where I have to loop at a table and fill an internal table while incrementing the variable name of the internal table at the same time. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For instance I have three variables: var1, var2 and var3. In the first loop I want to assign the value to Var1, in the 2nd loop to var2 and in the third loop to var3 and so on. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;types: Begin of t_second&lt;/P&gt;&lt;P&gt;  var1        TYPE C,&lt;/P&gt;&lt;P&gt;  var2        TYPE C,&lt;/P&gt;&lt;P&gt;  var3        TYPE C,&lt;/P&gt;&lt;P&gt;end of t_second.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data : gt_second type table of t_second,&lt;/P&gt;&lt;P&gt;       wa_second type t_second.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP at gt_first into wa_first.&lt;/P&gt;&lt;P&gt;    MOVE: wa_first-var TO wa_second-var1,  &amp;lt;---- in the 2nd loop I want to make this var1 to var2 and so on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    APPEND wa_first TO gt_second&lt;/P&gt;&lt;P&gt;    CLEAR wa_first&lt;/P&gt;&lt;P&gt;  ENDLOOP. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Will it be possible to achieve this with ABAP?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: mark mark on Mar 1, 2009 8:49 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 01 Mar 2009 07:48:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273795#M1217365</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-01T07:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Increment variable dynamically in LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273796#M1217366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;USE:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;PERFORM: sy-tabix OF sub1 sub2 sub3.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;as the value of sy-tabix increases value subroutine will be executed.&lt;/P&gt;&lt;P&gt;Ex:&lt;/P&gt;&lt;P&gt;When SY-tabix = 1---&amp;gt;SUB1&lt;/P&gt;&lt;P&gt;When 2-----&amp;gt;SUB2&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF t_second,
var1 TYPE c,
var2 TYPE c,
var3 TYPE c,
END OF t_second.

DATA : gt_second TYPE TABLE OF t_second,
wa_second TYPE t_second,
wa_first(20) TYPE c,
gt_first TYPE TABLE OF t_second.

wa_first = 'TEST'.
append wa_first to gt_first.

wa_first = 'TEST'.
append wa_first to gt_first.

wa_first = 'TEST'.
append wa_first to gt_first.
LOOP AT gt_first INTO wa_first.

  PERFORM: sy-tabix OF sub1 sub2 sub3.

*   MOVE: wa_first TO wa_second-var1.  " &amp;lt;---- in the 2nd loop i want to make this var1 to var2 and so on.

  APPEND wa_first TO gt_second.
  CLEAR wa_first.
ENDLOOP.

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  sub1
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub1.

  MOVE: wa_first TO wa_second-var1.
ENDFORM.                                                    "sub1

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  sub2
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub2.
  MOVE: wa_first TO wa_second-var2.
ENDFORM.                                                    "sub2

*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  sub3
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM sub3.
  MOVE: wa_first TO wa_second-var3.
ENDFORM.                                                    "sub3&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;Gurpreet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 01 Mar 2009 08:16:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273796#M1217366</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-01T08:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: Increment variable dynamically in LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273797#M1217367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you can use case endcase statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP at gt_first into wa_first.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CASE sy-tabix.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when 1.&lt;/P&gt;&lt;P&gt;MOVE: wa_first-var TO wa_second-var1.&lt;/P&gt;&lt;P&gt;when 2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MOVE: wa_first-var TO wa_second-var2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when 3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MOVE: wa_first-var TO wa_second-var3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when others.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;message for no variable to transfer data&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;endcase.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;APPEND wa_first TO gt_second.&lt;/P&gt;&lt;P&gt;CLEAR wa_first.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 01 Mar 2009 08:36:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273797#M1217367</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-01T08:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: Increment variable dynamically in LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273798#M1217368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;use field symbols&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Aug 2009 19:44:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273798#M1217368</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-11T19:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Increment variable dynamically in LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273799#M1217369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;  I understood your Requirement. I am giving you one dynamic Solution. This is applicable in all cases. Like Uploading data from Excel, or Building Dynamic fieldcats.&lt;/P&gt;&lt;P&gt;Illustration:&lt;/P&gt;&lt;P&gt;data: Begin of wa1,&lt;/P&gt;&lt;P&gt;            var type char10,  " (take any length you want)&lt;/P&gt;&lt;P&gt;         end of wa1,&lt;/P&gt;&lt;P&gt;         itab1 like standard table of wa1.&lt;/P&gt;&lt;P&gt;data: begin of wa2,&lt;/P&gt;&lt;P&gt;             var1 type char6,&lt;/P&gt;&lt;P&gt;             var2 type char7,&lt;/P&gt;&lt;P&gt;             var3 type char8,&lt;/P&gt;&lt;P&gt;             var4 type char9,&lt;/P&gt;&lt;P&gt;             var5 type char10,&lt;/P&gt;&lt;P&gt;           end of wa2,&lt;/P&gt;&lt;P&gt;          itab2 like standard table of wa2.&lt;/P&gt;&lt;P&gt;field-symbols: &amp;lt;FS1&amp;gt; type any.&lt;/P&gt;&lt;P&gt;parameters: p_a RADIOBUTTON GROUP gr1 default 'X', " fill in diagonal&lt;/P&gt;&lt;P&gt;            p_b RADIOBUTTON GROUP gr1.  " fill in left triangle&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;start-of-selection.&lt;/P&gt;&lt;P&gt;wa1-var = 'Balaji'.      Append wa1 to itab1.&lt;/P&gt;&lt;P&gt;wa1-var = 'Balaji1'.     Append wa1 to itab1.&lt;/P&gt;&lt;P&gt;wa1-var = 'Balaji12'.    Append wa1 to itab1.&lt;/P&gt;&lt;P&gt;wa1-var = 'Balaji123'.   Append wa1 to itab1.&lt;/P&gt;&lt;P&gt;wa1-var = 'Balaji1234'.  Append wa1 to itab1.&lt;/P&gt;&lt;P&gt;loop at itab1 into wa1.&lt;/P&gt;&lt;P&gt;  assign component sy-tabix of structure wa2 to &amp;lt;FS1&amp;gt;.&lt;/P&gt;&lt;P&gt;  if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;     &amp;lt;fs1&amp;gt; = wa1-var.&lt;/P&gt;&lt;P&gt;    append wa2 to itab2.&lt;/P&gt;&lt;P&gt;    unassign &amp;lt;fs1&amp;gt;.&lt;/P&gt;&lt;P&gt;    if p_b is INITIAL.&lt;/P&gt;&lt;P&gt;      clear: wa2.&lt;/P&gt;&lt;P&gt;    endif.&lt;/P&gt;&lt;P&gt;  else.&lt;/P&gt;&lt;P&gt;    exit.&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;&lt;/P&gt;&lt;P&gt;Try this one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Balaji Peethani.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Aug 2009 23:27:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273799#M1217369</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-11T23:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: Increment variable dynamically in LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273800#M1217370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the sample code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data variable type char5.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data no type char2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data vartab type table of char5 with header line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do 5 times.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; pack sy-tabix to no.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; concatenate 'Var' no into variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; append variable to vartab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;enddo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at vartab.&lt;/P&gt;&lt;P&gt;  write: / vartab.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank,&lt;/P&gt;&lt;P&gt;Augustin.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Aug 2009 04:52:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273800#M1217370</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-12T04:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Increment variable dynamically in LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273801#M1217371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I hope you adopt one of the last three solutions.  The others are nice efforts, but not right.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Aug 2009 04:55:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273801#M1217371</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2009-08-12T04:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Increment variable dynamically in LOOP</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273802#M1217372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi mark,&lt;/P&gt;&lt;P&gt;kindly chk the followingg code , it works according  to the requirement.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
types: Begin of t_second,
var1 TYPE C,
var2 TYPE C,
var3 TYPE C,
end of t_second.

data : gt_second type table of t_second,
wa_second type t_second.

types: begin of t_first,
  var type c,
  end of t_first.

  data: gt_first type table of t_first,
        wa_first type t_first.

data: w_idx type i value 1.

do 9 times.
  wa_first-var = sy-index.
  append wa_first to gt_first.
  enddo.
LOOP at gt_first into wa_first.
  case w_idx.
    when 1.
      CLEAR wa_second.
      MOVE: wa_first-var TO wa_second-var1.
      APPEND wa_second TO gt_second.
      w_idx = 2.
     when 2.
       CLEAR wa_second.
       MOVE: wa_first-var TO wa_second-var2.
       APPEND wa_second TO gt_second.
       w_idx = 3.
      when 3.
        CLEAR wa_second.
        MOVE: wa_first-var TO wa_second-var3.
        APPEND wa_second TO gt_second.
        w_idx = 1.
  ENDCASE    .
ENDLOOP.

loop at gt_second into wa_second.
  write:/ wa_second-var1,
           wa_second-var2,
            wa_second-var3.
endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Aug 2009 06:00:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/increment-variable-dynamically-in-loop/m-p/5273802#M1217372</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-08-12T06:00:55Z</dc:date>
    </item>
  </channel>
</rss>

