<?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: Performance of a SQL Query in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-of-a-sql-query/m-p/2242692#M483661</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Giri,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you post the whole program because I am not sure why the person who wrote this code user for all entries on a select option instead of just using the select option in the query?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 17 May 2007 16:51:49 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-05-17T16:51:49Z</dc:date>
    <item>
      <title>Performance of a SQL Query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-of-a-sql-query/m-p/2242691#M483660</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code given by you is working absolutely fine.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can you please help me to solve the following complicated query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT a~vbeln &lt;/P&gt;&lt;P&gt;         a~erdat &lt;/P&gt;&lt;P&gt;         a~ernam &lt;/P&gt;&lt;P&gt;         a~vkorg &lt;/P&gt;&lt;P&gt;         a~vkbur &lt;/P&gt;&lt;P&gt;         a~kunnr &lt;/P&gt;&lt;P&gt;         b~kunnr AS kunnr_shp &lt;/P&gt;&lt;P&gt;         b~adrnr &lt;/P&gt;&lt;P&gt;         c~gbstk &lt;/P&gt;&lt;P&gt;         c~fkstk&lt;/P&gt;&lt;P&gt;         d~vbeln AS vbeln_i &lt;/P&gt;&lt;P&gt;    INTO CORRESPONDING FIELDS OF TABLE t_z92sales &lt;/P&gt;&lt;P&gt;    FROM vbak AS a INNER JOIN vbuk AS c ON a&lt;SUB&gt;vbeln = c&lt;/SUB&gt;vbeln &lt;/P&gt;&lt;P&gt;    INNER JOIN vbpa AS b ON a&lt;SUB&gt;vbeln = b&lt;/SUB&gt;vbeln &lt;/P&gt;&lt;P&gt;      AND b&lt;SUB&gt;posnr = 0 AND b&lt;/SUB&gt;parvw = 'WE' &lt;/P&gt;&lt;P&gt;      LEFT OUTER JOIN vbfa AS d ON a&lt;SUB&gt;vbeln = d&lt;/SUB&gt;vbelv &lt;/P&gt;&lt;P&gt;      AND d~vbtyp_n = 'M' &lt;/P&gt;&lt;P&gt;      FOR ALL ENTRIES IN vbeln_s&lt;/P&gt;&lt;P&gt;      WHERE a~vbeln = vbeln_s-low &lt;/P&gt;&lt;P&gt;          AND a~vbtyp = 'C' &lt;/P&gt;&lt;P&gt;          AND a~vkorg IN vkorg_s &lt;/P&gt;&lt;P&gt;          AND c~gbstk IN gbstk_s.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Giri&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 May 2007 14:12:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-of-a-sql-query/m-p/2242691#M483660</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-17T14:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: Performance of a SQL Query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-of-a-sql-query/m-p/2242692#M483661</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Giri,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you post the whole program because I am not sure why the person who wrote this code user for all entries on a select option instead of just using the select option in the query?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 May 2007 16:51:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-of-a-sql-query/m-p/2242692#M483661</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-17T16:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: Performance of a SQL Query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-of-a-sql-query/m-p/2242693#M483662</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Giri,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ASSUMPTION:&lt;/P&gt;&lt;P&gt;As you have not answered my previous post I am assuming that the programmer who wrote this query had no apparent reason for using the following &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FOR ALL ENTRIES IN vbeln_s&lt;/P&gt;&lt;P&gt;WHERE a~vbeln = vbeln_s-low &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and could have written it as &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WHERE a~vbeln IN vbeln_s &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Based on this assumption I have written the following code. Please let me know if it solves your problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TABLES: vbak,
        vbuk.

SELECT-OPTIONS: vbeln_s FOR vbak-vbeln,
                vkorg_s FOR vbak-vkorg,
                gbstk_s FOR vbuk-gbstk.

DATA: w_index TYPE sy-tabix,

      BEGIN OF t_z92sales OCCURS 0,
        vbeln     TYPE vbak-vbeln,
        erdat     TYPE vbak-erdat,
        ernam     TYPE vbak-ernam,
        vkorg     TYPE vbak-vkorg,
        vkbur     TYPE vbak-vkbur,
        kunnr     TYPE vbak-kunnr,
        kunnr_shp TYPE vbpa-kunnr,
        adrnr     TYPE vbpa-adrnr,
        gbstk     TYPE vbuk-gbstk,
        fkstk     TYPE vbuk-fkstk,
        vbeln_i   TYPE vbfa-vbeln,
      END OF t_z92sales,

      BEGIN OF t_vbak OCCURS 0,
        vbeln TYPE vbak-vbeln,
        erdat TYPE vbak-erdat,
        ernam TYPE vbak-ernam,
        vkorg TYPE vbak-vkorg,
        vkbur TYPE vbak-vkbur,
        kunnr TYPE vbak-kunnr,
      END OF t_vbak,

      BEGIN OF t_vbuk OCCURS 0,
        vbeln TYPE vbuk-vbeln,
        gbstk TYPE vbuk-gbstk,
        fkstk TYPE vbuk-fkstk,
      END OF t_vbuk,

      BEGIN OF t_vbpa OCCURS 0,
        vbeln TYPE vbpa-vbeln,
        kunnr TYPE vbpa-kunnr,
        adrnr TYPE vbpa-adrnr,
      END OF t_vbpa,

      BEGIN OF t_vbfa OCCURS 0,
        vbelv TYPE vbfa-vbelv,
        posnv TYPE vbfa-posnv,
        vbeln TYPE vbfa-vbeln,
        posnn TYPE vbfa-posnn,
      END OF t_vbfa.


REFRESH t_z92sales.

SELECT vbeln
       erdat
       ernam
       vkorg
       vkbur
       kunnr
FROM vbak
INTO TABLE t_vbak
WHERE vbeln IN vbeln_s
AND   vbtyp EQ 'C'
AND   vkorg IN vkorg_s.

IF sy-subrc EQ 0.

  SORT t_vbak BY vbeln.

  SELECT vbeln
         gbstk
         fkstk
    FROM vbuk
    INTO TABLE t_vbuk
    FOR ALL ENTRIES IN t_vbak
    WHERE vbeln EQ t_vbak-vbeln
    AND   gbstk IN gbstk_s.

  IF sy-subrc EQ 0.

    SORT t_vbuk BY vbeln.

    SELECT vbeln
           kunnr
           adrnr
      FROM vbpa
      INTO TABLE t_vbpa
      FOR ALL ENTRIES IN t_vbuk
      WHERE vbeln EQ t_vbuk-vbeln
      AND   posnr EQ '000000'
      AND   parvw EQ 'WE'.

    IF sy-subrc EQ 0.

      SORT t_vbpa BY vbeln.

      SELECT vbelv
             posnv
             vbeln
             posnn
        FROM vbfa
        INTO TABLE t_vbfa
        FOR ALL ENTRIES IN t_vbpa
        WHERE vbelv EQ t_vbpa-vbeln
        AND   vbtyp_n EQ 'M'.
      IF sy-subrc EQ 0.
        SORT t_vbfa BY vbelv
                       posnv
                       vbeln
                       posnn.
      ENDIF.

    ENDIF.

  ENDIF.

ENDIF.

LOOP AT t_vbak.

  READ TABLE t_vbuk WITH KEY vbeln = t_vbak-vbeln
                             BINARY SEARCH
                             TRANSPORTING
                               gbstk
                               fkstk.
  IF sy-subrc EQ 0.
    READ TABLE t_vbpa WITH KEY vbeln = t_vbak-vbeln
                               BINARY SEARCH
                               TRANSPORTING
                                 kunnr
                                 adrnr.
    IF sy-subrc EQ 0.

      t_z92sales-vbeln     = t_vbak-vbeln.
      t_z92sales-erdat     = t_vbak-erdat.
      t_z92sales-ernam     = t_vbak-ernam.
      t_z92sales-vkorg     = t_vbak-vkorg.
      t_z92sales-vkbur     = t_vbak-vkbur.
      t_z92sales-kunnr     = t_vbak-kunnr.
      t_z92sales-kunnr_shp = t_vbpa-kunnr.
      t_z92sales-adrnr     = t_vbpa-adrnr.
      t_z92sales-gbstk     = t_vbuk-gbstk.
      t_z92sales-fkstk     = t_vbuk-fkstk.

      READ TABLE t_vbfa WITH KEY vbelv = t_vbak-vbeln
                                 BINARY SEARCH
                                 TRANSPORTING NO FIELDS.
      IF sy-subrc EQ 0.
        w_index = sy-tabix.

        LOOP AT t_vbfa FROM w_index.

          IF t_vbfa-vbelv GT t_vbak-vbeln.
            EXIT.
          ELSEIF t_vbfa-vbelv EQ t_vbak-vbeln.
            t_z92sales-vbeln_i = t_vbfa-vbeln.
            APPEND t_z92sales.
          ENDIF.

        ENDLOOP.

        CLEAR  t_z92sales.

      ELSE.
        APPEND t_z92sales.
        CLEAR  t_z92sales.
      ENDIF.

    ENDIF.

  ENDIF.

ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 May 2007 18:13:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-of-a-sql-query/m-p/2242693#M483662</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-17T18:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Performance of a SQL Query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-of-a-sql-query/m-p/2242694#M483663</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;If u want to imrpove perfromance of this query:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Remove corrosponding fields of table option&lt;/P&gt;&lt;P&gt;2. first use all inner join and outer join condition and then write seprate sql for for all entreis in vbeln_s&lt;/P&gt;&lt;P&gt;3. in worst case give inner joins in one query and outer join in other and for all entries in third one, but it think 1.2. will work....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jogdand M B&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 May 2007 04:34:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-of-a-sql-query/m-p/2242694#M483663</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-18T04:34:59Z</dc:date>
    </item>
    <item>
      <title>Re: Performance of a SQL Query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-of-a-sql-query/m-p/2242695#M483664</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Mark,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the promp reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your previous code is working absolutely fine as i made few changes as per my requirement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ii need to improve the performanceof this Function module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am testing your code as well, will update you accordingly. Please prvovide me your persoanl mail ID so that i can interact with you directly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers and Regards,&lt;/P&gt;&lt;P&gt;Ramada Giri&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 May 2007 11:41:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-of-a-sql-query/m-p/2242695#M483664</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-18T11:41:54Z</dc:date>
    </item>
  </channel>
</rss>

