<?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: code optimization in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-optimization/m-p/5378988#M1237148</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Instead of using so many nested loops ... use FOR ALL ENTERIES&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 23 Mar 2009 14:23:30 GMT</pubDate>
    <dc:creator>amit_khare</dc:creator>
    <dc:date>2009-03-23T14:23:30Z</dc:date>
    <item>
      <title>code optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-optimization/m-p/5378987#M1237147</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;I need an assistance to optimise this code as it is slowing down the server.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
  select werks from t001w into table itab_werks where werks like 'A%'.
  delete itab_werks where werks cp 'A0*' .
  loop at itab_werks.
    select matnr werks lgort labst insme   from mard into
                  corresponding fields of table imard where
                          werks = itab_werks-werks.
    delete imard where labst = 0  and insme = 0 .
    sort imard by lgort matnr .
    loop at imard .
      select single * from mara where matnr = imard-matnr and
                      mtart = 'FERT'.
      if sy-subrc ne 0.
        continue.
      endif.
      refresh : clr_qty ,  h_status_tab.
      clear clr_qty.
      select * from equi into table itab_equi where matnr = imard-matnr
     loop at itab_equi.
         if itab_equi-werk  eq itab_werks-werks and
             itab_equi-lager eq imard-lgort.
             refresh : h_status_tab , h_status_text_tab.
          clear atwrt2.
          clear colour.
          move itab_equi-charge to colour.
          move colour+2(8) to atwrt2.
          call function 'STATUS_READ'
            exporting
              client           = sy-mandt
              objnr            = itab_equi-objnr
              only_active      = 'X'
            tables
              status           = h_status_tab
            exceptions
              object_not_found = 1
              others           = 2.
          loop at h_status_tab.
            call function 'STATUS_NUMBER_CONVERSION'
              exporting
                language      = sy-langu
                objnr         = itab_equi-objnr
                status_number = h_status_tab-stat
              importing
                txt04         = h_status_text_tab-txt04
              exceptions
                others        = 01.
            if sy-subrc = 0.
              append h_status_text_tab.
            endif.
          endloop.
          clear h_stat_flag.
          loop at h_status_text_tab.
            check h_status_text_tab-txt04 = 'ESTO'.
            h_stat_flag = 'X'.
            exit.
          endloop.
          delete h_status_text_tab where txt04 ne 'ESTO' .
          clear h_status_text_tab .
          read table h_status_text_tab index 1.
          describe table h_status_text_tab lines lin2.
          if lin2 &amp;gt; 0 .
            if h_stat_flag = 'X'.
              move : atwrt2 to clr_qty-atwrt.
                move 1 to clr_qty-qty.
              collect clr_qty.
              clear: clr_qty-qty.
            endif.
          endif.
        else.
          clear eqbs.
          select single * from eqbs where equnr   = itab_equi-equnr
                                and b_werk    = itab_werks-werks
                                and b_lager   = imard-lgort.
          if sy-subrc eq 0 .
            refresh : h_status_tab , h_status_text_tab.
            clear atwrt2.
            clear colour.
            move itab_equi-charge to colour.
            move colour+2(8) to atwrt2.
           call function 'STATUS_READ'
              exporting
                client           = sy-mandt
                objnr            = itab_equi-objnr
                only_active      = 'X'
              tables
                status           = h_status_tab
              exceptions
                object_not_found = 1
                others           = 2.
            loop at h_status_tab.
              call function 'STATUS_NUMBER_CONVERSION'
                exporting
                  language      = sy-langu
                  objnr         = itab_equi-objnr
                  status_number = h_status_tab-stat
                importing
                  txt04         = h_status_text_tab-txt04
                exceptions
                  others        = 01.
              if sy-subrc = 0.
                append h_status_text_tab.
              endif.
            endloop.
            clear h_stat_flag.
            loop at h_status_text_tab.
              check h_status_text_tab-txt04 = 'ESTO'.
              h_stat_flag = 'X'.
              exit.
            endloop.
            delete h_status_text_tab where txt04 ne 'ESTO' .
            clear h_status_text_tab .
            read table h_status_text_tab index 1.
            describe table h_status_text_tab lines lin2.
            if lin2 &amp;gt; 0 .
              if h_stat_flag = 'X'.
                move : atwrt2 to clr_qty-atwrt.
                  move 1 to clr_qty-qty.
                   collect clr_qty.
                clear: clr_qty-qty , clr_qty-atwrt.
              endif .
            endif.
          endif.
        endif .
 endloop.
      loop at clr_qty.
        move imard-matnr to wa-matnr .
        move imard-werks to wa-werks .
        move imard-lgort to wa-lgort.
        move clr_qty-atwrt to  wa-atwrt.
        move clr_qty-qty to wa-cvmla .
        append wa to  itab_zstockdet .
      endloop.
     clear wa.
    endloop.
  endloop.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Mar 2009 14:09:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-optimization/m-p/5378987#M1237147</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-03-23T14:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: code optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-optimization/m-p/5378988#M1237148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Instead of using so many nested loops ... use FOR ALL ENTERIES&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Mar 2009 14:23:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-optimization/m-p/5378988#M1237148</guid>
      <dc:creator>amit_khare</dc:creator>
      <dc:date>2009-03-23T14:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: code optimization</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-optimization/m-p/5378989#M1237149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&amp;gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; Instead of using so many nested loops ... use FOR ALL ENTERIES&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Inner joins are more efficient.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't use tables with header line, use hashed tables, or sorted tables.  Break your program down into FORMs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read this forum where other people have posted their code asking for tips.  They don't vary much.  As such, this is a frequently asked and answered question.  So I'm locking it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;matt&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Matt on Mar 23, 2009 4:33 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Mar 2009 15:33:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-optimization/m-p/5378989#M1237149</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2009-03-23T15:33:13Z</dc:date>
    </item>
  </channel>
</rss>

