<?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 Read Internal Table in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-internal-table/m-p/4678212#M1100183</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to read a particular record from an internal table. Can you please help me build the logic?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the scenario: I have Order Number and a flag as fields in an internal table. I need to pick the &lt;STRONG&gt;Order Number&lt;/STRONG&gt; which is not flagged and next to the highest Order is which is flagged. Ignore anything in the middle. I know that I can get this done by creating another internal table. But was wondering how I do it using only 1 internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the following example, I need to pick Order &lt;STRONG&gt;8450&lt;/STRONG&gt; because the highest flagged order is 7020.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;ITAB:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;________&lt;/P&gt;&lt;P&gt;&lt;U&gt;Order|Flag&lt;/U&gt;&lt;/P&gt;&lt;P&gt;9460|&lt;/P&gt;&lt;P&gt;8450|&lt;/P&gt;&lt;P&gt;7020|X&lt;/P&gt;&lt;P&gt;6030|X&lt;/P&gt;&lt;P&gt;5120|&lt;/P&gt;&lt;P&gt;5068|X&lt;/P&gt;&lt;P&gt;4320|X&lt;/P&gt;&lt;P&gt;2130|&lt;/P&gt;&lt;P&gt;1150|X&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 24 Oct 2008 21:17:17 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-10-24T21:17:17Z</dc:date>
    <item>
      <title>Read Internal Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-internal-table/m-p/4678212#M1100183</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to read a particular record from an internal table. Can you please help me build the logic?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the scenario: I have Order Number and a flag as fields in an internal table. I need to pick the &lt;STRONG&gt;Order Number&lt;/STRONG&gt; which is not flagged and next to the highest Order is which is flagged. Ignore anything in the middle. I know that I can get this done by creating another internal table. But was wondering how I do it using only 1 internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the following example, I need to pick Order &lt;STRONG&gt;8450&lt;/STRONG&gt; because the highest flagged order is 7020.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;ITAB:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;________&lt;/P&gt;&lt;P&gt;&lt;U&gt;Order|Flag&lt;/U&gt;&lt;/P&gt;&lt;P&gt;9460|&lt;/P&gt;&lt;P&gt;8450|&lt;/P&gt;&lt;P&gt;7020|X&lt;/P&gt;&lt;P&gt;6030|X&lt;/P&gt;&lt;P&gt;5120|&lt;/P&gt;&lt;P&gt;5068|X&lt;/P&gt;&lt;P&gt;4320|X&lt;/P&gt;&lt;P&gt;2130|&lt;/P&gt;&lt;P&gt;1150|X&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Oct 2008 21:17:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-internal-table/m-p/4678212#M1100183</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-24T21:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: Read Internal Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-internal-table/m-p/4678213#M1100184</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Something along the lines of:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;READ TABLE itab WITH KEY flag = 'X'.
index = sy-tabix - 1.
READ TABLE itab INDEX index.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tested this and it does what I want it to do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rob Burbank on Oct 24, 2008 5:31 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Oct 2008 21:25:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-internal-table/m-p/4678213#M1100184</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-24T21:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Read Internal Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-internal-table/m-p/4678214#M1100185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;try to do that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: BEGIN OF itab OCCURS 0,
        order(10),
        flag,
      END OF itab.

DATA: w_order LIKE itab-order,
      w_tabix TYPE sy-tabix..

itab-order = 9460.
itab-flag  = ' '.
APPEND itab.

itab-order = 8450.
itab-flag  = ' '.
APPEND itab.

itab-order = 7020.
itab-flag  = 'X'.
APPEND itab.

itab-order = 6030.
itab-flag  = 'X'.
APPEND itab.

itab-order = 5120.
itab-flag  = ' '.
APPEND itab.

itab-order = 5068.
itab-flag  = 'X'.
APPEND itab.

itab-order = 4320.
itab-flag  = 'X'.
APPEND itab.

itab-order = 2130.
itab-flag  = ' '.
APPEND itab.

itab-order = 1150.
itab-flag  = 'X'.
APPEND itab.

SORT itab BY order DESCENDING.

CLEAR w_tabix.
LOOP AT itab.
  IF  w_tabix IS INITIAL
  AND itab-flag EQ 'X'.
    w_tabix = sy-tabix.
  ENDIF.
ENDLOOP.

w_tabix = w_tabix - 1.

READ TABLE itab INDEX w_tabix.
WRITE: itab-order.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Oct 2008 21:32:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-internal-table/m-p/4678214#M1100185</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-24T21:32:54Z</dc:date>
    </item>
    <item>
      <title>Re: Read Internal Table</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-internal-table/m-p/4678215#M1100186</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great Rob, Thanks. That worked.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 Oct 2008 21:46:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-internal-table/m-p/4678215#M1100186</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-10-24T21:46:07Z</dc:date>
    </item>
  </channel>
</rss>

