<?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: read in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/read/m-p/3414713#M820106</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;READ - Read an internal table&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;Basic form&lt;/P&gt;&lt;P&gt;READ TABLE itab. &lt;/P&gt;&lt;P&gt;READ TABLE itab INTO wa. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additions&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1a. ... WITH KEY k1 = v1 ... kn = vn &lt;/P&gt;&lt;P&gt;1b. ... WITH KEY = value &lt;/P&gt;&lt;P&gt;1c. ... WITH KEY key &lt;/P&gt;&lt;P&gt;2. ... BINARY SEARCH &lt;/P&gt;&lt;P&gt;3. ... INDEX idx &lt;/P&gt;&lt;P&gt;4a. ... COMPARING f1 f2 ... &lt;/P&gt;&lt;P&gt;4b. ... COMPARING ALL FIELDS &lt;/P&gt;&lt;P&gt;5a. ... TRANSPORTING f1 f2 ... &lt;/P&gt;&lt;P&gt;5b. ... TRANSPORTING NO FIELDS &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;Reads an internal table entry. An entry can be chosen using a key or its index. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With " READ TABLE itab. ", the header line of the internal table itab is used as the output area; with " READ TABLE itab INTO wa. " the explicity specified work area wa is used for this purpose. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The return code value of SY-SUBRC specifies whether a suitable entry was found. In turn, this determines the value of the table index SY-TABIX . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC = 0 Entry found &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-TABIX is set to the index of the found entry. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC &amp;lt;&amp;gt; 0 Entry not found &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The value of SY-TABIX is undefined. &lt;/P&gt;&lt;P&gt;The output area remains unchanged. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note&lt;/P&gt;&lt;P&gt;In the case of internal tables with a header, a table line can be accessed without specifying an explicit key (addition: WITH KEY ... ) or index (addition: INDEX idx ). The system then uses (as an implicit key) all table header fields that are not number fields (type I, F, P), are not tables themselves (compare default keys of internal tables) and whose contents are unequal to SPACE . It searches for the first entry which matches the header in all key fields and transfers this entry into the output area. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The implicit key is only set up (dynamically) at runtime. If the search key is already known at the time of generation (static), the read with an explicit key is faster than with an implicit key, and is therefore preferable. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 1a&lt;/P&gt;&lt;P&gt;... WITH KEY k1 = v1 ... kn = vn &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;Accesses the first entry which matches v1 ... vn in the components specified with k1 ... kn . Here, the component type forms the basis for the comparison between the components and the values. If the type of a value and the type of a component are not compatible, the value is converted to the type of the component before the read access is performed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notes&lt;/P&gt;&lt;P&gt;If a component is not determined until runtime, you can use WITH KEY ... (ni) = vi ... to specify it dynamically as the contents of the field ni . If ni is empty at runtime, the component is ignored. If ni contains an invalid component name, a runtime error occurs. &lt;/P&gt;&lt;P&gt;You can use offset and/or length specifications to further restrict components, regardless of whether they have been specified statically or dynamically. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 1b&lt;/P&gt;&lt;P&gt;... WITH KEY = value &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;Accesses the first entry which matches value . In this case, the type of the table line forms the basis for the comparison between table lines and the specified value. If the type of the specified value and the type of the table line are not compatible, the specified value is converted to the type of the table line before the read access is performed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note&lt;/P&gt;&lt;P&gt;Even with internal tables containing lines with no components, the addition WITH KEY = value allows you to access an entry via an explicity specified key. Internal tables without line components result when you define internal tables directly via an elementary data type or a table type, but not via a field string. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 1c&lt;/P&gt;&lt;P&gt;... WITH KEY key &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;Accesses the first entry which begins with key (left-justified). The type of the specified key forms the basis for the comparison between table lines and the specified key. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note&lt;/P&gt;&lt;P&gt;The key key can be neither a table nor a structure that contains tables as components. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note&lt;/P&gt;&lt;P&gt;Runtime errors (only when using addition 1c): &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ_BAD_KEY_ALIGN : The alignment requirements of the key take priority over those of individual table lines. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ_BAD_KEY_PARTIAL : The key is longer than a table line and cannot be shortened. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 2&lt;/P&gt;&lt;P&gt;... BINARY SEARCH &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;The addition BINARY SEARCH only makes sense with one of the WITH-KEY additions (1a-1c). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The read access is performed using a binary search method and is non-sequential. It is assumed that the internal table is sorted in ascending order according to the specified key, with addition 1a in the order of the specified key fields. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the specified key is not unique, the entry with the lowest index is placed in the output area. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The return code value of SY-SUBRC specifies whether a suitable entry was found. In turn, this determines the value of the table index SY-TABIX . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC = 0 Entry found &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-TABIX is set to the index of the found entry &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC &amp;lt;&amp;gt; 0 Entry not found &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The output area remains unchanged. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY_SUBRC = 4 SY-TABIX points to the next largest entry. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC = 8 The key sought is greater than that of the last table entry. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-TABIX is set to (number of all entries + 1). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF INT_TABLE  OCCURS 100,&lt;/P&gt;&lt;P&gt;        COMP1,&lt;/P&gt;&lt;P&gt;        COMP2,&lt;/P&gt;&lt;P&gt;        COMP3,&lt;/P&gt;&lt;P&gt;      END OF INT_TABLE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FORM PUT_ENTRY USING ENTRY LIKE LINE OF INT_TABLE.&lt;/P&gt;&lt;P&gt;  READ TABLE INT_TABLE WITH KEY COMP2 = ENTRY-COMP2&lt;/P&gt;&lt;P&gt;                       BINARY SEARCH&lt;/P&gt;&lt;P&gt;                       TRANSPORTING NO FIELDS.&lt;/P&gt;&lt;P&gt;  IF SY-SUBRC &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;    INSERT ENTRY INTO INT_TABLE INDEX SY-TABIX.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;ENDFORM.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The method used in this subroutine makes it easy (and desirable for performance) to add new entries to a table and sort them. &lt;/P&gt;&lt;P&gt;Before PERFORM PUT_ENTRY , you fill the transferred work area ENTRY with the new values. The READ statement checks (in the sorted internal table INT_TABLE ) whether an entry with the specified key already exists. The system fields SY-SUBRC and SY-TABIX are set accordingly. Then, if ( SY-SUBRC &amp;lt;&amp;gt; 0 ), the new entry is inserted at the appropriate place. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 3&lt;/P&gt;&lt;P&gt;... INDEX idx &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;Accesses the entry with the index idx of an internal table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The return code value of SY-SUBRC specifies whether a suitable entry was found. In turn, this determines the value of the table index SY-TABIX . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC = 0 Entry found &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-TABIX is set to the index of the found entry. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC &amp;lt;&amp;gt; 0 Entry not found &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The value of SY-TABIX is undefined. &lt;/P&gt;&lt;P&gt;The output area remains unchanged. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 4a&lt;/P&gt;&lt;P&gt;... COMPARING f1 f2 ... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;This addition has no effect on the read process itself, i.e. it is normally used together with one of the additions 1, 2 or 3. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Only when an entry - regardless of the read method - already exists does this addition cause the contents of the sub-fields f1, f2, ... of the found entry to be compared with the corresponding fields of the output area before transporting the found entry to the output area. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The return code value of SY-SUBRC specifies whether the value sought was found and, if so, the result of the comparison: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC = 0 Entry found, field contents identical &lt;/P&gt;&lt;P&gt;SY-SUBRC = 2 Entry found, field contents different &lt;/P&gt;&lt;P&gt;SY-SUBRC &amp;gt; 2 Entry not found &lt;/P&gt;&lt;P&gt;If you want to indicate explicitly that no fields are compared (even though this is the default), you can use COMPARING NO FIELDS . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notes&lt;/P&gt;&lt;P&gt;If you use COMPARING together with an explicitly specified work area, the lattter must be compatible with the line type of the internal table. &lt;/P&gt;&lt;P&gt;If a comparison criterion is not known until runtime, you can use COMPARING ... (name) ... to specify it dynamically as the contents of the name . If name is blank at runtime, the comparison criterion is ignored. If name contains an invalid component name, a runtime error occurs. &lt;/P&gt;&lt;P&gt;You can use offset and/or length specifications to further restrict comparison criteria, regardless of whether they have been specified statically or dynamically. &lt;/P&gt;&lt;P&gt;If you use READ TABLE itab in its basic form (i.e. without one of its additions 1, 2 or 3, the addition COMPARING f1 f2 ... makes sense only if the fields f1, f2, ... are not part of the read key, i.e. if f1, f2, ... are number fields (type I, F or P). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 4b&lt;/P&gt;&lt;P&gt;... COMPARING ALL FIELDS &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;As with addition 4a, but compares all sub-fields. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 5a&lt;/P&gt;&lt;P&gt;... TRANSPORTING f1 f2 ... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;If an entry is found, not all sub-fields are transported to the output area (default), but only the specified sub-fields f1, f2, ... ; the other sub-fields remain unchanged. &lt;/P&gt;&lt;P&gt;If you want to indicate explicitly that all fields are transported (even though this is the default), you can use TRANSPORTING ALL FIELDS . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notes&lt;/P&gt;&lt;P&gt;If you use TRANSPORTING f1 f2 ... together with an explicitly specified output area, the latter must be compatible with the line type of the internal table. &lt;/P&gt;&lt;P&gt;If a transport field is not known until runtime, you can use TRANSPORTING ... (name) ... to specify it dynamically as the contents of the name . If name is blank at runtime, the transport criterion is ignored. If name contains an invalid component name, a runtime error occurs. &lt;/P&gt;&lt;P&gt;You can use offset and/or length specifications to further restrict transport fields, regardless of whether they have been specified statically or dynamically. &lt;/P&gt;&lt;P&gt;If you use the additions " COMPARING " and " TRANSPORTING " together, " COMPARING " must come before " TRANSPORTING ". &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 5b&lt;/P&gt;&lt;P&gt;... TRANSPORTING NO FIELDS &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;Does not change the output area of the internal table. The only purpose of the access is to set the system fields SY-SUBRC and SY-TABIX . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note&lt;/P&gt;&lt;P&gt;Performance &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The fastest way of reading a single record from an internal table is to make a direct access by specifying an index, because this is not dependent on the number of table entries and is much the same as the cost of transporting one line. &lt;/P&gt;&lt;P&gt;If you use a key to access the table, the required runtime increases with the number of lines and the size of the search key. A binary search is considerably faster than a linear search. Therefore, it is usually advisable to keep the table sorted and to use the addition BINARY SEARCH . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reading a record from a table with 100 entries with an index specification requires about 7 msn (standardized microseconds). Access with a 30-byte wide key takes about 25 msn. with a binary search, and about 100 msn. without a binary search. &lt;/P&gt;&lt;P&gt;If you use statements with an explicit work area for internal tables with a header line, you can avoid unnecessary assignments.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 Feb 2008 07:23:49 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-02-20T07:23:49Z</dc:date>
    <item>
      <title>read</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read/m-p/3414712#M820105</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1)code for reading an internal table  and then place it into another internal table....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2)and what is the use of  key with in read&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;3)code for reading a  table  and then place it into another internal table....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Sunil on Feb 20, 2008 8:24 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2008 07:21:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read/m-p/3414712#M820105</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-20T07:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: read</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read/m-p/3414713#M820106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG&gt;READ - Read an internal table&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;Basic form&lt;/P&gt;&lt;P&gt;READ TABLE itab. &lt;/P&gt;&lt;P&gt;READ TABLE itab INTO wa. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Additions&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1a. ... WITH KEY k1 = v1 ... kn = vn &lt;/P&gt;&lt;P&gt;1b. ... WITH KEY = value &lt;/P&gt;&lt;P&gt;1c. ... WITH KEY key &lt;/P&gt;&lt;P&gt;2. ... BINARY SEARCH &lt;/P&gt;&lt;P&gt;3. ... INDEX idx &lt;/P&gt;&lt;P&gt;4a. ... COMPARING f1 f2 ... &lt;/P&gt;&lt;P&gt;4b. ... COMPARING ALL FIELDS &lt;/P&gt;&lt;P&gt;5a. ... TRANSPORTING f1 f2 ... &lt;/P&gt;&lt;P&gt;5b. ... TRANSPORTING NO FIELDS &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;Reads an internal table entry. An entry can be chosen using a key or its index. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With " READ TABLE itab. ", the header line of the internal table itab is used as the output area; with " READ TABLE itab INTO wa. " the explicity specified work area wa is used for this purpose. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The return code value of SY-SUBRC specifies whether a suitable entry was found. In turn, this determines the value of the table index SY-TABIX . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC = 0 Entry found &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-TABIX is set to the index of the found entry. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC &amp;lt;&amp;gt; 0 Entry not found &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The value of SY-TABIX is undefined. &lt;/P&gt;&lt;P&gt;The output area remains unchanged. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note&lt;/P&gt;&lt;P&gt;In the case of internal tables with a header, a table line can be accessed without specifying an explicit key (addition: WITH KEY ... ) or index (addition: INDEX idx ). The system then uses (as an implicit key) all table header fields that are not number fields (type I, F, P), are not tables themselves (compare default keys of internal tables) and whose contents are unequal to SPACE . It searches for the first entry which matches the header in all key fields and transfers this entry into the output area. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The implicit key is only set up (dynamically) at runtime. If the search key is already known at the time of generation (static), the read with an explicit key is faster than with an implicit key, and is therefore preferable. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 1a&lt;/P&gt;&lt;P&gt;... WITH KEY k1 = v1 ... kn = vn &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;Accesses the first entry which matches v1 ... vn in the components specified with k1 ... kn . Here, the component type forms the basis for the comparison between the components and the values. If the type of a value and the type of a component are not compatible, the value is converted to the type of the component before the read access is performed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notes&lt;/P&gt;&lt;P&gt;If a component is not determined until runtime, you can use WITH KEY ... (ni) = vi ... to specify it dynamically as the contents of the field ni . If ni is empty at runtime, the component is ignored. If ni contains an invalid component name, a runtime error occurs. &lt;/P&gt;&lt;P&gt;You can use offset and/or length specifications to further restrict components, regardless of whether they have been specified statically or dynamically. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 1b&lt;/P&gt;&lt;P&gt;... WITH KEY = value &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;Accesses the first entry which matches value . In this case, the type of the table line forms the basis for the comparison between table lines and the specified value. If the type of the specified value and the type of the table line are not compatible, the specified value is converted to the type of the table line before the read access is performed. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note&lt;/P&gt;&lt;P&gt;Even with internal tables containing lines with no components, the addition WITH KEY = value allows you to access an entry via an explicity specified key. Internal tables without line components result when you define internal tables directly via an elementary data type or a table type, but not via a field string. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 1c&lt;/P&gt;&lt;P&gt;... WITH KEY key &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;Accesses the first entry which begins with key (left-justified). The type of the specified key forms the basis for the comparison between table lines and the specified key. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note&lt;/P&gt;&lt;P&gt;The key key can be neither a table nor a structure that contains tables as components. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note&lt;/P&gt;&lt;P&gt;Runtime errors (only when using addition 1c): &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ_BAD_KEY_ALIGN : The alignment requirements of the key take priority over those of individual table lines. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ_BAD_KEY_PARTIAL : The key is longer than a table line and cannot be shortened. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 2&lt;/P&gt;&lt;P&gt;... BINARY SEARCH &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;The addition BINARY SEARCH only makes sense with one of the WITH-KEY additions (1a-1c). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The read access is performed using a binary search method and is non-sequential. It is assumed that the internal table is sorted in ascending order according to the specified key, with addition 1a in the order of the specified key fields. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the specified key is not unique, the entry with the lowest index is placed in the output area. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The return code value of SY-SUBRC specifies whether a suitable entry was found. In turn, this determines the value of the table index SY-TABIX . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC = 0 Entry found &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-TABIX is set to the index of the found entry &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC &amp;lt;&amp;gt; 0 Entry not found &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The output area remains unchanged. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY_SUBRC = 4 SY-TABIX points to the next largest entry. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC = 8 The key sought is greater than that of the last table entry. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-TABIX is set to (number of all entries + 1). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: BEGIN OF INT_TABLE  OCCURS 100,&lt;/P&gt;&lt;P&gt;        COMP1,&lt;/P&gt;&lt;P&gt;        COMP2,&lt;/P&gt;&lt;P&gt;        COMP3,&lt;/P&gt;&lt;P&gt;      END OF INT_TABLE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FORM PUT_ENTRY USING ENTRY LIKE LINE OF INT_TABLE.&lt;/P&gt;&lt;P&gt;  READ TABLE INT_TABLE WITH KEY COMP2 = ENTRY-COMP2&lt;/P&gt;&lt;P&gt;                       BINARY SEARCH&lt;/P&gt;&lt;P&gt;                       TRANSPORTING NO FIELDS.&lt;/P&gt;&lt;P&gt;  IF SY-SUBRC &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;P&gt;    INSERT ENTRY INTO INT_TABLE INDEX SY-TABIX.&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;ENDFORM.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The method used in this subroutine makes it easy (and desirable for performance) to add new entries to a table and sort them. &lt;/P&gt;&lt;P&gt;Before PERFORM PUT_ENTRY , you fill the transferred work area ENTRY with the new values. The READ statement checks (in the sorted internal table INT_TABLE ) whether an entry with the specified key already exists. The system fields SY-SUBRC and SY-TABIX are set accordingly. Then, if ( SY-SUBRC &amp;lt;&amp;gt; 0 ), the new entry is inserted at the appropriate place. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 3&lt;/P&gt;&lt;P&gt;... INDEX idx &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;Accesses the entry with the index idx of an internal table. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The return code value of SY-SUBRC specifies whether a suitable entry was found. In turn, this determines the value of the table index SY-TABIX . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC = 0 Entry found &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-TABIX is set to the index of the found entry. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC &amp;lt;&amp;gt; 0 Entry not found &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The value of SY-TABIX is undefined. &lt;/P&gt;&lt;P&gt;The output area remains unchanged. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 4a&lt;/P&gt;&lt;P&gt;... COMPARING f1 f2 ... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;This addition has no effect on the read process itself, i.e. it is normally used together with one of the additions 1, 2 or 3. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Only when an entry - regardless of the read method - already exists does this addition cause the contents of the sub-fields f1, f2, ... of the found entry to be compared with the corresponding fields of the output area before transporting the found entry to the output area. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The return code value of SY-SUBRC specifies whether the value sought was found and, if so, the result of the comparison: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SY-SUBRC = 0 Entry found, field contents identical &lt;/P&gt;&lt;P&gt;SY-SUBRC = 2 Entry found, field contents different &lt;/P&gt;&lt;P&gt;SY-SUBRC &amp;gt; 2 Entry not found &lt;/P&gt;&lt;P&gt;If you want to indicate explicitly that no fields are compared (even though this is the default), you can use COMPARING NO FIELDS . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notes&lt;/P&gt;&lt;P&gt;If you use COMPARING together with an explicitly specified work area, the lattter must be compatible with the line type of the internal table. &lt;/P&gt;&lt;P&gt;If a comparison criterion is not known until runtime, you can use COMPARING ... (name) ... to specify it dynamically as the contents of the name . If name is blank at runtime, the comparison criterion is ignored. If name contains an invalid component name, a runtime error occurs. &lt;/P&gt;&lt;P&gt;You can use offset and/or length specifications to further restrict comparison criteria, regardless of whether they have been specified statically or dynamically. &lt;/P&gt;&lt;P&gt;If you use READ TABLE itab in its basic form (i.e. without one of its additions 1, 2 or 3, the addition COMPARING f1 f2 ... makes sense only if the fields f1, f2, ... are not part of the read key, i.e. if f1, f2, ... are number fields (type I, F or P). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 4b&lt;/P&gt;&lt;P&gt;... COMPARING ALL FIELDS &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;As with addition 4a, but compares all sub-fields. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 5a&lt;/P&gt;&lt;P&gt;... TRANSPORTING f1 f2 ... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;If an entry is found, not all sub-fields are transported to the output area (default), but only the specified sub-fields f1, f2, ... ; the other sub-fields remain unchanged. &lt;/P&gt;&lt;P&gt;If you want to indicate explicitly that all fields are transported (even though this is the default), you can use TRANSPORTING ALL FIELDS . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Notes&lt;/P&gt;&lt;P&gt;If you use TRANSPORTING f1 f2 ... together with an explicitly specified output area, the latter must be compatible with the line type of the internal table. &lt;/P&gt;&lt;P&gt;If a transport field is not known until runtime, you can use TRANSPORTING ... (name) ... to specify it dynamically as the contents of the name . If name is blank at runtime, the transport criterion is ignored. If name contains an invalid component name, a runtime error occurs. &lt;/P&gt;&lt;P&gt;You can use offset and/or length specifications to further restrict transport fields, regardless of whether they have been specified statically or dynamically. &lt;/P&gt;&lt;P&gt;If you use the additions " COMPARING " and " TRANSPORTING " together, " COMPARING " must come before " TRANSPORTING ". &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Addition 5b&lt;/P&gt;&lt;P&gt;... TRANSPORTING NO FIELDS &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Effect&lt;/P&gt;&lt;P&gt;Does not change the output area of the internal table. The only purpose of the access is to set the system fields SY-SUBRC and SY-TABIX . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note&lt;/P&gt;&lt;P&gt;Performance &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The fastest way of reading a single record from an internal table is to make a direct access by specifying an index, because this is not dependent on the number of table entries and is much the same as the cost of transporting one line. &lt;/P&gt;&lt;P&gt;If you use a key to access the table, the required runtime increases with the number of lines and the size of the search key. A binary search is considerably faster than a linear search. Therefore, it is usually advisable to keep the table sorted and to use the addition BINARY SEARCH . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reading a record from a table with 100 entries with an index specification requires about 7 msn (standardized microseconds). Access with a 30-byte wide key takes about 25 msn. with a binary search, and about 100 msn. without a binary search. &lt;/P&gt;&lt;P&gt;If you use statements with an explicit work area for internal tables with a header line, you can avoid unnecessary assignments.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2008 07:23:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read/m-p/3414713#M820106</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-20T07:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: read</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read/m-p/3414714#M820107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;READ TABLE ITAB WITH KEY itabfield = field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Key will helps to read the internal table&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2008 07:24:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read/m-p/3414714#M820107</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-20T07:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: read</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read/m-p/3414715#M820108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can read an internal table using either  aKEY or an INDEX.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you use a KEY - it searches for a &lt;STRONG&gt;single&lt;/STRONG&gt; record in the itnernal table where the columns mentioned match the value being searched for&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
READ TABLE &amp;lt;itab&amp;gt; INTO &amp;lt;wa&amp;gt; WITH KEY &amp;lt;field1&amp;gt; = &amp;lt;value1&amp;gt;.
IF SY-SUBRC EQ 0.
 Write:/ 'Value found'.
ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note: You have to use '=' and cant use 'EQ' here in WITH KEY clause, also here &amp;lt;field1&amp;gt; is a column in internal table &amp;lt;itab&amp;gt; and the record found for the check is moved into work area &amp;lt;wa&amp;gt; and SY-SUBRC set to 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For performance you must sort the table by the fields you are checking in KEY clause and then use BINARY SEARCH extension as shown:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SORT &amp;lt;itab&amp;gt; BY &amp;lt;field1&amp;gt;.
READ TABLE &amp;lt;itab&amp;gt; INTO &amp;lt;wa&amp;gt; WITH KEY &amp;lt;field1&amp;gt; = &amp;lt;value1&amp;gt; BINARY SEARCH.
IF SY-SUBRC EQ 0.
 Write:/ 'Value found'.
ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Other method is when you know you need a specific record &amp;lt;index&amp;gt; from the internal table, then you use the followuing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __jive_macro_name="Code"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;READ TABLE &amp;lt;itab&amp;gt; INTO &amp;lt;wa&amp;gt; INDEX &amp;lt;index&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here , if the &amp;lt;index&amp;gt; you use is 0 or negative, a short dump will occur.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Aditya&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2008 07:27:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read/m-p/3414715#M820108</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-20T07:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: read</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read/m-p/3414716#M820109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dude,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of giving u the fish,I'll tell u how to fish.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Type READ on you SAP editor(SE38).&lt;/P&gt;&lt;P&gt;Place cursor on this text and press F1.It  takes you to the help documentation which tells you all that you needs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For code,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Issue ABAPDOCU tcode.&lt;/P&gt;&lt;P&gt;Navigate to READ statement.It contains all the sample code u need.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Lakshmanan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Feb 2008 07:30:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read/m-p/3414716#M820109</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-02-20T07:30:13Z</dc:date>
    </item>
  </channel>
</rss>

