<?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: Table Expression in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/table-expression/m-p/12284263#M1988967</link>
    <description>&lt;P&gt;We already had the almost same discussion &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://answers.sap.com/questions/13018949/abap-new-syntax.html"&gt;https://answers.sap.com/questions/13018949/abap-new-syntax.html&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;1) Your table expression to read a record of the table, is using &lt;STRONG&gt;a search with a specified table key and it always requires the FULL key to be given.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;You have to provide all key values with this method, no part of the key can be left out and no further non-key attributes can be included!&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ls_tor_item_pred = lt_tor_item_pred[ KEY btd_id COMPONENTS
                      btd_id     = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_id
                      btd_tco    = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_tco
                      parent_key = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-key
                      root_key   = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-root_key ].

" equivalent READ TABLE statement (this will also throw the same error as above in your case)
READ TABLE lt_tor_item_pred INTO ls_tor_item_pred WITH TABLE KEY btd_id COMPONENTS
                      btd_id     =  &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_id
                      btd_tco     = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_tco
                      parent_key = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-key
                      root_key   = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-root_key.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;2) Your READ TABLE statement is using, &lt;STRONG&gt;a free search key WITH a forced binary search on a complete/partial primary/secondary key. This statement does not have a corresponding table expression.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Unlike the statement READ TABLE with a free key specified, no binary searches can be forced for a table expression and it is not possible to specify explicit table key for optimizing searches using secondary keys.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;READ TABLE lt_tor_item_pred INTO ls_tor_item_pred WITH KEY btd_id COMPONENTS
                      btd_id     =  &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_id
                      btd_tco     = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_tco
                      parent_key = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-key
                      root_key   = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-root_key.

" no equivalent for table expressions&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;3) Free search key vs. Specified search key&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;See the following examples to understand the differences in READ TABLE statements. Please be aware, that when a free key overlaps with some or all of the primary table key, the search optimizations are performed when sorted tables and hashed tables are read.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;" Free search key (without forcing binary search)
READ TABLE itab WITH KEY comp1 = operand1 ASSIGNING &amp;lt;fs&amp;gt;.
ASSIGN itab[ comp1 = operand1 ] TO &amp;lt;fs&amp;gt;.

" Free search key with explicitly forcing binary search on used components.
" error prone since the table needs to be 'manually' sorted by the used components
READ TABLE itab BINARY SEARCH WITH KEY comp1 = operand1 ASSIGNING &amp;lt;fs&amp;gt;.
" And because it is error prone, there is no equivalent in table expressions

" Free search key with implicetly forcing binary search based on key (primary or secondary) 
" error prone since used components dont have to partially/fully match the defined key components
READ TABLE itab WITH KEY key_name COMPONENTS comp1 = operand1 ASSIGNING &amp;lt;fs&amp;gt;.
" And because it is error prone, there is no equivalent in table expressions

" Search by primary table key (the full primary key has to be provided)
READ TABLE itab WITH TABLE KEY comp1 = operand1 ASSIGNING &amp;lt;fs&amp;gt;.
ASSIGN itab[ KEY primary_key COMPONENTS comp1 = operand1] TO &amp;lt;fs&amp;gt;. 

" Search by specified table key (primary or secondary, the full key has to be provided)
READ TABLE itab WITH TABLE KEY key_name COMPONENTS comp1 = operand1 ASSIGNING &amp;lt;fs&amp;gt;.
ASSIGN itab[ KEY key_name COMPONENTS comp1 = operand1] TO &amp;lt;fs&amp;gt;. &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 01 Sep 2020 12:14:25 GMT</pubDate>
    <dc:creator>michael_piesche</dc:creator>
    <dc:date>2020-09-01T12:14:25Z</dc:date>
    <item>
      <title>Table Expression</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/table-expression/m-p/12284262#M1988966</link>
      <description>&lt;P&gt;Hello Experts!&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;TRY.             

ls_tor_item_pred =  lt_tor_item_pred[ KEY btd_id                                                   
COMPONENTS 
btd_id     = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_id                                                      
btd_tco    = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_tco                                                   
parent_key = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-key                                                   
root_key   = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-root_key                                                 
].           

CATCH cx_sy_itab_line_not_found.         

ENDTRY. 

READ TABLE lt_tor_item_pred INTO ls_tor_item_pred WITH KEY btd_id 

COMPONENTS
btd_id     =  &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_id                                                      btd_tco     = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_tco                                                                    parent_key = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-key
root_key   = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-root_key.&lt;/CODE&gt;&lt;/PRE&gt; 
  &lt;PRE&gt;&lt;CODE&gt;The error which occurs is the following:The component "PARENT_KEY" is not in key "BTD_ID" of table "LT_TOR_ITEM_PRED" or the key is not known statically.The structures secondary keys are:BTD_IDBTD_KEYPARENT_KEYPREDEC_STATUSROOT_KEY&amp;lt;br&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Any idea about why I get an error message within the compiler y using the table expression?&lt;/P&gt;
  &lt;P&gt;Kind regards,&lt;/P&gt;
  &lt;P&gt;Pascal&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2020 11:52:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/table-expression/m-p/12284262#M1988966</guid>
      <dc:creator>former_member647100</dc:creator>
      <dc:date>2020-09-01T11:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Table Expression</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/table-expression/m-p/12284263#M1988967</link>
      <description>&lt;P&gt;We already had the almost same discussion &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://answers.sap.com/questions/13018949/abap-new-syntax.html"&gt;https://answers.sap.com/questions/13018949/abap-new-syntax.html&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;1) Your table expression to read a record of the table, is using &lt;STRONG&gt;a search with a specified table key and it always requires the FULL key to be given.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;You have to provide all key values with this method, no part of the key can be left out and no further non-key attributes can be included!&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ls_tor_item_pred = lt_tor_item_pred[ KEY btd_id COMPONENTS
                      btd_id     = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_id
                      btd_tco    = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_tco
                      parent_key = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-key
                      root_key   = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-root_key ].

" equivalent READ TABLE statement (this will also throw the same error as above in your case)
READ TABLE lt_tor_item_pred INTO ls_tor_item_pred WITH TABLE KEY btd_id COMPONENTS
                      btd_id     =  &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_id
                      btd_tco     = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_tco
                      parent_key = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-key
                      root_key   = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-root_key.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;2) Your READ TABLE statement is using, &lt;STRONG&gt;a free search key WITH a forced binary search on a complete/partial primary/secondary key. This statement does not have a corresponding table expression.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt; Unlike the statement READ TABLE with a free key specified, no binary searches can be forced for a table expression and it is not possible to specify explicit table key for optimizing searches using secondary keys.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;READ TABLE lt_tor_item_pred INTO ls_tor_item_pred WITH KEY btd_id COMPONENTS
                      btd_id     =  &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_id
                      btd_tco     = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-orig_btd_tco
                      parent_key = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-key
                      root_key   = &amp;lt;ls_tor_item_dlv_tmp&amp;gt;-root_key.

" no equivalent for table expressions&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;3) Free search key vs. Specified search key&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;See the following examples to understand the differences in READ TABLE statements. Please be aware, that when a free key overlaps with some or all of the primary table key, the search optimizations are performed when sorted tables and hashed tables are read.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;" Free search key (without forcing binary search)
READ TABLE itab WITH KEY comp1 = operand1 ASSIGNING &amp;lt;fs&amp;gt;.
ASSIGN itab[ comp1 = operand1 ] TO &amp;lt;fs&amp;gt;.

" Free search key with explicitly forcing binary search on used components.
" error prone since the table needs to be 'manually' sorted by the used components
READ TABLE itab BINARY SEARCH WITH KEY comp1 = operand1 ASSIGNING &amp;lt;fs&amp;gt;.
" And because it is error prone, there is no equivalent in table expressions

" Free search key with implicetly forcing binary search based on key (primary or secondary) 
" error prone since used components dont have to partially/fully match the defined key components
READ TABLE itab WITH KEY key_name COMPONENTS comp1 = operand1 ASSIGNING &amp;lt;fs&amp;gt;.
" And because it is error prone, there is no equivalent in table expressions

" Search by primary table key (the full primary key has to be provided)
READ TABLE itab WITH TABLE KEY comp1 = operand1 ASSIGNING &amp;lt;fs&amp;gt;.
ASSIGN itab[ KEY primary_key COMPONENTS comp1 = operand1] TO &amp;lt;fs&amp;gt;. 

" Search by specified table key (primary or secondary, the full key has to be provided)
READ TABLE itab WITH TABLE KEY key_name COMPONENTS comp1 = operand1 ASSIGNING &amp;lt;fs&amp;gt;.
ASSIGN itab[ KEY key_name COMPONENTS comp1 = operand1] TO &amp;lt;fs&amp;gt;. &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Sep 2020 12:14:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/table-expression/m-p/12284263#M1988967</guid>
      <dc:creator>michael_piesche</dc:creator>
      <dc:date>2020-09-01T12:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Table Expression</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/table-expression/m-p/12284264#M1988968</link>
      <description>&lt;P&gt;Your question is incorrectly formatted: you say that "The structures secondary keys [I guess you mean the components of the secondary key BTD_ID] are: BTD_ID, BTD_KEY, PARENT_KEY, PREDEC_STATUS, ROOT_KEY."&lt;/P&gt;&lt;P&gt;Why do you access the internal table &lt;STRONG&gt;without using PREDEC_STATUS&lt;/STRONG&gt;? Don't you think it's the cause of the error?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2020 18:58:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/table-expression/m-p/12284264#M1988968</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-09-01T18:58:20Z</dc:date>
    </item>
  </channel>
</rss>

