<?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: ABAP Loop Strange behaviour (bug?) in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-loop-strange-behaviour-bug/m-p/12379296#M1994091</link>
    <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;maheshkumar.palavalli&lt;/SPAN&gt;, Thank you!&lt;/P&gt;&lt;P&gt;I think you're right!&lt;/P&gt;&lt;P&gt;"If the internal table is specified as the return value of a functional method, a constructor expression, or a table expression, the additions ASSIGNING and REFERENCE INTO can also be specified for LOOP (this is not the case with READ TABLE). The internal table is only available while the loop is being processed, which means that all field symbols and reference variables that point to rows in the internal table become invalid when the loop is exited."&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abaploop_at_itab_result.htm"&gt;https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abaploop_at_itab_result.htm&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 14 Mar 2021 07:22:49 GMT</pubDate>
    <dc:creator>former_member685564</dc:creator>
    <dc:date>2021-03-14T07:22:49Z</dc:date>
    <item>
      <title>ABAP Loop Strange behaviour (bug?)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-loop-strange-behaviour-bug/m-p/12379294#M1994089</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
  &lt;P&gt;When you start this code:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    TYPES tt_data TYPE STANDARD TABLE OF i WITH EMPTY KEY.
    DATA mt_data TYPE tt_data.

    METHODS: change_data,

    get_reference
      RETURNING VALUE(ro_data) TYPE REF TO lcl_app.

    METHODS print.
ENDCLASS.

CLASS lcl_app IMPLEMENTATION.

  METHOD change_data.
    LOOP AT get_reference( )-&amp;gt;mt_data ASSIGNING FIELD-SYMBOL(&amp;lt;lv_value&amp;gt;).
      &amp;lt;lv_value&amp;gt; = &amp;lt;lv_value&amp;gt; + 1.
    ENDLOOP.
  ENDMETHOD.

  METHOD get_reference.
    ro_data = me.
  ENDMETHOD.

  METHOD print.
    LOOP AT mt_data INTO DATA(lv_value).
      WRITE: / lv_value.
    ENDLOOP.
    ULINE.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATA(lo_app) = NEW lcl_app( ).
  lo_app-&amp;gt;mt_data = VALUE #( ( 1 ) ).

  lo_app-&amp;gt;change_data( ).
  lo_app-&amp;gt;print( ).&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;You will see that mt_data is not changed. Сan anyone explain why?&lt;/P&gt;
  &lt;P&gt;If you change code to this:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;  METHOD change_data.
    DATA(lo_ref) = get_reference( ).

    LOOP AT lo_ref-&amp;gt;mt_data ASSIGNING FIELD-SYMBOL(&amp;lt;lv_value&amp;gt;).
      &amp;lt;lv_value&amp;gt; = &amp;lt;lv_value&amp;gt; + 1.
    ENDLOOP.
  ENDMETHOD.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Or this:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;  METHOD change_data.
    LOOP AT CAST lcl_app( get_reference( ) )-&amp;gt;mt_data ASSIGNING FIELD-SYMBOL(&amp;lt;lv_value&amp;gt;).
      &amp;lt;lv_value&amp;gt; = &amp;lt;lv_value&amp;gt; + 1.
    ENDLOOP.
  ENDMETHOD.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Everything will be OK&lt;/P&gt;</description>
      <pubDate>Sun, 14 Mar 2021 06:06:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-loop-strange-behaviour-bug/m-p/12379294#M1994089</guid>
      <dc:creator>former_member685564</dc:creator>
      <dc:date>2021-03-14T06:06:43Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP Loop Strange behaviour (bug?)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-loop-strange-behaviour-bug/m-p/12379295#M1994090</link>
      <description>&lt;P&gt;Is your scenario the same as what sap is trying to tell in the help? Internal table only available within the loop means that it is temporary data?(Not sure if that is what they are trying to say, maybe &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt; knows something). I also observed that the field symbol is not accessed outside the loop as they mentioned unlike the loop of a normal table.&lt;/P&gt;&lt;P&gt;"If the internal table is specified as the return value of a functional method, a constructor expression, or a table expression, the additions ASSIGNING and REFERENCE INTO can also be specified for LOOP (this is not the case with READ TABLE). The internal table is only available while the loop is being processed, which means that all field symbols and reference variables that point to rows in the internal table become invalid when the loop is exited."&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abaploop_at_itab_result.htm" target="test_blank"&gt;https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abaploop_at_itab_result.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Mar 2021 06:49:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-loop-strange-behaviour-bug/m-p/12379295#M1994090</guid>
      <dc:creator>maheshpalavalli</dc:creator>
      <dc:date>2021-03-14T06:49:01Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP Loop Strange behaviour (bug?)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-loop-strange-behaviour-bug/m-p/12379296#M1994091</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;maheshkumar.palavalli&lt;/SPAN&gt;, Thank you!&lt;/P&gt;&lt;P&gt;I think you're right!&lt;/P&gt;&lt;P&gt;"If the internal table is specified as the return value of a functional method, a constructor expression, or a table expression, the additions ASSIGNING and REFERENCE INTO can also be specified for LOOP (this is not the case with READ TABLE). The internal table is only available while the loop is being processed, which means that all field symbols and reference variables that point to rows in the internal table become invalid when the loop is exited."&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abaploop_at_itab_result.htm"&gt;https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abaploop_at_itab_result.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Mar 2021 07:22:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-loop-strange-behaviour-bug/m-p/12379296#M1994091</guid>
      <dc:creator>former_member685564</dc:creator>
      <dc:date>2021-03-14T07:22:49Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP Loop Strange behaviour (bug?)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-loop-strange-behaviour-bug/m-p/12379297#M1994092</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;maheshkumar.palavalli&lt;/SPAN&gt;, I believe this too, and it's expressed more clearly in the documentation for &lt;A href="https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abaploop_at_itab.htm?file=abaploop_at_itab.htm"&gt;LOOP AT itab - Basic Form&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;If the internal table is specified as the return value or result of a functional method, a constructor expression, or a table expression, the value is persisted for the duration of the loop. Afterwards, it is no longer possible to access the internal table.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;So "the value is persisted" means that we get a copy for the loop. We can use the field-symbol inside of the loop, but it refers only to the copy...&lt;/P&gt;&lt;P&gt;(And yes, &lt;SPAN class="mention-scrubbed"&gt;sandra.rossi&lt;/SPAN&gt; knows a great many things)&lt;/P&gt;</description>
      <pubDate>Sun, 14 Mar 2021 07:30:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-loop-strange-behaviour-bug/m-p/12379297#M1994092</guid>
      <dc:creator>joltdx</dc:creator>
      <dc:date>2021-03-14T07:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP Loop Strange behaviour (bug?)</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-loop-strange-behaviour-bug/m-p/12379298#M1994093</link>
      <description>&lt;P&gt;People around here are very knowledgeable as we can see &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Mar 2021 09:05:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-loop-strange-behaviour-bug/m-p/12379298#M1994093</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2021-03-14T09:05:07Z</dc:date>
    </item>
  </channel>
</rss>

