<?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 how to write 2 loops into single loop ? in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556795#M2007238</link>
    <description>so i have created 2 internal tables and i tried to find the name of employee from first table with base salary from 2nd table and i have manually inserted data into it. so how can i write both loops into single loop. and here is the code i have written -
  &lt;BR /&gt;
  &lt;BR /&gt;
  &lt;PRE&gt;&lt;CODE&gt;TYPES : BEGIN OF s_empdetails,&lt;BR /&gt;              empid       TYPE n,&lt;BR /&gt;              fname(20)       TYPE c,&lt;BR /&gt;              &lt;BR /&gt;             END OF s_empdetails.&lt;BR /&gt;    &lt;BR /&gt;    TYPES : BEGIN OF s_empsal,&lt;BR /&gt;              empid      TYPE n,&lt;BR /&gt;              base_sal   TYPE p,&lt;BR /&gt;            END OF s_empsal.&lt;BR /&gt;DATA : gt_header  TYPE TABLE OF s_empdetails WITH HEADER LINE,&lt;BR /&gt;       gwa_header TYPE s_empdetails.&lt;BR /&gt;DATA : gt_items  TYPE TABLE OF s_empsal,&lt;BR /&gt;       gwa_items TYPE s_empsal.&lt;BR /&gt;LOOP AT gt_items INTO gwa_items.&lt;BR /&gt;  IF gt_items IS INITIAL.&lt;BR /&gt;    gv_highest_num = gwa_items-base_sal.&lt;BR /&gt;  ELSEIF gv_highest_num &amp;lt; gwa_items-base_sal.&lt;BR /&gt;    gv_highest_num = gwa_items-base_sal.&lt;BR /&gt;  ENDIF.&lt;BR /&gt;ENDLOOP.&lt;BR /&gt;LOOP AT gt_items INTO gwa_items.&lt;BR /&gt;  IF gt_items IS INITIAL.&lt;BR /&gt;    gv_second_number = gwa_items-base_sal.&lt;BR /&gt;  ELSEIF gwa_items-base_sal &amp;gt; gv_second_number AND gwa_items-base_sal &amp;lt; gv_highest_num.&lt;BR /&gt;    gv_second_number = gwa_items-base_sal.&lt;BR /&gt;  ENDIF.&lt;BR /&gt;ENDLOOP.&lt;BR /&gt;READ TABLE gt_items INTO gwa_items WITH key base_sal = gv_second_number.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;PRE&gt;&lt;CODE&gt;READ TABLE gt_header INTO gwa_header WITH KEY empid = gwa_items-empid.&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 25 Oct 2021 16:00:15 GMT</pubDate>
    <dc:creator>former_member1320995</dc:creator>
    <dc:date>2021-10-25T16:00:15Z</dc:date>
    <item>
      <title>how to write 2 loops into single loop ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556795#M2007238</link>
      <description>so i have created 2 internal tables and i tried to find the name of employee from first table with base salary from 2nd table and i have manually inserted data into it. so how can i write both loops into single loop. and here is the code i have written -
  &lt;BR /&gt;
  &lt;BR /&gt;
  &lt;PRE&gt;&lt;CODE&gt;TYPES : BEGIN OF s_empdetails,&lt;BR /&gt;              empid       TYPE n,&lt;BR /&gt;              fname(20)       TYPE c,&lt;BR /&gt;              &lt;BR /&gt;             END OF s_empdetails.&lt;BR /&gt;    &lt;BR /&gt;    TYPES : BEGIN OF s_empsal,&lt;BR /&gt;              empid      TYPE n,&lt;BR /&gt;              base_sal   TYPE p,&lt;BR /&gt;            END OF s_empsal.&lt;BR /&gt;DATA : gt_header  TYPE TABLE OF s_empdetails WITH HEADER LINE,&lt;BR /&gt;       gwa_header TYPE s_empdetails.&lt;BR /&gt;DATA : gt_items  TYPE TABLE OF s_empsal,&lt;BR /&gt;       gwa_items TYPE s_empsal.&lt;BR /&gt;LOOP AT gt_items INTO gwa_items.&lt;BR /&gt;  IF gt_items IS INITIAL.&lt;BR /&gt;    gv_highest_num = gwa_items-base_sal.&lt;BR /&gt;  ELSEIF gv_highest_num &amp;lt; gwa_items-base_sal.&lt;BR /&gt;    gv_highest_num = gwa_items-base_sal.&lt;BR /&gt;  ENDIF.&lt;BR /&gt;ENDLOOP.&lt;BR /&gt;LOOP AT gt_items INTO gwa_items.&lt;BR /&gt;  IF gt_items IS INITIAL.&lt;BR /&gt;    gv_second_number = gwa_items-base_sal.&lt;BR /&gt;  ELSEIF gwa_items-base_sal &amp;gt; gv_second_number AND gwa_items-base_sal &amp;lt; gv_highest_num.&lt;BR /&gt;    gv_second_number = gwa_items-base_sal.&lt;BR /&gt;  ENDIF.&lt;BR /&gt;ENDLOOP.&lt;BR /&gt;READ TABLE gt_items INTO gwa_items WITH key base_sal = gv_second_number.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;PRE&gt;&lt;CODE&gt;READ TABLE gt_header INTO gwa_header WITH KEY empid = gwa_items-empid.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Oct 2021 16:00:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556795#M2007238</guid>
      <dc:creator>former_member1320995</dc:creator>
      <dc:date>2021-10-25T16:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to write 2 loops into single loop ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556796#M2007239</link>
      <description>&lt;P&gt;Thank you for visiting SAP
Community to get answers to your questions. Since you're asking a question here for the first time, I
recommend that you familiarize yourself with &lt;U&gt;&lt;A href="https://community.sap.com/resources/questions-and-answers"&gt;Community
Q&amp;amp;A&lt;/A&gt;&lt;/U&gt; , as it provides tips for preparing
questions that draw responses from our members.&lt;/P&gt;

&lt;P&gt;For example,
you can:&lt;/P&gt;

&lt;P&gt;- outline what steps you took to
find answers (and why they weren't helpful)&lt;/P&gt;

&lt;P&gt;- share screenshots of what
you've seen/done&lt;/P&gt;

&lt;P&gt;- make sure you've applied the
appropriate tags&lt;/P&gt;

&lt;P&gt;- use a more descriptive subject line.&lt;/P&gt;

&lt;P&gt;The more details you provide, the
more likely it is that members will be able to respond. Feel free to also take
our Q&amp;amp;A  tutorial &lt;A href="https://developers.sap.com/tutorials/community-qa.html"&gt;Q&amp;amp;A tutorial&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Should you wish, you can revise
your question by selecting Actions, then Edit.&lt;/P&gt;

&lt;P&gt;By adding a picture to your Profile
you encourage readers to respond.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 16:00:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556796#M2007239</guid>
      <dc:creator>former_member751591</dc:creator>
      <dc:date>2021-10-25T16:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to write 2 loops into single loop ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556797#M2007240</link>
      <description>&lt;P&gt;As far as I understand you are trying to find the employee with the second highest salary and then read its name from the other table.&lt;/P&gt;&lt;P&gt;If so, it is a bit of an over-complication. You can simply use a table which is sorted according to the salary.  &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA gt_items TYPE SORTED TABLE OF s_empsal WITH NON-UNIQUE KEY base_sal.
...
READ TABLE gt_items INTO gwa_items INDEX lines( gt_items ) - 1.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This way, you'll have the employee number available in gwa_items and can proceed with the second read command. (Don't forget to check if the table have less then 2 items.)&lt;/P&gt;&lt;P&gt;Also do not use obsolete language elements, like tables with header lines.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Oct 2021 19:35:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556797#M2007240</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-10-25T19:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to write 2 loops into single loop ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556798#M2007241</link>
      <description>&lt;P&gt;Thank you for the response. actually i already got the answer using reading with index but here i am trying to get the answer using loops that wrote into single loop . can u help me with that?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 06:15:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556798#M2007241</guid>
      <dc:creator>former_member1320995</dc:creator>
      <dc:date>2021-10-26T06:15:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to write 2 loops into single loop ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556799#M2007242</link>
      <description>&lt;P&gt;Thank you for the response . actually i already tried with reading with index different way . but here i want to get the anwer using loops that i have mentioned but now in single loop . how can i get it?&lt;/P&gt;&lt;P&gt;and also in the read statement that you have given ,if suppose i have big number of entried in table , then how i should get employee number using index lines?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 06:16:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556799#M2007242</guid>
      <dc:creator>former_member1320995</dc:creator>
      <dc:date>2021-10-26T06:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to write 2 loops into single loop ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556800#M2007243</link>
      <description>&lt;PRE&gt;&lt;CODE&gt; gt_header  TYPE TABLE OF s_empdetails WITH HEADER LINE,&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Tables with HEADER LINES have been obsolete for over twenty years. Don't use them. They're bad programming practice.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 08:01:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556800#M2007243</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2021-10-26T08:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to write 2 loops into single loop ?</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556801#M2007244</link>
      <description>&lt;P&gt;  &lt;SPAN class="mention-scrubbed"&gt;sumedh7&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;Yes, it is possible to implement a logic that uses single iteration. But I'd only use it if there is no option to use sorted tables.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA first TYPE s_empsal.&lt;BR /&gt;DATA second TYPE s_empsal.&lt;BR /&gt;&lt;BR /&gt;READ TABLE gt_items INDEX 1 INTO first.&lt;BR /&gt;READ TABLE gt_items INDEX 1 INTO second.&lt;BR /&gt;&lt;BR /&gt;LOOP AT gt_items FROM 2 INTO gwa_items.&lt;BR /&gt;  &lt;BR /&gt;  IF gwa_items-base_sal &amp;gt; first-base_sal.&lt;BR /&gt;    second = first.&lt;BR /&gt;    first = gwa_items.&lt;BR /&gt;  ELSEIF gwa_items-base_sal &amp;gt; second-base_sal.&lt;BR /&gt;    second = gwa_items.&lt;BR /&gt;  ENDIF.&lt;BR /&gt;  &lt;BR /&gt;ENDLOOP&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Oct 2021 11:27:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/how-to-write-2-loops-into-single-loop/m-p/12556801#M2007244</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2021-10-26T11:27:50Z</dc:date>
    </item>
  </channel>
</rss>

