<?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: Iteration returns zero in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/iteration-returns-zero/m-p/12424809#M1997496</link>
    <description>&lt;P&gt;Thank you so much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Sep 2021 15:30:07 GMT</pubDate>
    <dc:creator>CenkayArkan</dc:creator>
    <dc:date>2021-09-02T15:30:07Z</dc:date>
    <item>
      <title>Iteration returns zero</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/iteration-returns-zero/m-p/12424807#M1997494</link>
      <description>&lt;P&gt;Hi experts, &lt;/P&gt;
  &lt;P&gt;I'm facing an issue. I solved the problem but I wonder what is happening? What am I missing? I tried to calculate lcm(least common multiple) with the number range. After iteration, the result returns me zero. &lt;/P&gt;
  &lt;P&gt;When I changed it to an attribute instead of returning a parameter, it worked well. And also I tried to change my gcd method with a function, it also worked. &lt;/P&gt;
  &lt;P&gt;I just wonder what is the reason for this problem. I'm sharing my code and screen view.&lt;/P&gt;
  &lt;P&gt;I don't understand why rv_rcd parameter returns zero.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;CLASS lcl_math DEFINITION.
  PUBLIC SECTION.
    TYPES ty_range TYPE TABLE OF int4.
    METHODS gcd IMPORTING iv_val1       TYPE int4
                          iv_val2       TYPE int4
                RETURNING VALUE(rv_gcd) TYPE int4.
    METHODS findlcm IMPORTING it_range         TYPE ty_range
                    RETURNING VALUE(rv_lcm) TYPE int4.
ENDCLASS.


CLASS lcl_math IMPLEMENTATION.


  METHOD gcd.
    IF ( iv_val2 = 0 ).
      rv_gcd = iv_val1.
      WRITE : / 'RV_GCD: ' , rv_gcd.
      RETURN.
    ENDIF.
    me-&amp;gt;gcd( iv_val1 = iv_val2 iv_val2 = iv_val1 MOD iv_val2 ).
  ENDMETHOD.


  METHOD findlcm.
    DATA : lv_counter      TYPE int4 VALUE 2,
           lv_gcd TYPE int4.
    rv_lcm = it_range[ 1 ].
    WHILE lv_counter &amp;lt;= lines( it_range ).
      DATA(val) = it_range[ lv_counter ].
      TRY.
          lv_gcd = me-&amp;gt;gcd( iv_val1 = val iv_val2 = rv_lcm ).
          WRITE : / 'LV_GCD: ' , lv_gcd.
          rv_lcm = ( val * rv_lcm ) / lv_gcd.
        CATCH cx_sy_zerodivide.
      ENDTRY.
      lv_counter = lv_counter + 1.
    ENDWHILE.
  ENDMETHOD.


ENDCLASS.


START-OF-SELECTION.
  DATA(gref_math) = NEW lcl_math( ).
  gref_math-&amp;gt;findlcm(
    EXPORTING
      it_range = VALUE #( ( 10 ) ( 15 ) ( 6 ) ( 20 ) )
    RECEIVING
      rv_lcm = DATA(gv_lcm)
  ).
  ULINE.
  WRITE gv_lcm.
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1973688-gcd.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 15:05:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/iteration-returns-zero/m-p/12424807#M1997494</guid>
      <dc:creator>CenkayArkan</dc:creator>
      <dc:date>2021-09-02T15:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: Iteration returns zero</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/iteration-returns-zero/m-p/12424808#M1997495</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;METHOD gcd.
    IF ( iv_val2 = 0 ).
      rv_gcd = iv_val1.
      WRITE : / 'RV_GCD: ' , rv_gcd.
      RETURN.
    ENDIF.
    me-&amp;gt;gcd( iv_val1 = iv_val2 iv_val2 = iv_val1 MOD iv_val2 ). "&amp;lt;--- not assigned to anything
ENDMETHOD.&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;If not, you call the method again, without assigning its returning value, so the method returns zero.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 15:23:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/iteration-returns-zero/m-p/12424808#M1997495</guid>
      <dc:creator>VXLozano</dc:creator>
      <dc:date>2021-09-02T15:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: Iteration returns zero</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/iteration-returns-zero/m-p/12424809#M1997496</link>
      <description>&lt;P&gt;Thank you so much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 15:30:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/iteration-returns-zero/m-p/12424809#M1997496</guid>
      <dc:creator>CenkayArkan</dc:creator>
      <dc:date>2021-09-02T15:30:07Z</dc:date>
    </item>
  </channel>
</rss>

