<?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: please help me optimize this code.. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-this-code/m-p/2160934#M457050</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;1. Avoid APPENDING clause in the SELECT statement. use temporary internal table.&lt;/P&gt;&lt;P&gt;2. Avoid INTO CORRESPONDING &lt;/P&gt;&lt;P&gt;3. Avoid Join on VBAK and VBKD.&lt;/P&gt;&lt;P&gt;4. Avoid select single inside loop, if full keys are not passed in the select.&lt;/P&gt;&lt;P&gt;5.Avoid joins in the Loop-Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;there are so many SELECTs in Loop-Endloop, and even joins. try to move them outside loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;madhu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 May 2007 08:18:31 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-05-02T08:18:31Z</dc:date>
    <item>
      <title>please help me optimize this code..</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-this-code/m-p/2160933#M457049</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i have already checked the indexes of the tables and used the primary keys.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
 r_datum-sign = gco_sign_i.
  r_datum-low  = docdate_from.

  IF NOT docdate_to IS INITIAL.
    r_datum-option = gco_option_bt.
    r_datum-high   = docdate_to.

  ELSE.
    r_datum-option = gco_option_eq.
  ENDIF.

  APPEND r_datum.
  CLEAR r_datum.

  r_vbeln-sign = gco_sign_i.
  r_vbeln-low  = docnum_from.

  IF NOT docnum_to IS INITIAL.
    r_vbeln-option = gco_option_bt.
    r_vbeln-high   = docnum_to.

  ELSE.
    r_vbeln-option = gco_option_eq.
  ENDIF.

  APPEND r_vbeln.
  CLEAR r_vbeln.

  process_web_rset salesgroup
                   r_vkgrp
                   gco_sign_i
                   gco_option_eq.

* Get Total (Confirmed) Qty
  PERFORM get_valid_itemcateg TABLES gr_pstyv.

* Header
  SELECT   vbak~vbeln
           vbkd~inco1
           vbak~erdat
           vbak~gueen
           vbak~ernam
           vbkd~bstkd
           vbak~kunnr
  APPENDING CORRESPONDING FIELDS OF TABLE lt_hdr
  FROM  vbak INNER JOIN vbkd
  ON  vbak~vbeln EQ vbkd~vbeln
  WHERE vbak~vbeln IN r_vbeln
                AND  vbak~erdat IN r_datum
                AND  vbak~vkgrp IN r_vkgrp
                AND  vbak~kunnr EQ customer
                AND  vbkd~posnr EQ lv_posnr
.

  SORT lt_hdr BY vbeln.

  LOOP AT lt_hdr.
* Customer Name
    SELECT SINGLE  kna1~name1
             INTO  lv_cusname
             FROM  kna1
             WHERE kna1~kunnr EQ lt_hdr-kunnr.

    MOVE lt_hdr-vbeln TO listing-sa.
    MOVE lt_hdr-ernam TO listing-ordered_thru.
    MOVE lt_hdr-bstkd TO listing-po.
    MOVE lt_hdr-kunnr TO listing-customer.
    MOVE lv_cusname TO listing-customer_name.

    MOVE lt_hdr-erdat TO listing-date_created.
    MOVE lt_hdr-gueen TO listing-valid_until.


 CONCATENATE lt_hdr-erdat+6(2) lt_hdr-erdat+4(2) lt_hdr-erdat+0(4) INTO
                   listing-date_created SEPARATED BY '.'.

 CONCATENATE  lt_hdr-gueen+6(2) lt_hdr-gueen+4(2) lt_hdr-gueen+0(4) INTO
                            listing-valid_until SEPARATED BY '.'.

* Get Mode of Sale
    IF lt_hdr-inco1 EQ 'FOB'.
      listing-incoterms = co_inco1.

    ELSEIF lt_hdr-inco1 EQ 'CIF'.
      listing-incoterms = co_inco2.
    ENDIF.

* Get Status
    SELECT SINGLE  bezei
             FROM  tvbst JOIN vbuk
               ON  tvbst~statu EQ vbuk~gbstk
             INTO  listing-status
            WHERE  tbnam      EQ co_tbnam
              AND  spras      EQ co_spras
              AND  fdnam      EQ co_fdnam
              AND  vbuk~vbeln EQ listing-sa.

* Get Ship to party
    SELECT SINGLE  name1
             FROM  vbpa INNER JOIN kna1
               ON  vbpa~kunnr = kna1~kunnr
             INTO  listing-ship_to
            WHERE  vbeln EQ listing-sa
              AND  posnr EQ lv_posnr
              AND  parvw EQ 'WE'.

* Get Plant
    SELECT SINGLE  vbap~werks
                   t001w~name1
             FROM  vbap INNER JOIN t001w
               ON  vbap~werks EQ t001w~werks
             INTO (listing-plant,
                   listing-plant_text)
            WHERE  vbap~vbeln EQ listing-sa
            .

* Items
    SELECT SINGLE
          a~matnr
          a~pstyv
          b~bmeng
          b~vrkme
  INTO (lv_matnr,
  lv_pstyv,
  lv_bmeng,
  lv_vrkme)
    FROM  vbap AS a INNER JOIN vbep AS b
      ON  a~vbeln = b~vbeln
     AND  a~posnr = b~posnr
   WHERE  a~vbeln = lt_hdr-vbeln
   AND a~posnr EQ co_posnr
   AND a~pstyv IN gr_pstyv
   .




* Use zshowitem to identify items for display on SO
    lv_convvl = 1.

*   Convert Quantity
    PERFORM check_conversion USING: lv_bmeng
                                    listing-total_uom
                                    lv_pstyv
                                    lv_vrkme
                               lv_matnr.  "&amp;lt;&amp;lt;CR002-DEVK944861 ins

    IF listing-total_uom IS INITIAL.
      MOVE lv_vrkme TO listing-total_uom.
    ENDIF.


    IF listing-total_uom IS INITIAL.
      MOVE lv_vrkme TO listing-total_uom.
    ENDIF.

    vl_sum1 = vl_sum1 + lv_bmeng.

*    ENDLOOP.
    listing-total_qty = vl_sum1.


    REFRESH lv_itab.
    CLEAR: vl_sum1,
           vl_sum2.



* Scheduling Agreement Item and Served Qty
    SELECT SINGLE
            b~vbeln AS vbeln2
            b~rfmng
            b~meins
  INTO (lv_vbeln2,
        lv_rfmng,
        lv_meins)
      FROM  vbap AS a INNER JOIN vbfa AS b
      ON a~vbeln EQ b~vbelv
      AND a~posnr EQ b~posnv
     WHERE a~vbeln = lt_hdr-vbeln
     AND a~pstyv IN gr_pstyv
     AND b~vbtyp_n EQ co_vbtyp_n.
    IF sy-subrc EQ 0.

*   Goods Issue Status per Item
      SELECT SINGLE  wbstk
               FROM  vbuk
               INTO  vl_drstatus
              WHERE  vbeln = lv_vbeln2.

*   Convert Quantity
      PERFORM check_conversion USING: lv_rfmng
                                      listing-served_uom
                                      lv_pstyv
                                      lv_meins
                               lv_matnr. " &amp;lt;&amp;lt;CR002-DEVK944861 ins

*   Pass Value
      IF listing-served_uom IS INITIAL.
        MOVE lv_meins TO listing-served_uom.
      ENDIF.

      vl_served_qty = vl_served_qty + lv_rfmng.


      CLEAR: lt_scheditm,
             vl_drstatus,
             vl_sum3,
             vl_meins.

    ENDIF.



    listing-served_qty = vl_served_qty.
    CLEAR vl_served_qty.

* Append List
    APPEND listing.
    CLEAR: lt_hdr,
           lv_itab,
           lt_scheditm,
           listing,
           vl_datum1,
           vl_datum2,
           vl_sum1,
           vl_sum2,
           vl_sum3.

  ENDLOOP.


  IF sy-subrc &amp;lt;&amp;gt; 0.
    CALL FUNCTION 'BALW_BAPIRETURN_GET2'
         EXPORTING
              type   = 'W'
              cl     = 'ZECOM'
              number = 000
         IMPORTING
              return = return.

  ELSE.
    CALL FUNCTION 'BALW_BAPIRETURN_GET2'
         EXPORTING
              type   = 'S'
              cl     = 'ZECOM'
              number = 001
         IMPORTING
              return = return.
  ENDIF.


ENDFUNCTION.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2007 08:09:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-this-code/m-p/2160933#M457049</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-02T08:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: please help me optimize this code..</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-this-code/m-p/2160934#M457050</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;1. Avoid APPENDING clause in the SELECT statement. use temporary internal table.&lt;/P&gt;&lt;P&gt;2. Avoid INTO CORRESPONDING &lt;/P&gt;&lt;P&gt;3. Avoid Join on VBAK and VBKD.&lt;/P&gt;&lt;P&gt;4. Avoid select single inside loop, if full keys are not passed in the select.&lt;/P&gt;&lt;P&gt;5.Avoid joins in the Loop-Endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;there are so many SELECTs in Loop-Endloop, and even joins. try to move them outside loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;madhu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2007 08:18:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-this-code/m-p/2160934#M457050</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-02T08:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: please help me optimize this code..</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-this-code/m-p/2160935#M457051</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;And even..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1 Try to use field symbols/workarea when looping the internal tables.. &lt;/P&gt;&lt;P&gt; field symbols act like pointers.. they will directly point to the value in the table..&lt;/P&gt;&lt;P&gt;2. Avoid select statement inside the loop..&lt;/P&gt;&lt;P&gt;   select the necessary data from DBtable into Internal tables and the make the manupulations using internal tables..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward if helpful,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;nazeer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2007 08:38:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-this-code/m-p/2160935#M457051</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-02T08:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: please help me optimize this code..</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-this-code/m-p/2160936#M457052</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As mentioned by others avoid into corresponding fields.&lt;/P&gt;&lt;P&gt;If you have to join vbak/vbkd then at least try to use &lt;/P&gt;&lt;P&gt;Sales Organization&lt;/P&gt;&lt;P&gt;Distribution Channel&lt;/P&gt;&lt;P&gt;Division&lt;/P&gt;&lt;P&gt;FOr customer name do n ot select for each document, select for all entries in lt_hdr_aux before the loop where lt_hdr_aux[] = lt_hdr[] with adjacent duplicates by customer deleted and then in the loop use read instead.&lt;/P&gt;&lt;P&gt;Don't use inner joins on vbap to other tables instead select vbap information for all documents selected and then read.&lt;/P&gt;&lt;P&gt;etc etc&lt;/P&gt;&lt;P&gt;Use st05 to review which table accesses are giving you a problem and concentrate first on those taking into account&lt;/P&gt;&lt;P&gt; - not to retrieve data multiple times e.g. is customer is cust1 for deoc1 and for doc 10 then only retrieve once as detailed above.&lt;/P&gt;&lt;P&gt;- optimise the actual select statement - no into corresponding, using keys etc&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2007 18:14:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/please-help-me-optimize-this-code/m-p/2160936#M457052</guid>
      <dc:creator>alison_lloyd</dc:creator>
      <dc:date>2007-05-02T18:14:02Z</dc:date>
    </item>
  </channel>
</rss>

