Performance on select join vbap/vbak/vbep

Hello,
I would like to know how improve the performance (time-reponse) of my select :
SELECT
apmatkl  approdh apmatnr  aparktx  apvbeln apposnr  apnetwr  apkzwi3  apkzwi1  apmwsbp
epbmeng  epwmeng  epedatu  apvrkme  ap~brgew
INTO CORRESPONDING FIELDS OF TABLE p_tvbapcache
FROM vbap AS ap
INNER JOIN vbep AS ep ON  apvbeln = epvbeln AND apposnr = epposnr
INNER JOIN vbak AS ak ON  akvbeln = epvbeln AND apvbeln = akvbeln
WHERE ak~vbeln NOT LIKE '0005%'
AND ep~vbeln NOT LIKE '0005%'
AND ap~vbeln NOT LIKE '0005%'
AND ep~edatu IN date
AND ap~prodh IN nomencla
AND ak~auart IN canal
AND ap~matnr IN numero
AND apnetwr <> 0 AND apnetwr <> '0'
AND epwmeng <> 0 AND epwmeng <> '0'
AND epbmeng <> 0 AND epbmeng <> '0'
AND apkzwi1 <> 0 AND apkzwi1 <> '0'
AND ak~faksk <> 'Z3'.
The performance are very very very poor...
For information, there are 18.329.040 entries in VBAP table; VBAK : 485.437 entries ; VBEP : 18.304.173 entries
Many thanks for yours ideas,

Hi Coppalle,
Sometimes you need to have a bit more confidence.
Your WHERE-clause checks VBELN for all tables, but in an inner join they are already checked if VBELN is used in the relation.
To check number fields <> 0 <u>AND</u> also <> '0' is not required. Use either one (what you find easy to use), allthough <> 0 is slightly faster.
Since many records are in your tables, consider the following program detail.
DATA: p_tvbapcache_buf LIKE p_tvbapcache OCCURS 0,
      w_tvbapcache_buf LIKE p_tvbapcache.
SELECT ap~vbeln ap~posnr ap~matnr ap~matkl ap~prodh ap~arktx
       ap~netwr ap~kzwi3 ap~kzwi1 ap~mwsbp ap~vrkme ap~brgew
       ep~bmeng ep~wmeng ep~edatu
  INTO CORRESPONDING FIELDS OF TABLE p_tvbapcache_buf
  FROM vbap AS ap PACKAGE SIZE 10000
INNER JOIN vbep AS ep
    ON ap~vbeln = ep~vbeln
   AND ap~posnr = ep~posnr
INNER JOIN vbak AS ak
    ON ak~vbeln = ep~vbeln
   AND ap~vbeln = ak~vbeln
WHERE ak~auart IN canal
   AND ak~faksk <> 'Z3'.
  LOOP AT p_tvbapcache_buf INTO w_tvbapcache_buf.
    CHECK: vbeln NOT LIKE '0005%',
           prodh IN nomencla,
           matnr IN numero,
           netwr <> 0,
           kzwi1 <> 0,
           edatu IN date,
           wmeng <> 0,
           bmeng <> 0.
    APPEND w_tvbapcache_buf TO p_tvbapcache.
  ENDLOOP.
ENDSELECT.
And as last suggestion: I see that you use a lot of 'NEGATIVE' selections (this is selection by exclusion). In the database world this is a very bad way of selecting data, because it will not follow any key in a table. In my opinion you try and find a way of using at least a selection that can use a key.
Hope this gives you some directions,
Regards,
Rob.

Similar Messages

  • Performance in Inner Join on VBAK

    HI,
    For a customized report the select statement was written like this which is giving time out error for large data. How one can improve performance of following Inner Joins.
      SELECT  *
          INTO CORRESPONDING FIELDS OF TABLE it_tab
           FROM vbak as A INNER JOIN vbuk as B
                  ON Avbeln = Bvbeln
                INNER JOIN vbkd as C
                 ON Avbeln = Cvbeln
      WHERE    A~vbeln      IN  so_vbeln
         AND   A~audat      IN  so_audat
         AND   A~auart      IN  so_auart
         AND   A~augru      IN  so_augru
         AND   A~faksk    IN  so_faksp
         AND   A~vkorg      IN  so_vkorg
         AND   A~vtweg      IN  so_vtweg
         AND   A~spart      IN  so_spart
         AND   A~vkbur      IN  so_vkbur
         AND   A~vkgrp      IN  so_vkgrp
         AND   A~vsbed      IN  so_vsbed
         AND   A~kunnr      IN  so_kunnr
         and   B~gbstk      IN  so_gbstx
         AND   C~posnr       =  '000000'.
    Thanks
    anya
    Moderator message: FAQ, it all depends on the content of the so_ ranges at runtime.
    Please Read before Posting in the Performance and Tuning Forum
    Edited by: Thomas Zloch on Nov 1, 2010 11:57 AM

    Others have already responded, and I would only like to dwell on the answers for a short while. Or maybe rather the question.
    This question is typical for the inexperienced developer. This particular question is actually a little different, because there is a straight answer: there is no difference. For most questions of this type the answer is "it depends", because one
    particular syntax can happen to perform better with one set of data and indexes, but with a different data/index profile another syntax gives better result.
    Ideally, as long as two queries are logically equivalent, the syntax should not matter at all, because the optimizer should always figure out the best way to achieve the result. In practice, this is not the case, because there are lots of limitaitons in
    an optimizer in an RDBMS.
    While it certainly can matter for performance how you write your queries, that is not what you should focus on. What you should focus is to express your query as clearly as possible, and make sure that you have the relevant indexes in place. There is one
    rule when it comes to query-writing you should take your heart: never entable a column in a condition in an expression, because that is likely to render index on that column useless.
    For this particular question, the answer is that as you long as you write code for SQL Server, use the JOIN syntax. But if you use that in the Oracle world, you may get funny looks from people. It's a different culture over there...
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Performance issue with joins on table VBAK, VBEP, VBKD and VBAP

    hi all,
    i have a report where there is a join on all 4 tables VBAK, VBEP, VBKD and VBAP.
    the report is giving performance issues because of this join.
    all the key fields are used for the joining of tables. but some of the non-key fields like vbap-vstel, vbap-abgru and vbep-wadat are also part of select query and are getting filled.
    because of these there is a performance issue.
    is there any way i can improve the performance of the join select query?
    i am trying "for all entries" clause...
    kindly provide any alternative if possible.
    thanks.

    Hi,
    Pls perform some of the below steps as applicable for the performance improvement:
    a) Remove join on all the tables and put joins only on header and item (VBAK & VBAP).
    b) code should have separate select for VBEP and VBKD.
    c) remove the non key fields from the where clause. Once you retrieve data from the database into the internal table, sort the table and delete the entries which are not part of the non-key fields like vstel, abgru and wadat.
    d) last option is you can create index in the VBAP & VBEP table with respect to the fields vstel, abgru & wadat ( not advisable)
    e) buffering option on database tables also possible.
    f) select only the fields into the internal table that are applicable for the processing logic and also the select query should contaian the field names in the same order as mentioned in the database table.
    Hope this helps.
    Regards
    JLN

  • Poor Performance on Inner Join of VBUP and VBAK

    The following select is performing poorly, i.e., ST05 Execution is 1, Records is 246, but Time/Exec 94,499,272. Very poor.
    SELECT VBUPVBELN VBUPPOSNR VBAK~KUNNR
             FROM VBUP INNER JOIN VBAK
             ON VBUPVBELN = VBAKVBELN
             WHERE VBAK~VBTYP EQ 'C'     
               AND VBUP~LFSTA NE 'C'
               AND VBUP~LFGSA NE 'C'.
    VBUP has a custom index, Z01, on MANDT, LFSTA, LFGSA. There is no index on VBAK.
    The Explain under ST05 indicates an Est. I/O cost of 73.94 for a Clustered Index Seek on [VBAK].[VBAK0], and an Est. I/O cost of 81.34 for an Index Seek on [VBUP].[VBUPZ01].
    There is no index on VBAK, so I assume that's the first problem. But I don't understand why the index on VBUP does not appear to be helping. This the ST05 Explain: Index Seek WHERE: [PCI].[pci].[VBUP].[LFGSA] as [T_00].[LFGSA]<[@P4] OR [PCI].[pci].[VBUP].[LFGSA] as [T_00].[LFGSA]>[@P4] : [VBUP].MANDT EQ [@P1] ORDERED 1.
    Is my index even being used?  Any ideas how I can speed this up?
    Thanks in advance for your help.
    Beth

    tis the negative selection which is causing the problem..try to avoid selection using not equal to.
    try this.
    ranges : r_lfsta for vbup-lfsta.
    r_lfsta-sign = 'I'.
    r_lfsta-option = 'EQ'.
    r_lfsta-low = ' '.
    append r_lfsta.
    r_lfsta-low = 'A'.
    append r_lfsta.
    r_lfsta-low = 'B'.
    append r_lfsta.
    do similar for r_lfgsa also.
    SELECT VBUP~VBELN
                 VBUP~POSNR
                 VBAK~KUNNR
    FROM VBUP INNER JOIN VBAK
    into corresponding fields of table t_vbakvbup
    ON VBUPVBELN = VBAKVBELN
    WHERE VBAK~VBTYP EQ 'C'
    AND VBUP~LFSTA in r_lfsta
    AND VBUP~LFGSA in r_lfgsa. 
    or
    SELECT VBUP~VBELN
                 VBUP~POSNR
                 VBAK~KUNNR
    vbup~lfsta
    vbup~lfgsa
    FROM VBUP INNER JOIN VBAK
    into corresponding fields of table t_vbakvbup
    ON VBUPVBELN = VBAKVBELN
    WHERE VBAK~VBTYP EQ 'C' .
    delete t_vbakvbup where lfsta ne 'C'.
    delete t_vbakvbup where lfgsa ne 'C'.

  • Performance Impovement for Join

    I have the following join statement. I have 220,000 records ... when I run this program, it times out. Can any one suggest performance impovement?
      SELECT vbapvbeln  vbapposnr  vbapkwmeng  vbapmatnr
             vbapwerks  vbapkdmat  vbapposex   vbakauart
             vbakkunnr  vbakvdatu  vbepedatu   lipsvbeln
             lipsposnr  lipslfimg  marcdispo   marcbeskz "--> PV
             maktmaktx  marameins  vbkdihrez   vbkdempst
             vbkdbstkd  vbkdbstkd_e vbpa~ablad
      INTO TABLE lt_orders_t
      FROM vbak INNER JOIN vbap
                  ON ( vbakvbeln = vbapvbeln )
                INNER JOIN vbep
                  ON ( vbapposnr = vbepposnr AND vbapvbeln = vbepvbeln )
                LEFT OUTER JOIN lips
                  ON ( vbapvbeln = lipsvgbel AND vbapposnr = lipsvgpos )
                LEFT OUTER JOIN marc
                  ON ( vbapmatnr = marcmatnr AND vbapwerks = marcwerks )
                LEFT OUTER JOIN makt
                  ON ( vbapmatnr = maktmatnr AND makt~spras = 'E'        )
                LEFT OUTER JOIN mara
                  ON ( vbapmatnr = maramatnr )
                LEFT OUTER JOIN vbkd
                  ON ( vbapvbeln = vbkdvbeln AND vbapposnr = vbkdposnr )
                LEFT OUTER JOIN vbpa
                  ON ( vbapvbeln = vbpavbeln AND vbpa~posnr = '000010' AND
                       vbpa~parvw = 'WE'       )
      WHERE vbak~vbeln IN s_vbeln AND
            vbep~etenr = '0001'   AND
            vbap~posnr IN s_posnr AND
            vbap~werks IN s_werks AND
            vbak~auart IN s_auart AND
            vbak~kunnr IN s_kunnr AND
            vbak~vbtyp IN s_vbtyp AND
            vbap~matnr IN s_matnr AND
            vbep~ettyp IN s_ettyp AND
            vbep~edatu IN s_edatu.

    Hi PV,
    As others have mentioned you really need to break the statement down. 3 joins is usually pushing it (depending on the tables). By the way, you can go to SE12 and look up each table. On the main screen you will see a pushbutton saying Indexes I think. Click on it and it will show you the secondary indexes for that table. There may be some or none defined. They may be SAP defined or customer defined (Z).
    Keep your inner joins on vbak, vbap and vbep. The resulting table will be used as your driver for the other tables.
    You can create another inner join of mara, marc and makt.
    Use your driver table as For All Entries for the other tables.
    If you keep your driver table to be as shown, create another table with the first 5 fields.( vbeln, posnr, kwmeng, matnr, werks). The reason for this is so you can load the table with:
    It_newtab[] = It_orders_t[].
    All you want from the new table is matnr werks.
    Sort it_newtab by matnr werks.
    Delete adjacent duplicates from i_newtab comparing matnr werks.
    Now you can use it_newtab as your driver for marc-mara-makt join. The reason is that if you have 220,000 records, when you narrow down the material/plant combinations you will probably have only a few hundred materials. So your For All entries will be a table of a few hundred instead of 200 thousand.
    The result will be in a new table it_materials. When you read this table, don't forget to sort it by matnr and plant first. And READ with Binary Search.
    Once you have all your other smaller tables created. As with it_materials, SORT and READ with BINARY SEARCH, as you loop through your driver table and populate the missing data from the smaller tables.
    I think you will end up with 5 Select statements.
    Indexes are important. Once you have split out the Select statements, if the code is still running unacceptably slow, you can use ST05 to see what indexes are being used and see if new indexes need to be created to help your cause.
    You'll probably have to involve the Basis team to help you with your new indexes and they can help with the analysis of your ST05 results as well. Indexes must be created correctly in the proper order, or they may not be effective.
    Hope this helps.
    Filler

  • Inner Join. How to improve the performance of inner join query

    Inner Join. How to improve the performance of inner join query.
    Query is :
    select f1~ablbelnr
             f1~gernr
             f1~equnr
             f1~zwnummer
             f1~adat
             f1~atim
             f1~v_zwstand
             f1~n_zwstand
             f1~aktiv
             f1~adatsoll
             f1~pruefzahl
             f1~ablstat
             f1~pruefpkt
             f1~popcode
             f1~erdat
             f1~istablart
             f2~anlage
             f2~ablesgr
             f2~abrdats
             f2~ableinh
                from eabl as f1
                inner join eablg as f2
                on f1ablbelnr = f2ablbelnr
                into corresponding fields of table it_list
                where f1~ablstat in s_mrstat
                %_HINTS ORACLE 'USE_NL (T_00 T_01) index(T_01 "EABLG~0")'.
    I wanted to modify the query, since its taking lot of time to load the data.
    Please suggest : -
    Treat this is very urgent.

    Hi Shyamal,
    In your program , you are using "into corresponding fields of ".
    Try not to use this addition in your select query.
    Instead, just use "into table it_list".
    As an example,
    Just give a normal query using "into corresponding fields of" in a program. Now go to se30 ( Runtime analysis), and give the program name and execute it .
    Now if you click on Analyze button , you can see, the analysis given for the query.The one given in "Red" line informs you that you need to find for alternate methods.
    On the other hand, if you are using "into table itab", it will give you an entirely different analysis.
    So try not to give "into corresponding fields" in your query.
    Regards,
    SP.

  • Problems performing an outer join

    I added some criteria to the following sql statement to get the relationship.
    ie ('Husband', 'Wife','Father','Mother','Step Mother','Step Father','Father in-law','Mother in-law')
    The problem is that I also want to beable to display those that are not in this category. So I thought that I could do and outer join such as
    and hcr.relationship_name(+) in ('Husband',
    'Wife',
    This does not work. Can anyone recommend how I can perform an outer join to get that information that does not meet the in statement?
    thanks
    select      hac.case_id,hac.relation_to_hoh_id,hcr.RELATIONSHIP_NAME,
              decode(ha.GENDER_ID,1,'(F)',2,'(M)',3,'(T)') || ' Adult ' ||
              round((trunc(sYSdate) - ha.DATE_OF_BIRTH) / 365,0) info, 0 sort_by
    from      dpss_hts.hts_applicant ha,
              dpss_hts.hts_applicant_case hac,
              dpss_hts.certa_relationship hcr          
    where      ha.applicant_id = hac.applicant_id
    and      round((trunc(sYSdate) - ha.DATE_OF_BIRTH) / 365,0) > 17
    and      hac.relation_to_hoh_id = hcr.RELATIONSHIP_ID
    and hcr.relationship_name in ('Husband',
    'Wife',
    'Father',
    'Mother',
    'Step Mother',
    'Step Father',
    'Father in-law',
    'Mother in-law')

    If I understand correctly, you want to display the relationship_name only if it is one of those in the list. If it is not, then you want to display the rest of the data, but not the realtionship_name.
    Two approaches spring to mind. You can use an in-line view to select only the relationship_names you are interested in, then outer join to that in-line view like:
    SELECT hac.case_id, hac.relation_to_hoh_id, hcr.relationship_name,
           DECODE(ha.gender_id, 1, '(F)', 2, '(M)', 3, '(T)')||' Adult '||
           ROUND((TRUNC(sysdate) - ha.date_of_birth) / 365, 0) info, 0 sort_by
    FROM dpss_hts.hts_applicant ha, dpss_hts.hts_applicant_case hac,
         SELECT relationship_id, relationship_name
         FROM dpss_hts.certa_relationship
         WHERE hcr.relationship_name in ('Husband', 'Wife', 'Father', 'Mother',
                                         'Step Mother', 'Step Father',
                                         'Father in-law', 'Mother in-law') hcr
    WHERE ha.applicant_id = hac.applicant_id and
          ROUND((TRUNC(sysdate) - ha.date_of_birth) / 365, 0) > 17 and
          hac.relation_to_hoh_id = hcr.relationship_id(+)Another alternative would be do leave the current join intact, lose the predicate on relationship_name and do the dciding in the SELECT list.
    Something like:
    SELECT hac.case_id, hac.relation_to_hoh_id,
           CASE WHEN hcr.relationship_name IN ('Husband', 'Wife', 'Father',
                                               'Mother', 'Step Mother',
                                               'Step Father', 'Father in-law',
                                               'Mother in-law') THEN hcr.relationship_name
                ELSE NULL END relationship_name,
           DECODE(ha.gender_id, 1, '(F)', 2, '(M)', 3, '(T)')||' Adult '||
           ROUND((TRUNC(sysdate) - ha.date_of_birth) / 365, 0) info, 0 sort_by
    FROM dpss_hts.hts_applicant ha, dpss_hts.hts_applicant_case hac,
         dpss_hts.certa_relationship hcr
    WHERE ha.applicant_id = hac.applicant_id and
          ROUND((TRUNC(sysdate) - ha.date_of_birth) / 365, 0) > 17 and
          hac.relation_to_hoh_id = hcr.relationship_idHTH
    John

  • How to perform a self-join in WebI?

    Post Author: willgreenland
    CA Forum: WebIntelligence Reporting
    I want to perform a self-join on a table in WebI, in order to achieve the following result (of course, if there is another way of doing this I'd be glad to hear it):
    I have a table that lists the department in which an employee is located at given dates in the past:
    EMPLID    DEPT    DATE
    123                Sales    2007...
      I want to use this table to track migration between departments, in other words I want to produce the following output table, showing how in 2008, 5 employees moved from Sales to Marketing (etc):DEPT_A    DATE_A    DEPT_B    DATE_B    COUNT(EMPLID) Sales        2007          Mrkting      2008             5...
    In order to do this in SQL, I would do the following:
    SELECT a.DEPT, b.DEPT, count(distinct EMPLID)FROMEMPL_DEPT a, EMPL_DEPT b        // note the self-join hereWHERE( a.EMPLID = b.EMPLID AND a.DATE = '2007' AND b.DATE = '2008' )GROUP BY a.DEPT, b.DEPT;
    Is there a way of doing this in WebI, ideally without resorting to manual SQL editing (I want this to be a report that other users can make sense of without necessarily getting into the SQL)?

    Post Author: amr_foci
    CA Forum: WebIntelligence Reporting
    you cant do something like that in the WebI directly, you have to manager that at the unvinerse level first
    good luck

  • Regarding select join query

    hey guys,
    I have below inputs for the screen
          ZWADAT_IST -Actual goods movement date
          ZKUNNR- shipto party
          ZVGBEL-
          ZVBELN-
          ZPOSNR-
          ZBUNKATU-
    Depends on the input, i have to retrieve necessary fields from various related tables and display in screen .
    ZSDTB_LOT is the add on table where we can access few fields as below. Now i want to write QUERY using join to fetch the fields from different tables like LIKP,LIPS,ZSDTB_LOT,ADRC according to the inputs
    and display in table control.
    I am not good in writing SELECT JOIN statement to retrieve fields in effecient way. could somebody help me
    giving equavalent code for this...
    <b>
    Select
          LIKP-WADAT_IST,
          LIKP-VSTEL(shipping point)
          LIKP-KUNNR
          LIKP-LFART(delievery type)
          LIPS-VKBUR
          LIPS-MATNR
          LIPS-VGBEL
          ZSDTB_LOT-VBELN
          ZSDTB_LOT-BUNKATSU
          ZSDTB_LOT-POSNR
          ZSDTB_LOT-LOTB
          ZSDTB_LOT-LGMNG
          ADRC-NAME1
    FROM ZSDTB_LOT,LIKP,LIPS,ADRC
    WHERE WADAT_IST IN ZWADAT_IST AND
          KUNNR IN ZKUNNR AND
          VGBEL IN ZVGBEL AND
          VBELN IN ZVBELN AND
          POSNR IN ZPOSNR AND
          BUNKATU IN ZBUNKATU.</b>
    ambichan.

    I will try to avoid a big join on so many tables. Instead I will do something like this.
    DATA: BEGIN OF deliveries OCCURS 0,
            vbeln     LIKE likp-vbeln,
            lfart     LIKE likp-lfart,
            wadat_1st LIKE likp-wadat_1st,
            vstel     LIKE likp-vstel,
            kunnr     LIKE likp-kunnr,
            posnr     LIKE lips-posnr,
            matnr     LIKE lips-matnr,
            vkbur     LIKE lips-vkbur,
            vgbel     LIKE lips-vgbel.
    DATA: END OF deliveries.
    DATA: BEGIN OF ztab_entries OCCURS 0,
            vbeln    LIKE zsdtb_lot-vbeln,
            posnr    LIKE zsdtb_lot-posnr,
            lotb     LIKE zsdtb_lot-lotb,
            lgmng    LIKE zsdtb_lot-lgmng,
            bunkatsu LIKE zsdtb_lot-bunkatsu.
    DATA: END OF ztab_entries.
    SELECT likp~vbeln likp~lfart likp~wadat_1st
           likp~vstel likp~kunnr lips~posnr
           lips~matnr lips~vkbur lips~vgbel
      FROM likp as likp INNER JOIN lips as lips
        ON likp~vbeln = lips~vbeln
      INTO TABLE deliveries
    WHERE lips~vbeln IN zvbeln
       AND lips~posnr IN zposnr.
    IF NOT deliveries[] IS INITIAL.
      DELETE deliveries WHERE NOT
            ( wadat_1st IN zwadat_1st AND
              kunnr     IN zkunnr     AND
              vgbel     IN zvgbel ).
    ENDIF.
    SELECT vbeln posnr lotb
           lgmng bunkatsu
      FROM zsdtb_lot FOR ALL ENTRIES IN deliveries
      INTO TABLE ztab_entries
    WHERE vbeln = deliveries-vbeln
       AND posnr = deliveries-posnr.
    IF NOT ztab_entries[] IS INITIAL.
      DELETE ztab_entries WHERE NOT bunkatu IN zbunkatu.
    ENDIF.
    *-- Once we have these two internal tables then we can
    *   prepare the final table by looping through them
    SORT deliveries BY vbeln posnr.
    SORT ztab_entries BY vbeln posnr.
    LOOP AT deliveries.
      CLEAR ztab_entries.
      READ TABLE ztab_entries WITH KEY vbeln = deliveries-vbeln
                                       posnr = deliveries-vbeln
                            BIANRY SEARCH.
      SELECT SINGLE name1 INTO final_tab-name1
                          FROM KNA1
                         WHERE kunnr = deliveries-kunnr.
      MOVE-CORRESPONDING: deliveries   TO final_tab,
                          ztab_entries TO final_tab.
      APPEND final_tab.
      CLEAR final_tab.
    ENDLOOP.
    This way you will be selecting records from the database with the index of the primary key and then you can manipulate the selected entries as you wish.
    Hope this helps,
    Srinivas

  • How to perform a select op on a table whose name is contained by a variable

    I am using Oracle SQL*Plus client.
    declare
    tablename_var varchar(10); LOOK HERE
    date_var date;
    begin
    select sysdate
    into date_var
    from &tablename_var; LOOK HERE
    dbms_output.put_line('The system date is '||date_var);
    end;
    The above code prompts the user to enter a value for the variable tablename_var, once the user enters 'dual' on prompt... The system date is given as output.
    declare
    tablename_var varchar(10):='dual'; LOOK HERE
    date_var date;
    begin
    select sysdate
    into date_var
    from tablename_var; LOOK HERE
    dbms_output.put_line('The system date is '||date_var);
    end;
    This code fails and gives an error. I understand. Engine interprets it as... trying to perform a select operation on a variable, and says a table or a view is expected.
    Can someone please tell me what to do, to perform a select operation on a table whose name is contained by a variable, like above?

    Hi,
    Welcome to the forum!
    You need Dynamic SQL if the table- or column names are variables.
    Getting the current date isn't a good example; you could get that without a query simply by saying
    date_var := SYSDATE;Also, SELECT ... INTO will raise an error if the query does not return exactly 1 row.
    In the example below, let's get the latest entry_date from a given table:
    For example:
    declare
         tablename_var     varchar(10);
         date_var      date;
         sql_txt           VARCHAR2 (1000);
    begin
         tablename_var := 'table_x;
         sql_txt := 'select  MAX (entrydate)'
              || '  from  ' || tablename_var;
         dbms_output.put_line (sql_txt || ' = sql_txt');    -- Not essential, but recommended
         EXECUTE IMMEDIATE  sql_txt  INTO date_var;
         dbms_output.put_line ('The latest entry_date is ' || date_var);
    end;Dynamic SQL involves creating a string that contains the SQL statement. Displaying the string is purely optional, of course, but it's a very good idea when writing and de-bugging code. Remember to comment-out or delete the display before moving the code into Production.
    For an exercise, make the column name a variable, instead of the hard-coded entry_date.
    Edited by: Frank Kulash on Nov 5, 2009 9:20 AM

  • Relation between vbap vbak aukp cabnt cawnt..............

    hi ..
    I am working on project. I want to know the relationship between between the vbap vbak aukp cabnt and cawnt tables.
    I want to get related data from all the mentioned tables through field augr in vbap which is for season in our project and kdmat which is style number.it is a garment industry project.
    Please help me in doing this.

    Hi
    VBAK and VBAP are sales order related Tables
    we use CABN,CABNt and AUSP(it is not AUKP) for getting the characteristic data
    Do you wants to fetch the Material characteristics or what?
    better use the following
    BAPI's:
    BAPI_OBJCL_GETDETAIL
    BAPI_OBJCL_CHANGE
    or use the fun module:
    CLAF_CLASSIFICATION_OF_OBJECTS.
    Reward points for useful Answers
    Regards
    Anji

  • VBAP, VBAK and KNA1

    Hey SD experts,
    I would like to link those three SAP tables :
    VBAP, VBAK and KNA1 in order to create a query.
    VBAP is the principal table, VBAK and KNA1 are additional ones.
    What intermediate table should I use to make it possible ?
    Thank you,
    Bahia.

    I'll explain to you in details:
    I'm trying to create an infoset.
    I choose "direct read of table" : VBAP
    Than, I add VBAK : VBAP-VBELN = VBAK-VBELN
    Than, KNA1: KNA1-KUNNR = VBAK-KUNNR
    When I try to generate the infoset, I get this warning message:
    Access error in code for table KNA1,  KNA1 has sequence number 01
    Fields from VBAK are not assigned to a field group
    Fields from KNA1 are not assigned to a field group
    Thank you

  • Select Join problem

    Hi Experts,
          I need your help on this.  I really don't know what's wrong with my select statment.  Please let me know what went wrong.  I'm not sure if select join statement allows parameters for select-options.  Below is my select statement.  Thanks.
      SELECT tbtcojobname tbtcplistident
             INTO CORRESPONDING FIELDS OF TABLE itab
        FROM tbtco JOIN TBTCP ON ( tbtcojobcount = tbtcpjobcount )
        WHERE tbtco~status = 'F'
          AND tbtco~jobname IN P_SEARCH
          AND tbtco~enddate IN p_date
          AND tbtcp~listident IN p_spool.
      IF sy-subrc = 0.
        APPEND itab.
        CLEAR itab.
      ENDIF.
    Anna

    Just to give you an idea:  Here's what I did.
    SELECT-OPTIONS: p_search FOR TBTCO-jobname,
                    p_date FOR TBTCO-enddate,
                    p_spool FOR TBTCP-listident.
    DATA: BEGIN OF itab OCCURS 0,
            sp_name TYPE tbtco-jobname,
            br_code(1),
            dumon(7),
            sp_numb TYPE TSP01-rqident,
            ofc(12),
          END OF itab.
    SELECT tbtcojobname tbtcplistident
             INTO CORRESPONDING FIELDS OF TABLE itab
        FROM tbtco JOIN TBTCP ON ( tbtcojobcount = tbtcpjobcount )
        WHERE tbtco~status = 'F'
          AND tbtco~jobname IN P_SEARCH
          AND tbtco~enddate IN p_date
          AND tbtcp~listident IN p_spool.
      IF sy-subrc = 0.
        APPEND itab.
        CLEAR itab.
      ENDIF.

  • Performance Issue: Select From BSEG & BKPF

    Hi experts,
    Performance issue on the select statements; how can I improve the performance?
    Select Company Code (BUKRS)
    Accounting Document Number (BELNR)
                        Document Type (BLART)
                        Posting Date in the Document (BUDAT)
                        Document Status (BSTAT)
                        Reversal Document or Reversed Document Indicator (XREVERSAL)
               From Accounting Document Header (BKPF)
                 Into I_BKPF
             Where BKPF-BUKRS = I_VBAK-BUKRS_VF
           BKPF-BLART = ‘KI’
                        BKPF-BUDAT = SY-DATUM – 2 days
                        BKPF-BSTAT = Initial
                        BKPF-XREVERSAL <> ‘1’ or ‘2’
    Select Company Code (BUKRS)
                        Accounting Document Number (BELNR)
                        Assignment Number (ZUONR)
                        Sales Document (VBEL2)
                        Sales Document Item (POSN2)
                        P & L Statement Account Type (GVTYP)
                From Accounting Document Segment (BSEG)
                  Into I_BSEG
              Where BSEG-BUKRS = I_VBAK-BUKRS
            BSEG-VBELN = I_VBAK-VBEL2
            BSEG-POSN2 = I_VBAP-POSNR
                 BSEG-BELNR = I_BKPF-BELNR
                         P & L Statement Account Type (GVTYP) = ‘X’

    Hi,
    to improve the performance, you can use the secondary indices viz., BSIK / BSAK, BSID / BSAD, BSIS.
    Hope this helps.
    Best Regards, Murugesh AS

  • Performance problems selecting form vbak and vbap

    Hello,
    I am try to select data from the vbak and vbap databasetables. The tables have more than a million of entries. I tried my best with two related selectstatements and the 'FOR All ENTRIES' syntax. The query takes more than 30 minutes. Is there a more efficient way than the following query, for example an inner join?. Tanks.
    Regards, Lars.
    FORM firstselect.
       SELECT  kvkorg kvtweg kspart kauart k~kunnr
              kvsbed kaugru kvbeln kmandt
      FROM VBAK AS k
      INTO CORRESPONDING FIELDS OF TABLE t_outtab1
      WHERE  k~vkorg IN s_vkorg AND
             k~vtweg IN s_vtweg AND
             k~spart IN s_spart AND
             k~auart IN s_auart AND
             k~kunnr IN s_kunnr AND
             k~vsbed IN s_vsbed AND
             k~augru IN s_augru AND
             k~vbeln IN s_vbeln.
    ENDFORM.
    FORM secondselect.
         SELECT  pposnr pvstel p~werks
                  pabgru pmatnr p~kwmeng
                  pzzurmeng pvrkme pmandt pvbeln
          FROM VBAP AS p
          INTO CORRESPONDING FIELDS OF TABLE t_outtab2
              FOR ALL ENTRIES IN t_outtab1
          WHERE
              p~vstel IN s_vstel AND
              p~werks IN s_werks AND
              p~matnr IN s_matnr AND
              p~abgru IN s_abgru AND
             t_outtab1-mandt = p~mandt AND
              p~vbeln = t_outtab1-vbeln.
    ENDFORM.

    FORM firstselect.
    SELECT vkorg
           vtweg
           spart
           auart
           kunnr
           vsbed
           augru
           vbeln
           mandt
           FROM VBAK 
           INTO TABLE t_outtab1
    WHERE vkorg IN s_vkorg AND
    vtweg IN s_vtweg AND
    spart IN s_spart AND
    auart IN s_auart AND
    kunnr IN s_kunnr AND
    vsbed IN s_vsbed AND
    augru IN s_augru AND
    vbeln IN s_vbeln.
    ENDFORM.
    FORM secondselect.
    SELECT posnr
           vstel
           werks
           abgru
           matnr
           kwmeng
           zzurmeng
           vrkme
           mandt
          vbeln
      FROM VBAP TABLE t_outtab2
    FOR ALL ENTRIES IN t_outtab1
    WHERE  vbeln = t_outtab1-vbeln
    AND vstel IN s_vstel AND
    werks IN s_werks AND
    matnr IN s_matnr AND
    abgru IN s_abgru .
    ENDFORM.
    Hope this helps u.
    I will get u back with more answers.
    One more important thing see that the order which u r using in the select query is the same as that in the table this will affect the performs a lot.
    <i><b>The first field should be the vbeln and then see the order and change that first and the same order should be in the internal table taht u r defining also.
    If u do these things surely u can improve performance.</b></i>
    Message was edited by: Judith Jessie Selvi

Maybe you are looking for

  • Update supplier bank account details using open Interface

    In R12, how do you update/create the supplier bank accounts for existing supplier and supplier site? Is it correct that the bank account details cannot be imported individually and it can only be imported along with the supplier or supplier site? Ple

  • ICal To-Do's and the iPhone Calendar

    Why is it that at this stage of development, Apple has yet to offer a solution to manage and sync iCal to-do's with the iPhone Calendar? Am I missing something? It seems obvious that Apple is giving third party developers the opportunity to write the

  • RE Customization

    Dear SAP Users, Please let me know on how to Start with SAP RE (Real Estate) Customization.  While prepareing Sales Order , is there any reference with Objects like Business entity, property or lot. Please explain. regards, GHS.

  • Pro Application Support 4.0.1 - use with FCP 5, etc?

    Apple has released "Pro Application Support 4.0.1" (see http://www.apple.com/support/downloads/proapplicationsupport401.html) What's not clear is whether this is only for users of Final Cut Studio 2, or do these updates work with/apply to previous ge

  • Table, CommandToolbarButton, Control Flow

    hi All, I'm using JDev11g, ADF BC, IE7, Windows XP(OS). I have a problem in designing a functionality like using a SelectOneCheckbox i select a row in the table. On Click of the button ShowDetails the data which is displayed as a row should be displa