Issue regarding Select Query

Hello experts,
I want a join on table ekpo & mbew(for valuation class).
But its not working.
if valclass is initial.
select  aebeln aebelp atxz01 amatnr abukrs awerks a~menge
a~mtart
b~bklas
from  ekpo  as a inner join  mbew as b on bmatnr eq amatnr
into corresponding fields of table ekpo_mbew
where  ( a~matnr eq mat_num ) and
( a~bukrs eq compcode ) and
( a~werks eq plant ) and
( a~mtart eq mat_type ) and
b~bklas  in ('3001','3045' ,'3006','3055','3065') and
( amatnr eq bmatnr ).
else.
select  aebeln aebelp atxz01 amatnr abukrs awerks a~menge
a~mtart
b~bklas
from  ekpo  as a inner join  mbew as b on bmatnr eq amatnr
into corresponding fields of table ekpo_mbew
where  ( a~matnr eq mat_num ) and
( a~bukrs eq compcode ) and
( a~werks eq plant ) and
( a~mtart eq mat_type ) and
( b~bklas  in valclass ) and
( amatnr eq bmatnr ).
endif.
Plz tell where I m wrng.
Ravi.

Hi,
     Try the below code,
SELECT aebeln aebelp atxz01 amatnr abukrs awerks a~menge
a~mtart
b~bklas
FROM ekpo AS a INNER JOIN mbew AS b ON bmatnr EQ amatnr INTO CORRESPONDING FIELDS OF TABLE ekpo_mbew
WHERE  a~matnr EQ mat_num AND
               a~bukrs EQ compcode AND
               a~werks EQ plant AND
a~mtart EQ mat_type AND
b~bklas IN ('3001','3045' ,'3006','3055','3065').
ELSE.
SELECT aebeln aebelp atxz01 amatnr abukrs awerks a~menge
a~mtart
b~bklas
FROM ekpo AS a INNER JOIN mbew AS b
ON bmatnr EQ amatnr
INTO CORRESPONDING FIELDS OF TABLE ekpo_mbew
WHERE  a~matnr EQ mat_num AND
a~bukrs EQ compcode  AND
a~werks EQ plant AND
a~mtart eq mat_type AND
b~bklas IN valclass .
Note :- ( amatnr eq bmatnr ) this is not necessary as the INNER JOIN is on that condition itself.
Regards
Bala Krishna

Similar Messages

  • Regarding select query Issue

    Hi ABAPERS,
          I had written one written one 'select single' query to retrieve the data from PRPS table.
    but what the data was selecting for OBJNR (Object number)field based on PSPNR(WBS element) .
    That OBJNR values in the report is totally different from the database table OBJNR  values.How its possible
    I am not getting.So can anyone please help me regarding this...
    Thanks and Regards
    Deepa

    Hi deepa,
    Pass the values to the select query where clause as you can see the values in SE16 display.(This is external format)
    If a table field as conversion routine, then SAP dosplay some thing on screen and store some thing else in data base.
    To check conversion exit go to domain of that field. Here you can see the routine used.
    For example you can check domain MATNR. Externally it display with leading zeros. But internally it stores with out zeros.
    Thanks,
    Vinod.

  • Performance issue with select query

    Hi friends ,
    This is my select query which is taking so much time to retrive the records.CAn Any one help me in solving this performance issue.
    *- Get the Goods receipts  mainly selected per period (=> MKPF secondary
      SELECT msegebeln msegebelp mseg~werks
             ekkobukrs ekkolifnr ekkozterm ekkoekorg ekko~ekgrp
             ekkoinco1 ekkoexnum
             lfa1name1 lfa1land1 lfa1ktokk lfa1stceg
             mkpfmblnr mkpfmjahr msegzeile mkpfbldat mkpf~budat
             mseg~bwart
    *Start of changes for CIP 6203752 by PGOX02
             mseg~smbln
    *End of changes for CIP 6203752 by PGOX02
             ekpomatnr ekpotxz01 ekpomenge ekpomeins
             ekbemenge ekbedmbtr ekbewrbtr ekbewaers
             ekpolgort ekpomatkl ekpowebaz ekpokonnr ekpo~ktpnr
             ekpoplifz ekpobstae
             INTO TABLE it_temp
        FROM mkpf JOIN mseg ON msegmblnr EQ mkpfmblnr
                           AND msegmjahr EQ mkpfmjahr
                  JOIN ekbe ON ekbeebeln EQ msegebeln
                           AND ekbeebelp EQ msegebelp
                           AND ekbe~zekkn EQ '00'
                           AND ekbe~vgabe EQ '1'
                           AND ekbegjahr EQ msegmjahr
                           AND ekbebelnr EQ msegmblnr
                           AND ekbebuzei EQ msegzeile
                  JOIN ekpo ON ekpoebeln EQ ekbeebeln
                           AND ekpoebelp EQ ekbeebelp
                  JOIN ekko ON ekkoebeln EQ ekpoebeln
                  JOIN lfa1 ON lfa1lifnr EQ ekkolifnr
        WHERE mkpf~budat IN so_budat
          AND mkpf~bldat IN so_bldat
          AND mkpf~vgart EQ 'WE'
          AND mseg~bwart IN so_bwart
          AND mseg~matnr IN so_matnr
          AND mseg~werks IN so_werks
          AND mseg~lifnr IN so_lifnr
          AND mseg~ebeln IN so_ebeln
          AND ekko~ekgrp IN so_ekgrp
          AND ekko~bukrs IN so_bukrs
          AND ekpo~matkl IN so_matkl
          AND ekko~bstyp IN so_bstyp
          AND ekpo~loekz EQ space
          AND ekpo~plifz IN so_plifz.
    Thanks & Regards,
    Manoj Kumar .Thatha
    Moderator message - Please see Please Read before Posting in the Performance and Tuning Forum before posting and please use code tags when posting code - post locked
    Edited by: Rob Burbank on Feb 4, 2010 9:03 AM

    Hi friends ,
    This is my select query which is taking so much time to retrive the records.CAn Any one help me in solving this performance issue.
    *- Get the Goods receipts  mainly selected per period (=> MKPF secondary
      SELECT msegebeln msegebelp mseg~werks
             ekkobukrs ekkolifnr ekkozterm ekkoekorg ekko~ekgrp
             ekkoinco1 ekkoexnum
             lfa1name1 lfa1land1 lfa1ktokk lfa1stceg
             mkpfmblnr mkpfmjahr msegzeile mkpfbldat mkpf~budat
             mseg~bwart
    *Start of changes for CIP 6203752 by PGOX02
             mseg~smbln
    *End of changes for CIP 6203752 by PGOX02
             ekpomatnr ekpotxz01 ekpomenge ekpomeins
             ekbemenge ekbedmbtr ekbewrbtr ekbewaers
             ekpolgort ekpomatkl ekpowebaz ekpokonnr ekpo~ktpnr
             ekpoplifz ekpobstae
             INTO TABLE it_temp
        FROM mkpf JOIN mseg ON msegmblnr EQ mkpfmblnr
                           AND msegmjahr EQ mkpfmjahr
                  JOIN ekbe ON ekbeebeln EQ msegebeln
                           AND ekbeebelp EQ msegebelp
                           AND ekbe~zekkn EQ '00'
                           AND ekbe~vgabe EQ '1'
                           AND ekbegjahr EQ msegmjahr
                           AND ekbebelnr EQ msegmblnr
                           AND ekbebuzei EQ msegzeile
                  JOIN ekpo ON ekpoebeln EQ ekbeebeln
                           AND ekpoebelp EQ ekbeebelp
                  JOIN ekko ON ekkoebeln EQ ekpoebeln
                  JOIN lfa1 ON lfa1lifnr EQ ekkolifnr
        WHERE mkpf~budat IN so_budat
          AND mkpf~bldat IN so_bldat
          AND mkpf~vgart EQ 'WE'
          AND mseg~bwart IN so_bwart
          AND mseg~matnr IN so_matnr
          AND mseg~werks IN so_werks
          AND mseg~lifnr IN so_lifnr
          AND mseg~ebeln IN so_ebeln
          AND ekko~ekgrp IN so_ekgrp
          AND ekko~bukrs IN so_bukrs
          AND ekpo~matkl IN so_matkl
          AND ekko~bstyp IN so_bstyp
          AND ekpo~loekz EQ space
          AND ekpo~plifz IN so_plifz.
    Thanks & Regards,
    Manoj Kumar .Thatha
    Moderator message - Please see Please Read before Posting in the Performance and Tuning Forum before posting and please use code tags when posting code - post locked
    Edited by: Rob Burbank on Feb 4, 2010 9:03 AM

  • Issue in select query

    HI All experts,<br><br>
    i have  a program in which i have a select query <pre>
    SELECT  b~vertrag
              a~anlage
              a~operand
              a~saison
              a~ab
              a~ablfdnr
              a~bis
              a~wert1
      FROM ettifn AS a INNER JOIN ever AS b
      ON aanlage = banlage
      INTO TABLE li_captran PACKAGE SIZE p_pack
      WHERE a~anlage IN s_anlage
        AND a~ab <= l_date
        AND a~bis >= l_date
        AND a~operand IN ('ID-CAPLOAD','ID-OBLT')
        AND b~einzdat <= l_date
        AND b~auszdat >= l_date.</pre><br><br>
    this query is taking a lot of time in running and we are facing lot of performance related issues
    <br><br>
    kindly guide me how i can break this into som simpler query
    <br><br>
    ettifn has 10 million records
    ever has around 5 million records .
    <br><br>
    also please tell me how much data i can store into an internal table
    can i store 5 million records in an internal table ??????
    is it good in terms of performance of a program if not please tell me what is the better way of doing dat .
    <br><br>
    also tell me how secondry indexes help in improving performance of select query
    is it good to maintain number of secondry indexes in a standard table or it decreases performance of a standard table .
    <br><br>
    <pre>
      TYPES: BEGIN OF ty_eanlh,
              anlage LIKE eanlh-anlage,
              bis LIKE eanlh-bis,
              tariftyp LIKE eanlh-tariftyp,
             END OF ty_eanlh.
      DATA: l_date TYPE datum.
      DATA: li_eanlh TYPE HASHED TABLE OF ty_eanlh WITH UNIQUE KEY anlage
                                                                   bis
                                                   WITH HEADER LINE.
      DATA: li_captran TYPE HASHED TABLE OF ty_captran WITH UNIQUE KEY vertrag
                                                                       anlage
                                                                       operand
                                                                       saison
                                                                       ab
                                                                       ablfdnr
                                                        WITH HEADER LINE.
      DATA: l_tariftyp LIKE eanlh-tariftyp.
    l_date = p_date + 6.
      l_date = p_date + 5.          "As per Terry's Request 1/23/2009
      CHECK NOT p_cap IS INITIAL.
    Get Operand Values
      SELECT  b~vertrag
              a~anlage
              a~operand
              a~saison
              a~ab
              a~ablfdnr
              a~bis
              a~wert1
      FROM ettifn AS a INNER JOIN ever AS b
      ON aanlage = banlage
      INTO TABLE li_captran PACKAGE SIZE p_pack
      WHERE a~anlage IN s_anlage
        AND a~ab <= l_date
        AND a~bis >= l_date
        AND a~operand IN ('ID-CAPLOAD','ID-OBLT')
        AND b~einzdat <= l_date
        AND b~auszdat >= l_date.
        IF sy-subrc EQ 0 AND NOT li_captran[] IS INITIAL.
       Get Rate Category
          SELECT anlage
                 bis
                 tariftyp
          FROM eanlh INTO CORRESPONDING FIELDS OF TABLE li_eanlh
          FOR ALL ENTRIES IN li_captran
          WHERE anlage = li_captran-anlage
            AND ab <= l_date
            AND bis >= l_date.
       Get POD ID
          SELECT a~anlage
                 a~int_ui
                 a~dateto
                 a~timeto
                 b~ext_ui
          INTO TABLE i_pod
          FROM euiinstln AS a INNER JOIN euitrans AS b
          ON aint_ui = bint_ui
          FOR ALL ENTRIES IN li_captran
          WHERE a~anlage = li_captran-anlage.
          IF sy-subrc EQ 0 AND NOT i_pod[] IS INITIAL.
            SORT i_pod BY anlage.
            SELECT vertrag
                   int_ui
                   serviceid
            FROM eservice
            INTO TABLE i_servicect
            FOR ALL ENTRIES IN i_pod
            WHERE int_ui = i_pod-int_ui
              AND service_start <= l_date
              AND service_end >= l_date
              AND service = 'ESUP'.
          ENDIF.
          LOOP AT li_captran.
            i_ct-anlage = li_captran-anlage.
            READ TABLE li_eanlh WITH KEY anlage = li_captran-anlage.
            IF sy-subrc EQ 0.
              i_ct-tariftyp = li_eanlh-tariftyp.
              READ TABLE i_rate WITH KEY tariftyp = i_ct-tariftyp.
              IF sy-subrc NE 0.
                CONTINUE.
              ENDIF.
            ELSE.
              i_ct-tariftyp = '0000'.
            ENDIF.
            READ TABLE i_pod WITH KEY anlage = li_captran-anlage.
            IF sy-subrc EQ 0.
              READ TABLE i_servicect WITH KEY int_ui = i_pod-int_ui.
              IF sy-subrc EQ 0.
                i_ct-serviceid = i_servicect-serviceid.
              ENDIF.
            ENDIF.
            IF li_captran-operand = 'ID-CAPLOAD'.
              i_ct-cap = li_captran-wert1.
            ELSEIF li_captran-operand = 'ID-OBLT'.
              i_ct-tran = li_captran-wert1.
            ENDIF.
            COLLECT i_ct.
            CLEAR: li_captran, i_ct.
          ENDLOOP.
        ENDIF.
      ENDSELECT.</pre><br><br>
      this code is taking a lot of time to execute and decreasing the system performance .<br><br>
    please guide me how can i increase the performance of this code .<br><br>
    Thanks in advance<br><br><br><br>
    Edited by: Matt on Oct 11, 2009 9:45 PM

    Hi matt ,
    no i am not thru bcoz of formatting i just trying to remove it and i just marked it answered so that it will not come in my unanswered because unanswered questions are limited.
    also could you please help me in this question .
    now how can i change this question to unanswerd .
    plz guide me
    Thanks in advance

  • Issue in select query with where clause

    Hi guys,
    I'm facing an issue while using select query with the where clause. When I'm selecting all the data from the table it returns the correct result. But when I'm using the where clause to get the specific rows from the table it returns no rows. But the data I'm trying to fetch using the where condition exists in the table.
    Here is my query which causing the issue,
    select * from mytable where myfield = 'myvalue'
    But if I use the following query it returns the result correctly.
    select * from mytable
    Also the myfield value 'myvalue' exists in the table.
    I have tried by running this query in both SQL Developer and SQL Plus. I have tried this query in mssql as well. It works perfectly and returns correct result sets for both the queries I have mentioned above. I'm unable to predict the issue as I'm new to ORACLE. Please help.
    Thanks,
    Ram.

    Hi Ram,
    I experienced an issue similar to this with a varchar2 field. Some of our records had a hidden newline character at the end of them, which was making queries like the one below fail:
    select * from employees
    where email = '[email protected]'The best way I found to detect this was to use
    select 'XX'||email||'XX' from employeesTo make sure that there were no newlines. But that is just a guess. If you could provide some example table data and the outputs of your selects, it would be helpful.
    Jeff

  • Issue with Select Query in the Delivery userexit USEREXIT_SAVE_DOCUMENT

    Hi All,
    I am facing a strang issue with delivery userexit
    1) I have a delivery user exit MV50AFZ1 - USEREXIT_SAVE_DOCUMENT.
    2) In this user exit. I have written a select query as shown below
    *Get the already delivered data
        SELECT vbeln
               vgbel
               vgpos
               erdat
               erzet
               lfimg
          FROM lips
          INTO TABLE t_lips
           FOR ALL ENTRIES IN t_xlips_reference
         WHERE vgbel EQ t_xlips_reference-vgbel
           AND vgpos EQ t_xlips_reference-vgpos.
        IF sy-subrc EQ 0.
        ENDIF.
    3) The use of the above select query is to find out if there is any delivery that has already been created for the reference slaes order for which the current delivery is being created.
    4) The issue here is that for the FIRST DELIVERY, this select query should fail becuase there is no delivery created earlier and LIPS table would not have data. But, I am seeing some data getting populated in the internal table. The data that I am seeing in the internal table is the data of XLIPS which is nothing but the one that is about to get saved in the database after finishing this userexit.
    5) STRANGE Point is that this is working fine in case if I create delivery using the transaction VL01N. But, if I create delivery using VL10A program I am facing this issue.
    << Removed >>
    Thanks,
    Babu Kilari
    Edited by: Rob Burbank on Jun 16, 2010 4:22 PM

    Then why don't you add
    AND vbeln NE likp-vbeln

  • Regarding "select query" on performance basis..

    Hi Experts,
    I am creating an ALV report,so that i have to collect all data in 1 internal table.
    I have to collect data from 3 standard tables i.e.T157E,MSEG,MKPF.
    For all entries of T157E, i have to fetch data from MSEG.
    But in where condition i have to give POSTING DATE n this field is in MKPF.
    Also Database performance analysis is around 98%.
    How can i give better performance, please help..
    Below is my coding...
    (second select query is taking too much time,how can i rectify)
    SELECT BWART
                 GRUND
        FROM T157D
        INTO CORRESPONDING FIELDS OF TABLE IT_MOV_TYPE.
    SELECT MATNR
             MJAHR
             MBLNR
             BWART
             WERKS
             LGORT
             CHARG
             GRUND
             MENGE
             MEINS
        FROM MSEG
        INTO CORRESPONDING FIELDS OF TABLE IT_MSEG
        FOR ALL ENTRIES IN IT_MOV_TYPE
       WHERE GRUND = IT_MOV_TYPE-GRUND
         AND BWART = IT_MOV_TYPE-BWART
         AND WERKS = PLANT
         AND LGORT IN ST_L.
      SORT IT_MSEG BY MBLNR.
      LOOP AT IT_MSEG.
        AT NEW MBLNR.
          SELECT SINGLE BUDAT
                   FROM MKPF
                   INTO V_BUDAT
                  WHERE MBLNR = IT_MSEG-MBLNR
                    AND MJAHR = IT_MSEG-MJAHR.
          SELECT SINGLE MAKTX
                   FROM MAKT
                   INTO V_MAKTX
                  WHERE MATNR = IT_MSEG-MATNR.
          SELECT SINGLE GRTXT
                   FROM T157E
                   INTO V_GRTXT
                  WHERE GRUND = IT_MSEG-GRUND.
        ENDAT.
        IT_MSEG-BUDAT = V_BUDAT.
        IT_MSEG-MAKTX = V_MAKTX.
        IT_MSEG-GRTXT = V_GRTXT.
        MODIFY IT_MSEG.
      ENDLOOP.
    Regards,
    Ankur

    Before you use
    FOR ALL ENTRIES IN
    Do the following :
    1. Sort the Internal table used in the 'FOR ALL ENTRIES IN' clause.
    2. Make sure they do not contain duplicates.
    3. Last and most importantly include a primary key field(Unique entry) in the select list. The reason, the system gets unique field records based on the where condition. It summarizes the data based on the Data type and field list in the target internal table.
    One should be sure the internal table, used in the FOR ALL ENTRIES clause is not empty. If the table is empty, ALL ENTRIES will be selected. (Actually, all WHERE clauses are neglected). Of course, you should also be sure you select on INDEX fields. Otherwise the use of FOR ALL ENTRIES increases the runtime instead of improving it.

  • Issue with select query join....

    Hello,
    I am facing a problem with a select query. I get a message that itab_data is not long enough.
    DATA: itab_data like ptrv_head occurs 0 with header line.
    SELECT *    from PTRV_HEAD
                as a inner join PA0002 as b
                on a~pernr = b~pernr
                inner join PA0001 as c
                on a~pernr = c~pernr
                INTO TABLE itab_data
           where a~PERNR in S_PERNR
           and   a~REINR in S_TRIP
           and   a~ZLAND in S_LAND
           and   a~DATV1 in S_BEGIN
           and   a~DATB1 in S_END
           and   b~NACHN in S_FIRST
           and   b~VORNA in S_LAST
           and   c~BUKRS in S_BUKRS
           and   c~KOSTL in S_KOSTL
           and   c~PERSG in S_EMPGP
           and   c~PERSK in S_SUBGP
           and   c~begda in ldbbegda
           and   c~endda in ldbendda.
    Regards,
    Jainam.
    Edited by: Jainam Shah on Mar 27, 2009 4:13 PM
    Edited by: Jainam Shah on Mar 27, 2009 4:13 PM

    Hi,
    Try this..
    DATA: t_dfies  TYPE STANDARD TABLE OF dfies.
    DATA: t_fields TYPE STANDARD TABLE OF char40.
    DATA: s_dfies  TYPE dfies,
          s_fields TYPE char40.
    * Get the fields
    CALL FUNCTION 'DDIF_FIELDINFO_GET'
      EXPORTING
        tabname        = 'PTRV_HEAD'
      TABLES
        dfies_tab      = t_dfies[]
      EXCEPTIONS
        not_found      = 1
        internal_error = 2
        OTHERS         = 3.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    * Build the fields to be selected.
    LOOP AT t_dfies INTO s_dfies.
      CONCATENATE 'A~' s_dfies-fieldname INTO s_fields.
      APPEND s_fields TO t_fields.
      CLEAR: s_fields.
    ENDLOOP.
    * Select.
    SELECT (t_fields)    from PTRV_HEAD
    Thanks
    Naren

  • Performance issue with select query and for all entries.

    hi,
    i have a report to be performance tuned.
    the database table has around 20 million entries and 25 fields.
    so, the report fetches the distinct values of two fields using one select query.
    so, the first select query fetches around 150 entries from the table for 2 fields.
    then it applies some logic and eliminates some entries and makes entries around 80-90...
    and then it again applies the select query on the same table using for all entries applied on the internal table with 80-90 entries...
    in short,
    it accesses the same database table twice.
    so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
    is around 80-90 entries too much for using "for all entries"?
    the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
    i really cant find the way out...
    please help.

    chinmay kulkarni wrote:Chinmay,
    Even though you tried to ask the question with detailed explanation, unfortunately it is still not clear.
    It is perfectly fine to access the same database twice. If that is working for you, I don't think there is any need to change the logic. As Rob mentioned, 80 or 8000 records is not a problem in "for all entries" clause.
    >
    > so, i tried to get the database table in internal table and apply the logic on internal table and delete the unwanted entries.. but it gave me memory dump, and it wont take that huge amount of data into abap memory...
    >
    It is not clear what you tried to do here. Did you try to bring all 20 million records into an internal table? That will certainly cause the program to short dump with memory shortage.
    > the logic that is applied to eliminate the entries from internal table is too long, and hence cannot be converted into where clause to convert it into single select..
    >
    That is fine. Actually, it is better (performance wise) to do much of the work in ABAP than writing a complex WHERE clause that might bog down the database.

  • Regarding SELECT query

    Dear experts,
    Is there a way for the following SELECT query to be improved?
    The problem that I'm seeing here is that the same table (l_item_tab) is being queried twice in the SELECT query (due to the "table joins", a and b). How can I improve the data retrieval here? And I also can't change the SELECT query to be out of the loop - ledger is a select-option and multiple values are possible.
    * Get Ledger
      SELECT * FROM t881 INTO TABLE lt_t881
        WHERE rldnr IN s_rldnr.
      LOOP AT lt_t881.
    *   Get FI-SL user-defined item table based on ledger
        PERFORM get_sl_item_tab USING lt_t881-rldnr CHANGING l_item_tab.
      " L_ITEM_TAB is populated here
    *   Get SL line items
        SELECT * APPENDING CORRESPONDING FIELDS OF TABLE gt_glu1
        FROM (l_item_tab) AS a
        WHERE
            rldnr         IN s_rldnr             " Ledger
        AND rbukrs        IN s_bukrs             " Company code
        AND ryyrkeg_wwsub IN s_wwsub             " Subsystem
        AND racct         IN s_racct             " Account no
        AND ryymac        IN s_yymac             " Management area
        AND rtcur         IN s_rtcur             " Trx currency
        AND docnr         IN s_docnr             " Doc. number
        AND docty         IN s_docty             " Doc. type
        AND docct         EQ c_docct_l           " Doc. category (L = Local)
        AND ryear         IN s_ryear             " Fiscal year
        AND budat         IN s_budat             " Posting date
        AND yystodt       IN s_stodt             " Reversal date
        AND yystgrd       IN s_stgrd             " Reversal reason
        AND yyintref      IN s_intref            " Interface ID
        AND NOT exists
          ( SELECT * FROM (l_item_tab) AS b
             WHERE
                 b~rldnr    = a~rldnr     AND
                 b~docnr    = a~docnr     AND
                 b~rbukrs   = a~rbukrs    AND
           ( ( ( b~docct    = c_docct_y
              OR b~docct    = c_docct_x ) AND
                 b~refryear = a~ryear )   OR
             ( ( b~docct    = c_docct_u
              OR b~docct    = c_docct_t ) AND
                 b~ryear    = a~ryear ) )
      ENDLOOP.
    Edited by: Rob Burbank on Jun 23, 2010 12:33 PM

    >
    Siegfried Boes wrote:
    > > Will certainly try this out too..
    > maybe you should think twice .... The usage of a subselect is that the result set is not transferred to the application server it is only needed
    > during the selection.
    >
    > You should anser the following questions:
    > + who wrote the code? you or? I get the impression that you don't know what is intended.
    > + SQL Trace, what are the numbers for repeated executions, (go to summary by SQL statement), duration, execution, records
    > + how many different tables are accessed, l_item_tab is dynamic
    > + what knid of tables are accessed?
    >
    > Siegfried
    Hi Siegfried,
    - The codes are currently existing ones and they were not written by me too. I just do know that the first / main SELECT statement in the query is for retrieving FI special ledger line item data records, while the second / sub SELECT statement is to ensure that the line item data records are not already reversed, and not a reversal.
    - In the summarized SQL trace of a sample test run: executions = 1, identical executions = 0, duration = 700247324 (almost 100% of the total processing durations), records = 0 (there should be more records returned in an actual production run)
    - Only one table, ZZGLV4A (custom) is accessed based on the selection screen variant. ZZGLV4A is an FI special ledger line item table and its data volume: 455 mil. data records. Note: The codes are written for a report that runs in the background, and the selection screen variant is used for the executions too. The table accessed (l_item_tab is ZZGLV4A in this case) depends on the ledger inputted here - only one ledger is specified for the current selection screen variant.
    - Table accessed - FI special ledger line item data.
    I tried tuning the query a little further by just properly specifying the WHERE fields - only a minimal improvement is observed, an average of about 6% of runtime improvement only (tested via SE30 in the development box for ZZGLV4A but its table volume is 4 mil. data records here only). This obviously works only for the table ZZGLV4A for now, I'm afraid.
    Any other ideas on how such subqueries can be improved generally (maybe secondary indexes)? The subquery is certainly re-hitting the same table at least twice.
    Thanks for the inputs once again!

  • Issue with select query for secondary index

    Hi all,
    I have created a secondary index A on mara table with fields Mandt and Packaging Material Type VHART.
    Now i am trying to write a report
    Tables : mara.
    data : begin of itab occurs 0.
    include structure mara.
    data  : end of itab.
    *select * from mara into table itab*
    CLIENT SPECIFIED where
      MANDT = SY-MANDT and
      VHART = 'WER'.
    I'm getting an error
    Unable to interpret "CLIENT". Possible causes of error: Incorrect spelling or comma error.          
    if i change to my select query     to
    *select * from mara into table itab*
      where
      MANDT = SY-MANDT and
      VHART = 'WER'.
    I'm getting an error
    Without the addition "CLIENT SPECIFIED", you cannot specify the client     field "MANDT" in the WHERE condition.
    Let me know if iam wrong and we are at 4.6c
    Thanks

    Like I already said, even if you have added the mandt field in the secondary index, there is no need the use it in the select statement.
    Let me elaborate on my reply before. If you have created a UNIQUE index, which I don't think you have, then you should include CLIENT in the index. A unique index for a client-dependent table must contain the client field.
    Additional info:
    The accessing speed does not depend on whether or not an index is defined as a unique index. A unique index is simply a means of defining that certain field combinations of data records in a table are unique.
    Even if you have defined a secondary index, this does not automatically mean, that this index is used. This also depends on the database optimizer. The optimizer will determine which index is best and use it. So before transporting this index, you should make sure that the index is used. How to check this, have a look at the link:
    [check if index is used|http://help.sap.com/saphelp_nw70/helpdata/EN/cf/21eb3a446011d189700000e8322d00/content.htm]
    Edited by: Micky Oestreich on May 13, 2008 10:09 PM

  • Performance issue in Select Query on ERCH

    Dear Friends,
    I have to execute a query on ERCH in production system having around 20 lakh data which keeps on increasing. "Select BELNR VERTRAG ADATSOLL from ERCH where BCREASON = u201803u2019 " . The expected volume of data that the query will return is approx 1400 records.
    Since the where clause includes a field which is not a key field please suggest the performance of the query so that it doesn't time-out.
    Regards,
    Amit Srivastava

    Hello Amit Srivastava ,
                                        You can add the Contract account number(VKONT)  and Business Partner number(GPARTNER) in your query and can create a custom Index for the contract account number  (We have this index created in our system).
    This will improve the performance effectively.
    Hope this answers your question.
    Thanks,
    Greetson

  • Need clarification regarding select query

    Hi,
    I need a little clarification regrding a Select senario
    I want to select data from table which have been minupulated between a certian date like between 1-DEC-10 to 31-DEC-10 and note that table does not have any time/date column. I've applied the following query to do this.
    select * from TABLE_NAME where sysdate between to_date('01-DEC-10') AND to_date('31-DEC-10');
    Would it work fine because I've tried it against a table and it returned me nothing however DML occur between time period.
    Regards,
    Abbasi

    Abbasi wrote:
    Hi,
    I need a little clarification regrding a Select senario
    I want to select data from table which have been minupulated between a certian date like between 1-DEC-10 to 31-DEC-10 and note that table does not have any time/date column. I've applied the following query to do this.
    select * from TABLE_NAME where sysdate between to_date('01-DEC-10') AND to_date('31-DEC-10');
    Would it work fine because I've tried it against a table and it returned me nothing however DML occur between time period.
    Regards,
    AbbasiAFAIK without log mining and auditing this is not possible.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/logminer.htm

  • Issue with select query to fetch data using Join from two tabels

    Hello All-
    I want to fetch the ShowName as "SUN NIGHTLY NEWS" and EpisodeName as "091706"
    based on the condition a.TitleNo=b.TitleNo and a.seriesNo=b.TitleNo.
    If i use the only first condition-a.TitleNo=b.TitleNo than output is displayed as-
    SchedItemNo |      Showname|      EpisodeName
    2702154     |     091706     |     091706
    If i use the second Condition-a.seriesNo=b.TitleNo than Output is displayed as-
    SchedItemNo|     Showname      |     EpisodeName
    2702154     |     SUN NIGHTLY NEWS |     SUN NIGHTLY NEWS
    Than i tried following Query to use the Union based on two conditions:-
    Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
    from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
    a.ScheditemNo in ('2702154')
    Union All
    Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
    from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
    a.ScheditemNo in ('2702154')
    than it display the following result-
    SchedItemNo|     Showname |     EpisodeName
    2702154     |     091706          |     091706
    2702154     |     SUN NIGHTLY NEWS |     SUN NIGHTLY NEWS
    Here also values are not what i want :(
    I want the result to be displayed as using SQL:-
    SchedItemNo |     Showname      |     EpisodeName
    2702154     |     SUN NIGHTLY NEWS |     091706
    Please help me out!
    Thanks in Advance for putting your efforts.Looking forward for your replies.

    SQL> create table scheduleitem
      2  as
      3  select 2702154 scheditemno, 1 titleno, 11 seriesno from dual
      4  /
    Tabel is aangemaakt.
    SQL> create table titles
      2  as
      3  select 1 titleno, '071706' titlename from dual union all
      4  select 11, 'SUN NIGHTLY NEWS' from dual
      5  /
    Tabel is aangemaakt.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
      3  a.ScheditemNo in ('2702154')
      4  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 071706           071706
    1 rij is geselecteerd.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
      3  a.ScheditemNo in ('2702154')
      4  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 SUN NIGHTLY NEWS SUN NIGHTLY NEWS
    1 rij is geselecteerd.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
      3  a.ScheditemNo in ('2702154')
      4  Union All
      5  Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      6  from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
      7  a.ScheditemNo in ('2702154')
      8  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 071706           071706
                                   2702154 SUN NIGHTLY NEWS SUN NIGHTLY NEWS
    2 rijen zijn geselecteerd.
    SQL> select a.SchedItemNo "SchedItemNo"
      2       , show.TitleName "Showname"
      3       , episode.TitleName "EpisodeName"
      4    from ScheduleItem a
      5       , Titles episode
      6       , Titles show
      7   where a.TitleNo = episode.TitleNo
      8     and a.SeriesNo = show.TitleNo
      9  /
                               SchedItemNo Showname         EpisodeName
                                   2702154 SUN NIGHTLY NEWS 071706
    1 rij is geselecteerd.Regards,
    Rob.

  • Regarding select query with code

    Hi Experts ,
    i m taking two transparent table "VBAK , VBAP" WITH CLUSTER TABLE "KONV"
    In this Table we create inner join between VBAK ,ABAP  to itab and make  itab2 with some field of KONV.
    ===========================================================
    *& Report  Z_VBAP_REPORT                                               *
    REPORT  Z_VBAP_REPORT    .
    TABLES:VBAP,VBAK,KONV.
    DATA KNUMV LIKE VBAK-KNUMV.
    DATA:BEGIN OF ITAB OCCURS 0,
         VBELN LIKE VBAK-VBELN,
         POSNR LIKE VBAP-POSNR,
         MATNR LIKE VBAP-MATNR,
         NETPR LIKE VBAP-NETPR,
         BNAME LIKE VBAK-BNAME,
         ERDAT LIKE VBAK-ERDAT,
         KBETR LIKE KONV-KBETR,
         KNTYP LIKE KONV-KNTYP,
         KNUMV LIKE VBAK-KNUMV,
         END OF ITAB.
    DATA ITAB2 LIKE ITAB OCCURS 0 WITH HEADER LINE.
    PARAMETER SALE_DOC LIKE VBAK-VBELN.
    SELECT-OPTIONS D_DATE FOR VBAK-ERDAT.
    SELECT BVBELN APOSNR AMATNR ANETPR BBNAME BERDAT INTO
    CORRESPONDING FIELDS OF TABLE ITAB FROM VBAP AS A INNER JOIN VBAK
    AS B ON ( BVBELN = AVBELN ) WHERE B~ERDAT IN D_DATE AND
    A~VBELN =  SALE_DOC.
    SELECT  KBETR KNTYP  FROM KONV INTO CORRESPONDING FIELDS OF TABLE ITAB2
    WHERE KNUMV = KNUMV .
    EXPORT ITAB TO MEMORY ID 'ASHISH'.
    EXPORT ITAB2 TO MEMORY ID 'ASHISH1'.
    SUBMIT Z_ABAP2 VIA SELECTION-SCREEN AND RETURN.
    ///////Code for report Z_ABAP2
    *& Report  Z_ABAP2                                                     *
    REPORT  Z_ABAP2   .
    TABLES:VBAP,VBAK,KONV.
    DATA:BEGIN OF ITAB OCCURS 0,
         VBELN LIKE VBAK-VBELN,
         POSNR LIKE VBAP-POSNR,
         MATNR LIKE VBAP-MATNR,
         NETPR LIKE VBAP-NETPR,
         BNAME LIKE VBAK-BNAME,
         ERDAT LIKE VBAK-ERDAT,
         KBETR LIKE KONV-KBETR,
         KNTYP LIKE KONV-KNTYP,
         KNUMV LIKE VBAK-KNUMV,
         END OF ITAB.
    DATA ITAB2 LIKE ITAB OCCURS 0 WITH HEADER LINE.
    LOOP AT ITAB.
    WRITE : / ITAB-VBELN,
               ITAB-POSNR, 25
               ITAB-MATNR,
               ITAB-NETPR,
               ITAB-BNAME,
               ITAB-ERDAT,
               ITAB-KBETR,
               ITAB-KNTYP.
    ENDLOOP.
    LOOP AT ITAB2.
    WRITE :/   ITAB2-KBETR,
               ITAB2-KNTYP.
               ENDLOOP.
    INITIALIZATION .
      IMPORT ITAB FROM MEMORY ID 'ASHISH'.
      IMPORT ITAB2 FROM MEMORY ID 'ASHISH1'.
    =========================================================
    thanks & regards ,
    Ashish

    Hi
    after the first select use for all entries of this ITAB and fetch data from KONV as below, declare I_FINAL and move the ITAB and ITAB2 data into it and display its output
    SELECT BVBELN APOSNR AMATNR ANETPR BBNAME BERDAT <b>B~KNUMV</b> INTO
    CORRESPONDING FIELDS OF TABLE ITAB FROM VBAP AS A INNER JOIN VBAK
    AS B ON ( BVBELN = AVBELN ) WHERE B~ERDAT IN D_DATE AND
    A~VBELN = SALE_DOC.
    <b>IF NOT ITAB[] IS INITIAL.
    SELECT KNUMV KPOSN KBETR KNTYP FROM KONV INTO CORRESPONDING FIELDS OF TABLE ITAB2 for all entries in ITAB
    WHERE KNUMV = ITAB-KNUMV and KPOSN = ITAB-POSNR .</b>
    Loop at itab.
      move-corresponding itab to i_final.
      read table itab2 with key knumv = itab-knumv and kposn = itab-posnr.
      if sy-subrc  = 0.
        move-corresponding itab2 to i_final.
      endif.
    append i_final.
    clear i_final.
    endloop.
    Loop at i_final.
       write: / I_final (write all the fields)
    endloop.
    <b>Reward points for useful Answers</b>
    Regards
    Anji

Maybe you are looking for

  • I have an itunes account can i share with my husband iphone

    I have an itunes account with my email address. my husband just got an iphone and I want to share my playlist on his iphone (which has a different email address) can this be done?

  • Video out fire wire port from iTunes?

    Final cut and Pro Tools LE both have the ability to send video from a G5 to a TV out of the fire wire port via a Canopus ADVC-110. Why doesn't iTunes? I understand that the new Mac TV gizmo plus an airport card will do this, but I already have all th

  • Difference between 1142 and 1042 AP's

    Is there any important difference between these 2 Aironet AP series? Can both of them perform band selection? I'm designing a company's wireless network and I'm not sure about choosing 1142's or 1042's

  • Adding AdSense and Other Script Based Items to iWeb Websites

    For all those who are trying to figure out how to add AdSense and other script based content, here is a tutorial on how to do so. You can see this article with graphics and other niceties on my website: http://keylime.ca/adsense%20on%20iweb.html For

  • Setups for Directory where data files sit, in Inbound Transaction.

    Hi, My customer is implementing Inbound Po transaction using e-commerce gateway for Order Import in R12. Could you let me know what setups i need to ask DBA's for creating inbound directory. I just found one required setup online. 1) DBA's must defin