<?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: optimize SELECT statement in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204318#M1376617</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sudha,&lt;/P&gt;&lt;P&gt;For Query 1:&lt;/P&gt;&lt;P&gt;No need to use count(*) as yiu are using select single. Supply all the promary keys (otherwise use up to 1 rows). As you wants to check whether record exist or not, select up to 1 rows or select single is enough. Checjk on sys-subrc after query will tell you if record exist or not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Query 2:&lt;/P&gt;&lt;P&gt;Same is applicable for second query also.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 08 Oct 2009 11:31:51 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-10-08T11:31:51Z</dc:date>
    <item>
      <title>optimize SELECT statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204310#M1376609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Colleagues, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please assist me in optimizing the two SELECT statement which is taking too much time &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. SELECT SINGLE COUNT(*) FROM j_3abdsi&lt;/P&gt;&lt;P&gt;                          WHERE matnr IN r_matnr&lt;/P&gt;&lt;P&gt;                            AND j_4krcat EQ im_valcat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-- I just need to check whether there are entries in the table with this criteria.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2.   SELECT e~vbeln FROM ( vbep AS e&lt;/P&gt;&lt;P&gt;         INNER JOIN vbap AS p ON p&lt;SUB&gt;vbeln = e&lt;/SUB&gt;vbeln&lt;/P&gt;&lt;P&gt;                        AND p&lt;SUB&gt;posnr = e&lt;/SUB&gt;posnr )&lt;/P&gt;&lt;P&gt;          INTO lv_vbeln&lt;/P&gt;&lt;P&gt;         WHERE p~matnr IN r_matnr&lt;/P&gt;&lt;P&gt;           AND e~j_4krcat eq im_valcat.&lt;/P&gt;&lt;P&gt;    EXIT.&lt;/P&gt;&lt;P&gt;  ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-- here also the case is same. Just need to check whether any value exist. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kindly help. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Sudha&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Sudha Naik on Oct 8, 2009 7:32 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2009 05:31:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204310#M1376609</guid>
      <dc:creator>sudha_naik</dc:creator>
      <dc:date>2009-10-08T05:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: optimize SELECT statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204311#M1376610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;You can check value in the internal table by debugging the prog .&lt;/P&gt;&lt;P&gt;Using select endselect and count * are all expensive statements .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2009 05:45:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204311#M1376610</guid>
      <dc:creator>former_member192432</dc:creator>
      <dc:date>2009-10-08T05:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: optimize SELECT statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204312#M1376611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Sudha, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
SELECT SINGLE e~vbeln FROM ( vbep AS e
INNER JOIN vbap AS p ON p~vbeln = e~vbeln
AND p~posnr = e~posnr )
INTO lv_vbeln
WHERE p~matnr IN r_matnr
AND e~j_4krcat eq im_valcat.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or just load data into table and use DESCRIBE command.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Lukas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Lukasz Gruca on Oct 8, 2009 9:23 AM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Lukasz Gruca on Oct 8, 2009 9:24 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2009 07:22:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204312#M1376611</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-08T07:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: optimize SELECT statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204313#M1376612</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; Try like this,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;

TABLES:  j_3abdsi.

 SELECT SINGLE *
 FROM j_3abdsi
WHERE matnr IN r_matnr
AND j_4krcat EQ im_valcat.

if sy-subrc NE 0.
write: 'No entries available'.
endif.

2. SELECT single  e~vbeln FROM ( vbep AS e
INNER JOIN vbap AS p ON p~vbeln = e~vbeln
AND p~posnr = e~posnr )
INTO lv_vbeln
WHERE p~matnr IN r_matnr
AND e~j_4krcat eq im_valcat.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vikranth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2009 07:27:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204313#M1376612</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-08T07:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: optimize SELECT statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204314#M1376613</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sudha,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try below are the best methods&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;1 ) 
data:lv_lines type i.

SELECT SINGLE * FROM j_3abdsi  "Take required fileds only
into it_itab
WHERE matnr IN r_matnr 
AND j_4krcat EQ im_valcat.
if sy-subrc = 0.
 DESCRBE table it_itab lines lv_lines.
endif.

" In lv_lines you will be getting the number of lines.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for the second query..try to avoid the SELECT..ENDSELECT....&lt;/P&gt;&lt;P&gt;and also check for the secondary indexs..if there you can avoid that..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this info useful to you.&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>Thu, 08 Oct 2009 07:29:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204314#M1376613</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-08T07:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: optimize SELECT statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204315#M1376614</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;as always,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;existenzchecks should be done like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  SELECT ... one field of index ...
               INTO
               FROM
               UP TO 1 ROWS
               WHERE ...
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;+ You don't need to count, you need to know that there is at least 1 !&lt;/P&gt;&lt;P&gt;+ SINGLE and UP TO 1 ROWS are identical, but use SINGLE for full primary key (there is only solution)&lt;/P&gt;&lt;P&gt;   and UP TO 1 ROWS when one out of many is sufficient.&lt;/P&gt;&lt;P&gt;+ Combination COUNT and UP TO 1 ROWS depends on database, some evaluate COUNT first, others UP TO 1 ROWS,&lt;/P&gt;&lt;P&gt;   so be careful when you test yourself.&lt;/P&gt;&lt;P&gt;+ whether you use * or only field gives your some additionaly microseconds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2009 08:08:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204315#M1376614</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-08T08:08:21Z</dc:date>
    </item>
    <item>
      <title>Re: optimize SELECT statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204316#M1376615</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Sudha,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;               You only want to check this record is available or not then you can use statement 'select single count from' like this also you can add 'up to one row' this will give you subrc return.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this will help you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Shrikant.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2009 08:51:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204316#M1376615</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-08T08:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: optimize SELECT statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204317#M1376616</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN __default_attr="18" __jive_macro_name="size"&gt;Never COUNT(*) for Existence Check  !!!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Clear ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2009 11:19:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204317#M1376616</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-08T11:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: optimize SELECT statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204318#M1376617</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sudha,&lt;/P&gt;&lt;P&gt;For Query 1:&lt;/P&gt;&lt;P&gt;No need to use count(*) as yiu are using select single. Supply all the promary keys (otherwise use up to 1 rows). As you wants to check whether record exist or not, select up to 1 rows or select single is enough. Checjk on sys-subrc after query will tell you if record exist or not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Query 2:&lt;/P&gt;&lt;P&gt;Same is applicable for second query also.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2009 11:31:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204318#M1376617</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-08T11:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: optimize SELECT statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204319#M1376618</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sudha,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) I do not understand why you would say SELECT SINGLE COUNT(&lt;STRONG&gt;). If you know the entire primary key and would like to retrieve a record you will use SELECT SINGLE to retrieve just that single record. SELECT COUNT(&lt;/STRONG&gt;) returns the number of records meeting your selection criteria in the system field SY-DBCNT. SELECT COUNT(*) is generally used to check for the existance of the record because this construct just check the number of qualifying records and does not retrieve any data fields from the table. You seem to have merged both these statements and have created something I have never seen before. If you are only interested in finding the existance of the record may I suggest that you use the following. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: w_matnr TYPE mara-matnr.

SELECT matnr
  UP TO 1 ROWS
  FROM j_3abdsi
  WHERE matnr    IN r_matnr
  AND   j_4krcat EQ im_valcat.
ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT COUNT(*) is good if you are using an index. If not you will be trying to count the records without an index. This can be time consuming. If you are not interested in the record count and only want to know if a qualifying record exist the above option will be faster because SAP check for the first instance and then returns SY-SUBRC = 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) Use the following code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT e~vbeln 
  UP TO 1 ROWS
  FROM       vbap AS p
  INNER JOIN vbep AS e
  ON  p~vbeln = e~vbeln
  AND p~posnr = e~posnr )
  INTO lv_vbeln
  WHERE p~matnr    IN r_matnr
  AND   e~j_4krcat EQ im_valcat.
ENDSELECT.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2009 18:15:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204319#M1376618</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-08T18:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: optimize SELECT statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204320#M1376619</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Lukasz Gruca,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sudha does not care about the count. She is just concerned about the existance of a single entry. If you are downloading data into an internal table a READ statement would be less expensive than a DESCRIBE statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Secondly you should use SELECT SINGLE if you are entering single values for all the primary key fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Prasanth Maddela,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you say SELECT SINGLE aren't you just expecting a single record? Why then would you use a DESCRIBE statement to find out what you already know?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Oct 2009 20:02:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204320#M1376619</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-08T20:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: optimize SELECT statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204321#M1376620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sudha,&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Do not use count in selection query.if you want to check the number of entries ,better you use describe table statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;basavaraj&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 10 Oct 2009 16:58:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/optimize-select-statement/m-p/6204321#M1376620</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-10-10T16:58:05Z</dc:date>
    </item>
  </channel>
</rss>

