<?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: query for sales document# in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-for-sales-document/m-p/2298594#M502163</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Write the query vbak,vbuk and vbpa,vbup,vbap as inner join and for all entries,so that you will have good performance..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 May 2007 16:51:11 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-05-18T16:51:11Z</dc:date>
    <item>
      <title>query for sales document#</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-for-sales-document/m-p/2298592#M502161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi experts, &lt;/P&gt;&lt;P&gt;I am a new ABAPer, I need your help, given below is my requirement&lt;/P&gt;&lt;P&gt;KUNNR--&amp;gt; ACT+store ---&amp;gt; input&lt;/P&gt;&lt;P&gt;role: ship to party SH&lt;/P&gt;&lt;P&gt;SALES_ORG - Sales organization -&amp;gt;1000&lt;/P&gt;&lt;P&gt;DISTR_CHAN - Distribution channel -&amp;gt;10&lt;/P&gt;&lt;P&gt;DIVISION - Division -&amp;gt;40&lt;/P&gt;&lt;P&gt;Open sales document - --&amp;gt; LFSTK &amp;lt;&amp;gt; 'C'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want all sales document#,total order qty related data with material# (Also other fields, if its necessary to identify)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In given below query what I have to change?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at I_ORDERSUMMARY  (this structure give me input)&lt;/P&gt;&lt;P&gt;select a&lt;SUB&gt;KUNNR a&lt;/SUB&gt;VBELN  appending table &amp;lt;b&amp;gt;I_VBAK&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;from VBAK as a inner join VBUK as b on a&lt;SUB&gt;VBELN = b&lt;/SUB&gt;VBELN&lt;/P&gt;&lt;P&gt; where KUNNR = I_ORDERSUMMARY-ACCT_STORE and&lt;/P&gt;&lt;P&gt;                VKORG = '1000' and&lt;/P&gt;&lt;P&gt;                VTWEG = '10' and&lt;/P&gt;&lt;P&gt;                LFSTK &amp;lt;&amp;gt; 'C'.&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;loop at &amp;lt;b&amp;gt;I_VBAK&amp;lt;/b&amp;gt;.&lt;/P&gt;&lt;P&gt;select VBELN POSNR MATNR KWMENG&lt;/P&gt;&lt;P&gt;appending table I_VBAP&lt;/P&gt;&lt;P&gt;from VBAP  where VBELN = I_VBAK-VBELN.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am getting more number of sales document#  in my output, instead of that I have to get back same o/p as i am getting in VA05 t-code.&lt;/P&gt;&lt;P&gt;how to add division code &amp;amp; Ship to party functionality in my query?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 May 2007 16:08:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-for-sales-document/m-p/2298592#M502161</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-18T16:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: query for sales document#</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-for-sales-document/m-p/2298593#M502162</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;in this case, you need to add the VBPA table for to obtain the SHIP TO, SOLD TO fields. the link is like with inner join.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 May 2007 16:47:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-for-sales-document/m-p/2298593#M502162</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-18T16:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: query for sales document#</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-for-sales-document/m-p/2298594#M502163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Write the query vbak,vbuk and vbpa,vbup,vbap as inner join and for all entries,so that you will have good performance..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 May 2007 16:51:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-for-sales-document/m-p/2298594#M502163</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-18T16:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: query for sales document#</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/query-for-sales-document/m-p/2298595#M502164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Neo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A few points about your code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From a functionality perspective:&lt;/P&gt;&lt;P&gt;a) Your code does not take care of DIVISION - Division -&amp;gt;40.&lt;/P&gt;&lt;P&gt;b) Your code does not take care of role: ship to party SH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From a performance perspective.&lt;/P&gt;&lt;P&gt;a) Select within a loop is never a good idea.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look at this code and let me know if it helps. You will have to test it because I do not have relevant data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;IF NOT i_ordersummary[] IS INITIAL.

  i_ordersummary_tmp[] = i_ordersummary[].
  SORT i_ordersummary_tmp BY kunnr.
  DELETE ADJACENT DUPLICATES FROM i_ordersummary COMPARING kunnr.

  SELECT vbeln
         kunnr
    FROM vbak
    INTO TABLE i_vbak
    FOR ALL ENTRIES IN i_ordersummary_tmp
    WHERE vkorg EQ '1000'
    AND   vtweg EQ '10'
    AND   spart EQ '40'
    AND   kunnr EQ i_ordersummary_tmp-kunnr.

  IF sy-subrc EQ 0.

    SORT i_vbak BY vbeln.

    SELECT vbeln
           lfstk
      FROM vbuk
      INTO TABLE i_vbuk
      FOR ALL ENTRIES IN i_vbak
      WHERE vbeln EQ i_vbak-vbeln.

    IF sy-subrc EQ 0.

      DELETE i_vbuk WHERE lfstk EQ 'C'.

      IF NOT i_vbuk[] IS INITIAL.

        SORT i_vbuk BY vbeln.

        SELECT vbeln
               posnr
               matnr
               kwmeng
          FROM vbap
          INTO TABLE i_vbap
          FOR ALL ENTRIES IN i_vbuk
          WHERE vbeln EQ i_vbuk-vbeln.

        IF sy-subrc EQ 0.

          SORT i_vbap BY vbeln
                         posnr.

          SELECT vbeln
                 posnr
            FROM vbpa
            INTO TABLE i_vbpa
            FOR ALL ENTRIES IN i_vbap
            WHERE vbeln EQ i_vbap-vbeln
            AND   posnr EQ i_vbap-posnr
            AND   parvw EQ 'WE'.
          IF sy-subrc EQ 0.
            SORT i_vbpa BY vbeln
                           posnr.
          ENDIF.

        ENDIF.

      ENDIF.

    ENDIF.

  ENDIF.

ENDIF.


w_index = 1.
LOOP AT i_vbak.

  LOOP AT i_vbap FROM w_index.

    IF i_vbap-vbeln GT i_vbak-vbeln.
      w_index = sy-tabix.
      EXIT.
    ELSEIF i_vbap-vbeln EQ i_vbak-vbeln.
      READ TABLE i_vbpa WITH KEY vbeln = i_vbap-vbeln
                                 posnr = i_vbap-posnr
                                 BINARY SEARCH
                                 TRANSPORTING NO FIELDS.
      IF sy-subrc EQ 0.
        i_output-vbeln  = i_vbak-vbeln .
        i_output-posnr  = i_vbap-posnr .
        i_output-kunnr  = i_vbak-kunnr .
        i_output-matnr  = i_vbap-matnr .
        i_output-kwmeng = i_vbap-kwmeng.
        APPEND i_output.
        CLEAR  i_output.
      ENDIF.
    ENDIF.

  ENDLOOP.

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>Fri, 18 May 2007 17:44:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/query-for-sales-document/m-p/2298595#M502164</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-05-18T17:44:42Z</dc:date>
    </item>
  </channel>
</rss>

