<?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 Select statement using all fields in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280551#M1988683</link>
    <description>&lt;P&gt;I want to do a select on a database table for all fields of my work area. Is there a shorter way to do this i.e. I don't want to specify all 30 fields in the select? &lt;/P&gt;
  &lt;P&gt;All I want to do is check if the record exists in my DB table or not.&lt;/P&gt;
  &lt;P&gt;For example, I have:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;  LOOP AT g_table INTO wa_line.

    SELECT SINGLE * FROM zmydb_tab

    WHERE field1 = wa_line-field1

    AND   field2 = wa_line-field2

    ".... etc ... until

    AND   field30 = wa_line-field30.

  ENDLOOP.

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 15 Sep 2020 12:21:37 GMT</pubDate>
    <dc:creator>former_member201275</dc:creator>
    <dc:date>2020-09-15T12:21:37Z</dc:date>
    <item>
      <title>Select statement using all fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280551#M1988683</link>
      <description>&lt;P&gt;I want to do a select on a database table for all fields of my work area. Is there a shorter way to do this i.e. I don't want to specify all 30 fields in the select? &lt;/P&gt;
  &lt;P&gt;All I want to do is check if the record exists in my DB table or not.&lt;/P&gt;
  &lt;P&gt;For example, I have:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;  LOOP AT g_table INTO wa_line.

    SELECT SINGLE * FROM zmydb_tab

    WHERE field1 = wa_line-field1

    AND   field2 = wa_line-field2

    ".... etc ... until

    AND   field30 = wa_line-field30.

  ENDLOOP.

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Sep 2020 12:21:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280551#M1988683</guid>
      <dc:creator>former_member201275</dc:creator>
      <dc:date>2020-09-15T12:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement using all fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280552#M1988684</link>
      <description>&lt;P&gt;a dynamic where condition should simplify your query. loop those fields and create a dynamic where and pass it to the select where condition,&lt;/P&gt;&lt;P&gt;eg:&lt;/P&gt;&lt;P&gt;&lt;A href="https://answers.sap.com/questions/8136030/dynamic-where-condition-in-select-statement.html" target="test_blank"&gt;https://answers.sap.com/questions/8136030/dynamic-where-condition-in-select-statement.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Update: one more suggestion, try for all entries, so all the data will be selected in one go, then loop and check if the record exists. for creating dynamic for all entries:&lt;/P&gt;&lt;P&gt;&lt;A href="https://answers.sap.com/questions/8342724/dynamic-select-with-for-all-entries-in.html" target="test_blank"&gt;https://answers.sap.com/questions/8342724/dynamic-select-with-for-all-entries-in.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mahesh&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 12:32:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280552#M1988684</guid>
      <dc:creator>maheshpalavalli</dc:creator>
      <dc:date>2020-09-15T12:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement using all fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280553#M1988685</link>
      <description>&lt;P&gt;You would have been faster to write those thirty lines instead of posting a question and waiting for an answer.&lt;/P&gt;&lt;P&gt;In order to get the best performance, you will have to at least use all or parts of the key fields. Please keep in mind, that the less lines of coding does definitly not always mean better performance. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;" e.g.:
" 1) select records from zmydb_tab by primary keys 
" for all entries in g_table into a second internal table (e.g. db_table) 
" 2) and then do loop on g_table with an index search on the new db_table 
" and if a record is found, also compare both structures (without addressing a field directly)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So I hope you do care about bad performance caused by a SELECT ALL ENDSELECT that is nested in a LOOP statement (yucky, yuck, yuck - I wrote that version first, but couldnt leave that there).&lt;/P&gt;&lt;P&gt;For the following coding, I assume the structure of g_table and zmydb_tab are identical.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA db_table TYPE SORTED TABLE OF zmydb WITH UNIQUE KEYS key1 key2.

SELECT * FROM zmydb_tab INTO TABLE db_table FOR ALL ENTRIES IN g_table
         WHERE key1 = g_table-key1
           AND key2 = g_table-key2.

LOOP AT g_table INTO wa_line.   
  " make sure, that if wa_line has a client attribute that is empty, to also fill it accordingly
  READ TABLE db_table WITH TABLE KEY key1 = wa_line-key1 key2 = wa_line-key2.
  IF sy-subrc = 0 AND wa_line = db_line.
    " you found a perfect match, what do you want to do?
  ELSEIF sy-subrc = 0.
    " you found a match based on a key, but with different non-key values, what to do?
  ELSE.
    " you found no match, what do you want to do?
  ENDIF.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;On a serious note: &lt;/STRONG&gt;I would strongly recommend that you rework your requirements and the current coding you are wanting to put in place. Even though I dont know your entire requirements yet, your approach just doesnt feel right.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Sep 2020 13:03:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280553#M1988685</guid>
      <dc:creator>michael_piesche</dc:creator>
      <dc:date>2020-09-15T13:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement using all fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280554#M1988686</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;gemini.twin&lt;/SPAN&gt;, I hope you did not accept my answer when I was still about to present a bad coding example.&lt;/P&gt;&lt;P&gt;But if indeed so, here it is. It will work. But it is bad, really bad &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT g_table INTO wa_line. " make sure, that if wa_line has a client attribute that is empty, to also fill it accordingly
  SELECT * FROM zmydb_tab INTO db_line.
    IF wa_line = db_line. 
      " you found a match, what do you want to do?
      EXIT.
    ENDIF.
  ENDSELECT.
  IF wa_line &amp;lt;&amp;gt; db_line. " no match found
    " you found no match, what do you want to do?
  ENDIF.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Sep 2020 13:17:27 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280554#M1988686</guid>
      <dc:creator>michael_piesche</dc:creator>
      <dc:date>2020-09-15T13:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement using all fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280555#M1988687</link>
      <description>No need to show a so bad example, sometimes people take the code without reading the text accompanying it ! &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;</description>
      <pubDate>Tue, 15 Sep 2020 17:23:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280555#M1988687</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-09-15T17:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Select statement using all fields</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280556#M1988688</link>
      <description>&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;I actually took your advice at the end of your comment i.e. 'I would strongly recommend that you rework your requirement'. I changed the way the table was defined, to include a key and then it is easier to access.&lt;/P&gt;&lt;P&gt;Thank you kindly for your help!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 16:15:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/select-statement-using-all-fields/m-p/12280556#M1988688</guid>
      <dc:creator>former_member201275</dc:creator>
      <dc:date>2020-09-16T16:15:35Z</dc:date>
    </item>
  </channel>
</rss>

