<?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: nested select qurey to convert into normal in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-select-qurey-to-convert-into-normal/m-p/3355170#M804999</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI jaya kumar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Always try to avoid using select statement within loop , as this leads to accessing the database for every loop and hence decrease the performance.&lt;/P&gt;&lt;P&gt;You can refer the below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If not iqamb is initail.&lt;/P&gt;&lt;P&gt;select * from QAMB  into tb_qamb for all  entries in iqamb where PRUEFLOS EQ IQAMB-PRUEFLOS  .&lt;/P&gt;&lt;P&gt;Endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If not tb_qamb is initial.&lt;/P&gt;&lt;P&gt;select * from mseg into tb_mseg for all entries in tb_qamb where  MJAHR EQ QAMB-MJAHR .&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at i qamb.&lt;/P&gt;&lt;P&gt;Read table tb_qamb into wa_qamb where mblnr eq itab-mblnr.&lt;/P&gt;&lt;P&gt;read table tb_mseg into wa_mseg where  MJAHR EQ wa_QAMB-MJAHR AND&lt;/P&gt;&lt;P&gt;ZEILE EQ wa_QAMB-ZEILE AND&lt;/P&gt;&lt;P&gt;BWART EQ '321' AND&lt;/P&gt;&lt;P&gt;UMLGO EQ '1400' AND&lt;/P&gt;&lt;P&gt;XAUTO EQ ' '.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt;update fields.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endloop&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sachin M M&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Jan 2008 05:31:32 GMT</pubDate>
    <dc:creator>sachin_mathapati</dc:creator>
    <dc:date>2008-01-25T05:31:32Z</dc:date>
    <item>
      <title>nested select qurey to convert into normal</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-select-qurey-to-convert-into-normal/m-p/3355169#M804998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hai experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;how to improve the performance to modify the below select qurey converted in to normal?&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;LOOP AT IQAMB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM QAMB WHERE PRUEFLOS EQ IQAMB-PRUEFLOS AND&lt;/P&gt;&lt;P&gt;                                    MBLNR NE ITAB-MBLNR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;          SELECT SINGLE MENGE INTO (MSEG-MENGE)&lt;/P&gt;&lt;P&gt;                              FROM MSEG WHERE MBLNR EQ QAMB-MBLNR AND&lt;/P&gt;&lt;P&gt;                                          MJAHR EQ QAMB-MJAHR AND&lt;/P&gt;&lt;P&gt;                                          ZEILE EQ QAMB-ZEILE AND&lt;/P&gt;&lt;P&gt;                                          BWART EQ '321' AND&lt;/P&gt;&lt;P&gt;                                          UMLGO EQ '1400' AND&lt;/P&gt;&lt;P&gt;                                          XAUTO EQ ' '.&lt;/P&gt;&lt;P&gt;          IF SY-SUBRC NE 0. CONTINUE. ENDIF.&lt;/P&gt;&lt;P&gt;          MOVE MSEG-MENGE TO TMP_MENGE.&lt;/P&gt;&lt;P&gt;          MOVE QAMB-MBLNR TO TMP_MBLNR.&lt;/P&gt;&lt;P&gt;          MOVE QAMB-MJAHR TO TMP-MJAHR.&lt;/P&gt;&lt;P&gt;          PERFORM ADDTOITAB.&lt;/P&gt;&lt;P&gt;        ENDSELECT.&lt;/P&gt;&lt;P&gt;ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward will avail for useful answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks in adv.&lt;/P&gt;&lt;P&gt;jai.m&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Jan 2008 04:42:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-select-qurey-to-convert-into-normal/m-p/3355169#M804998</guid>
      <dc:creator>jayakummar</dc:creator>
      <dc:date>2008-01-25T04:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: nested select qurey to convert into normal</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-select-qurey-to-convert-into-normal/m-p/3355170#M804999</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI jaya kumar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Always try to avoid using select statement within loop , as this leads to accessing the database for every loop and hence decrease the performance.&lt;/P&gt;&lt;P&gt;You can refer the below code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If not iqamb is initail.&lt;/P&gt;&lt;P&gt;select * from QAMB  into tb_qamb for all  entries in iqamb where PRUEFLOS EQ IQAMB-PRUEFLOS  .&lt;/P&gt;&lt;P&gt;Endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If not tb_qamb is initial.&lt;/P&gt;&lt;P&gt;select * from mseg into tb_mseg for all entries in tb_qamb where  MJAHR EQ QAMB-MJAHR .&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at i qamb.&lt;/P&gt;&lt;P&gt;Read table tb_qamb into wa_qamb where mblnr eq itab-mblnr.&lt;/P&gt;&lt;P&gt;read table tb_mseg into wa_mseg where  MJAHR EQ wa_QAMB-MJAHR AND&lt;/P&gt;&lt;P&gt;ZEILE EQ wa_QAMB-ZEILE AND&lt;/P&gt;&lt;P&gt;BWART EQ '321' AND&lt;/P&gt;&lt;P&gt;UMLGO EQ '1400' AND&lt;/P&gt;&lt;P&gt;XAUTO EQ ' '.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if sy-subrc eq 0.&lt;/P&gt;&lt;P&gt;update fields.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;endloop&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if helpful.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sachin M M&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Jan 2008 05:31:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-select-qurey-to-convert-into-normal/m-p/3355170#M804999</guid>
      <dc:creator>sachin_mathapati</dc:creator>
      <dc:date>2008-01-25T05:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: nested select qurey to convert into normal</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-select-qurey-to-convert-into-normal/m-p/3355171#M805000</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;Instead of fetching all the field data in QAMB fetch only required fields like in&lt;/P&gt;&lt;P&gt;QAMB table u need only 3 fields MBLNR MJAHR ZEILE so that it will not waste time in fetching all fields .&lt;/P&gt;&lt;P&gt;Try following code .&lt;/P&gt;&lt;P&gt;In declaration declare one Internal tabletb_qamb  which contain MBLNR MJAHR ZEILE from QAMB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If not iqamb is initial.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select MBLNR MJAHR ZEILE from QAMB into tb_qamb for all entries in iqamb where PRUEFLOS EQ IQAMB-PRUEFLOS .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	If not tb_qamb is initial.&lt;/P&gt;&lt;P&gt;		select single MENGE from mseg into l_menge &lt;/P&gt;&lt;P&gt;					WHERE MBLNR EQ QAMB-	MBLNR&lt;/P&gt;&lt;P&gt;					AND 	MJAHR EQ QAMB-MJAHR &lt;/P&gt;&lt;P&gt;					AND   ZEILE EQ QAMB-ZEILE &lt;/P&gt;&lt;P&gt;					AND    BWART EQ '321' &lt;/P&gt;&lt;P&gt;					AND	UMLGO EQ '1400' &lt;/P&gt;&lt;P&gt;					AND	XAUTO EQ ' '.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	IF SY-SUBRC NE 0. CONTINUE. ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;MOVE l_MENGE TO TMP_MENGE.&lt;/P&gt;&lt;P&gt;MOVE tb_QAMB-MBLNR TO TMP_MBLNR.&lt;/P&gt;&lt;P&gt;MOVE tb_QAMB-MJAHR TO TMP-MJAHR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	PERFORM ADDTOITAB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;	ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDSELECT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Give reward points if it helps...............&lt;/P&gt;&lt;P&gt;Best Luck&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Jan 2008 13:57:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-select-qurey-to-convert-into-normal/m-p/3355171#M805000</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-25T13:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: nested select qurey to convert into normal</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/nested-select-qurey-to-convert-into-normal/m-p/3355172#M805001</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try using the following piece of code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF ty_qamb,&lt;/P&gt;&lt;P&gt;         prueflos TYPE qamb-prueflos,&lt;/P&gt;&lt;P&gt;         zaehler  TYPE qamb-zaehler ,&lt;/P&gt;&lt;P&gt;         mblnr    TYPE qamb-mblnr   ,&lt;/P&gt;&lt;P&gt;         mjahr    TYPE qamb-mjahr   ,&lt;/P&gt;&lt;P&gt;         zeile    TYPE qamb-zeile   ,&lt;/P&gt;&lt;P&gt;       END OF ty_qamb,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       BEGIN OF ty_mseg,&lt;/P&gt;&lt;P&gt;         mblnr TYPE mseg-mblnr,&lt;/P&gt;&lt;P&gt;         mjahr TYPE mseg-mjahr,&lt;/P&gt;&lt;P&gt;         zeile TYPE mseg-zeile,&lt;/P&gt;&lt;P&gt;         menge TYPE mseg-menge,&lt;/P&gt;&lt;P&gt;       END OF ty_mseg.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: w_qamb     TYPE                 ty_qamb,&lt;/P&gt;&lt;P&gt;      w_mseg     TYPE                 ty_mseg,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      t_qamb     TYPE SORTED TABLE OF ty_qamb&lt;/P&gt;&lt;P&gt;        WITH NON-UNIQUE KEY prueflos,&lt;/P&gt;&lt;P&gt;      t_qamb_tmp TYPE        TABLE OF ty_qamb,&lt;/P&gt;&lt;P&gt;      t_mseg     TYPE HASHED TABLE OF ty_mseg&lt;/P&gt;&lt;P&gt;        WITH UNIQUE KEY mblnr mjahr zeile,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      i_qamb_tmp LIKE        TABLE OF iqamb  .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF NOT iqamb[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  i_qamb_tmp[] = iqamb[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SORT i_qamb_tmp BY prueflos.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  DELETE ADJACENT DUPLICATES FROM i_qamb_tmp COMPARING prueflos.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  SELECT prueflos&lt;/P&gt;&lt;P&gt;         zaehler&lt;/P&gt;&lt;P&gt;         mblnr&lt;/P&gt;&lt;P&gt;         mjahr&lt;/P&gt;&lt;P&gt;         zeile&lt;/P&gt;&lt;P&gt;    FROM qamb&lt;/P&gt;&lt;P&gt;    INTO TABLE t_qamb&lt;/P&gt;&lt;P&gt;    FOR ALL ENTRIES IN i_qamb_tmp&lt;/P&gt;&lt;P&gt;    WHERE prueflos EQ i_qamb_tmp-prueflos.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  IF sy-subrc EQ 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    DELETE t_qamb WHERE mblnr NE itab-mblnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    IF NOT t_qamb[] IS INITIAL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      t_qamb_tmp[] = t_qamb[].&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      SORT t_qamb_tmp BY mblnr mjahr zeile.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      DELETE ADJACENT DUPLICATES FROM t_qamb_tmp&lt;/P&gt;&lt;P&gt;        COMPARING mblnr mjahr zeile.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      SELECT mblnr&lt;/P&gt;&lt;P&gt;             mjahr&lt;/P&gt;&lt;P&gt;             zeile&lt;/P&gt;&lt;P&gt;             menge&lt;/P&gt;&lt;P&gt;        FROM mseg&lt;/P&gt;&lt;P&gt;        INTO TABLE t_mseg&lt;/P&gt;&lt;P&gt;        FOR ALL ENTRIES IN t_qamb_tmp&lt;/P&gt;&lt;P&gt;        WHERE mblnr EQ t_qamb_tmp-mblnr&lt;/P&gt;&lt;P&gt;        AND   mjahr EQ t_qamb_tmp-mjahr&lt;/P&gt;&lt;P&gt;        AND   zeile EQ t_qamb_tmp-zeile.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  LOOP AT iqamb.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    LOOP AT t_qamb INTO w_qamb&lt;/P&gt;&lt;P&gt;      WHERE prueflos EQ iqamb-prueflos.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      READ TABLE t_mseg INTO w_mseg&lt;/P&gt;&lt;P&gt;        WITH KEY mblnr = w_qamb-mblnr&lt;/P&gt;&lt;P&gt;                 mjahr = w_qamb-mjahr&lt;/P&gt;&lt;P&gt;                 zeile = w_qamb-zeile&lt;/P&gt;&lt;P&gt;                 TRANSPORTING&lt;/P&gt;&lt;P&gt;                   menge.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      CHECK sy-subrc EQ 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      tmp_menge = w_mseg-menge.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      tmp_mblnr = w_qamb-mblnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      tmp_mjahr = w_qamb-mjahr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      PERFORM addtoitab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  ENDLOOP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Jan 2008 14:50:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/nested-select-qurey-to-convert-into-normal/m-p/3355172#M805001</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-01-25T14:50:00Z</dc:date>
    </item>
  </channel>
</rss>

