<?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: How to Avoid Nested Loops in Module Pool Program? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-nested-loops-in-module-pool-program/m-p/12233204#M1984670</link>
    <description>&lt;P&gt;Hi Frederic, thanks for your suggestion. I will try to use that in my code.&lt;/P&gt;&lt;P&gt;Hi Matthew, thanks for pointing out the error in the title. That was a mistake on my part&lt;/P&gt;</description>
    <pubDate>Thu, 03 Sep 2020 01:35:28 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2020-09-03T01:35:28Z</dc:date>
    <item>
      <title>How to Avoid Nested Loops in Module Pool Program?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-nested-loops-in-module-pool-program/m-p/12233200#M1984666</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
  &lt;P&gt;I am in the midst of developing a module pool program that uploads data into a z table. &lt;/P&gt;
  &lt;P&gt;The issue is that because of the many checks required (e.g. checking that the fields are not empty, checking which radiobutton has been selected), I have implemented several nested if else statements.&lt;/P&gt;
  &lt;P&gt;Essentially, the flow of logic is:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;when p_manual is selected...
- if all the input fields have no value --&amp;gt; message user
- elseif all the input fields have value --&amp;gt; select data
---if selection successful, display data
---elseif selection not successful, ask user input data

when p_excel is selected...
- if the filepath field has no value --&amp;gt; message user
- elseif the filepath field has a value, then...
---if the user chooses to perform a test upload --&amp;gt; upload the data + display uploaded data back to user
---if the user chooses to upload the file --&amp;gt; upload the data + insert data into z table
&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Code is below:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;*If user chooses to manually upload data
IF save_ok = 'X' and p_manual = 'X'. 
  IF field IS INITIAL. "check if field has no value
     "message user to fill in all fields
  ELSE. "if field has value
     "select data from zTable to display to user
    IF selected data is successful.
       "show the data in SM30
    ELSE. 
      "send user to another screen to manually fill in data
    ENDIF.

*if user chooses to upload data from Excel
ELSEIF save_ok = 'X' and p_excel = 'X'.
  IF filepath IS INITIAL.
     "message user to select a filepath
  ELSE.
     IF user wants to perform a test upload.
       "upload the data
        "call another screen to display the data
     ELSEIF user wants to upload the data directly into the z table.
        "upload the data
        "insert the data into table
     ENDIF.
  ENDIF.


ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Does anyone have any suggestions on how to improve this (i.e. without using nested IF...ELSE statements)? &lt;/P&gt;
  &lt;P&gt;Thank you,&lt;BR /&gt;Yi Lin&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 10:15:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-nested-loops-in-module-pool-program/m-p/12233200#M1984666</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-09-02T10:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to Avoid Nested Loops in Module Pool Program?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-nested-loops-in-module-pool-program/m-p/12233201#M1984667</link>
      <description>&lt;P&gt;Maybe you have to change totaly your mind and play with method &amp;amp; exceptions.&lt;/P&gt;&lt;P&gt;The part of your  code is not enough to be sure it is the good way to do it, but it could be something like that&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;try.
  check is_field_populated( field... ) eq abap_true. 
  check is_selected_data_success( data ) eq abap_true.

  catch cx_application into data(lo_excption).
endtry.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;for the part of the save data type, you have to split it. Try to folloy the Clean code and follow the rule : A method do one thing, and do it well &lt;/P&gt;&lt;P&gt;here, you do a lot of control, and it is a big melting of responsibility &lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 10:32:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-nested-loops-in-module-pool-program/m-p/12233201#M1984667</guid>
      <dc:creator>FredericGirod</dc:creator>
      <dc:date>2020-09-02T10:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to Avoid Nested Loops in Module Pool Program?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-nested-loops-in-module-pool-program/m-p/12233202#M1984668</link>
      <description>&lt;P&gt;"How to Avoid Nested Loops in Module Pool Program?"&lt;/P&gt;&lt;P&gt;I see no loop.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 10:37:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-nested-loops-in-module-pool-program/m-p/12233202#M1984668</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2020-09-02T10:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to Avoid Nested Loops in Module Pool Program?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-nested-loops-in-module-pool-program/m-p/12233203#M1984669</link>
      <description>&lt;P&gt;Hi, To validate user input fields use the below &lt;/P&gt;&lt;P&gt;FIELD Field_Name MODULE validate_field_name concept.&lt;/P&gt;&lt;P&gt;You can try with chain end chain if there is more than 1 field to be validated&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 11:11:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-nested-loops-in-module-pool-program/m-p/12233203#M1984669</guid>
      <dc:creator>former_member24871</dc:creator>
      <dc:date>2020-09-02T11:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to Avoid Nested Loops in Module Pool Program?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-nested-loops-in-module-pool-program/m-p/12233204#M1984670</link>
      <description>&lt;P&gt;Hi Frederic, thanks for your suggestion. I will try to use that in my code.&lt;/P&gt;&lt;P&gt;Hi Matthew, thanks for pointing out the error in the title. That was a mistake on my part&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 01:35:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-avoid-nested-loops-in-module-pool-program/m-p/12233204#M1984670</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2020-09-03T01:35:28Z</dc:date>
    </item>
  </channel>
</rss>

