<?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: Simple ABAP query in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-abap-query/m-p/1154077#M118334</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wilbert - when I looked at your code, I had to admit to myself that it does look more efficient than the code I posted. I put both sets of code into a program and ran them both, trapping the run time. For 100 rows, my code ran more quickly; for 1000 records yours ran more quickly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you said optimization is an imperfect science. In the final analysis, it's up to the programmer to test his or her code in his or her environment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Feb 2006 04:25:26 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2006-02-15T04:25:26Z</dc:date>
    <item>
      <title>Simple ABAP query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-abap-query/m-p/1154074#M118331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to read table VBRK to see if VBELN fetched from table VBFA exists in VBRK when VBRK-FKART  = 'F8'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it does not exist for given FKART = 'F8' in VBRK, then error else print the value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I do this optimally ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Feb 2006 22:34:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-abap-query/m-p/1154074#M118331</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-14T22:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Simple ABAP query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-abap-query/m-p/1154075#M118332</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;something like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT ztest.

TABLES: vbfa, vbrk.

DATA: BEGIN OF vbfa_int OCCURS 0,
        vbeln LIKE vbfa-vbeln,
      END   OF vbfa_int.

SELECT vbeln FROM  vbfa
  INTO TABLE vbfa_int
  UP TO 100 ROWS.

SORT vbfa_int.
DELETE ADJACENT DUPLICATES FROM vbfa_int.
CHECK NOT vbfa_int[] IS INITIAL.

LOOP AT vbfa_int.
  SELECT fkart FROM  vbrk
    INTO vbrk-fkart
    WHERE vbeln = vbfa_int-vbeln.
    IF sy-subrc = 0.
      IF vbrk-fkart = 'F8'.
        WRITE: /001 vbfa_int-vbeln.
      ELSE.
* Error
      ENDIF.
    ELSE.
* Error
    ENDIF.
  ENDSELECT.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Feb 2006 22:55:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-abap-query/m-p/1154075#M118332</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-14T22:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: Simple ABAP query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-abap-query/m-p/1154076#M118333</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Often the simple questions are the hardest to answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There're are probably thousands of threads relating to optimizing internal table joins and they don't always agree. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is what I'd typically do.&lt;/P&gt;&lt;P&gt;I assume that you'd already have an internal table of VBFA entries... let's call it LT_VBFA.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;types :
  begin of ty_vbeln,
    vbeln type vbeln,
  end of ty_vbeln.

field-symbols :
  &amp;lt;fs_vbfa&amp;gt;   type ty_vbeln.

data :
  lt_vbfa         type sorted table of ty_vbeln
                  with non-unique key vbeln,
  lt_vbrk         type sorted table of ty_vbeln
                  with unique key vbeln.
constants :
  co_vbtyp_inv    type vbtyp value 'M',
  co_fkart_inv    type fkart value 'F2'.


* Simulated
Select vbeln up to 100 rows
  from vbfa
  into table lt_vbfa
  where vbtyp_n = co_vbtyp_inv. "invoice

check  lt_vbfa[] is not initial.

* VBRK call
select distinct vbeln
  from vbrk
  into table lt_vbrk
  for all entries in lt_vbfa
  where vbeln = lt_vbfa-vbeln
  and   fkart = co_fkart_inv.

loop at lt_vbfa assigning &amp;lt;fs_vbfa&amp;gt;.
  read table lt_vbrk transporting no fields
    with key vbeln = &amp;lt;fs_vbfa&amp;gt;-vbeln.
  if sy-subrc ne 0.
    write : / 'ERROR: ', &amp;lt;fs_vbfa&amp;gt;-vbeln.
  else.
    write : / 'OK   : ', &amp;lt;fs_vbfa&amp;gt;-vbeln.
  endif.
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;u&amp;gt;&amp;lt;b&amp;gt;SQL ANALYSIS&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt;&lt;/P&gt;&lt;P&gt;to the previous post... yes, I confess, I've done it that way too - as sometimes it's unavoidable.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;LOOP/SELECT :&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;This approach gets 1 DB hit per 1 record returned. For 100 entries you get 100 PREPARE and 100 FETCH operations&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;SELECT/'FOR ALL ENTRIES' :&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;I try to get less hits on the DB whenever possible.&lt;/P&gt;&lt;P&gt;This  approach gets expanded at the DB level to show every key ot LT_VBFA. On oracle systems... several lines get bunched up in one execution  (depending on the systems' max_blocking_factor ). On 100 run, on my local db... I only get 1 PREPARE operation and 20 FETCH operations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The bad side is that this is memory intensive.But at &amp;lt; 10000 lines this factor is normally livable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;GENERALLY : SELECT/JOIN&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;If I had to start from scratch, a typical approach would be to use SELECT with JOIN to combine tables. Though, seeing that VBFA is one of your tables it is probably not recommended... as it is a pretty darn big one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;READING VBFA&amp;lt;/b&amp;gt; Reading VBFA is tricky. If it was a single read, instead of SELECT, I'd recommend using 'RV_ORDER_FLOW_INFORMATION' or some similar BAPI . RV_ORDER_FLOW_INFORMATION is unreleased but it is the common approach to retrieving document flow.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AGAIN... this is a general scenario. Depending on requirement... some other methods may be better. (Optimization can take a whole book to expand)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Feb 2006 00:17:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-abap-query/m-p/1154076#M118333</guid>
      <dc:creator>wilbertsison</dc:creator>
      <dc:date>2006-02-15T00:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Simple ABAP query</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/simple-abap-query/m-p/1154077#M118334</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wilbert - when I looked at your code, I had to admit to myself that it does look more efficient than the code I posted. I put both sets of code into a program and ran them both, trapping the run time. For 100 rows, my code ran more quickly; for 1000 records yours ran more quickly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you said optimization is an imperfect science. In the final analysis, it's up to the programmer to test his or her code in his or her environment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Feb 2006 04:25:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/simple-abap-query/m-p/1154077#M118334</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-02-15T04:25:26Z</dc:date>
    </item>
  </channel>
</rss>

