Urgent - I have written select query between loop and endloop, Ple help out

Can any one help out me on this select query. I have written select query between loop and endloop. When I execute the program it will take too much time in this query. Please help me out. Its very urgent.
LOOP AT l_i_invoices ASSIGNING <l_invoices>.
      CLEAR alv_wa.
      alv_wa-bukrs = <l_invoices>-bukrs.
      alv_wa-gsber = <l_invoices>-gsber.
      CLEAR l_instid.
      CONCATENATE <l_invoices>-belnr <l_invoices>-gjahr INTO l_instid.
      SELECT top_wi_id FROM sww_wi2obj INTO TABLE l_i_swwwihead
              WHERE catid   = c_catid_business_object
                AND instid  = l_instid
                AND typeid  = c_typeid_invoice
                AND removed = space
                AND ( wi_rh_task = c_task_buyer_message
                   OR wi_rh_task = c_task_buyer_message2 ).
      IF sy-subrc = 0.
        <l_invoices>-flag = 'X'.
      ELSE.
        <l_invoices>-flag = ' '.
      ENDIF.
      MODIFY l_i_invoices FROM <l_invoices> TRANSPORTING flag
                            WHERE belnr = <l_invoices>-belnr
                               AND gjahr = <l_invoices>-gjahr.
      APPEND alv_wa TO i_alv.
    ENDLOOP.
Thanks in advance.

Here is a way to solve this problem.
Choose somewhere before this loop processing to use that select. Therefore, you'll need use FOR ALL ENTRIES <that_loop_table> clause, and in the WHERE condition you need to specify that same fields.
This way, you will have an internal table with all data you'll need to check.
Then, inside your loop statement, use the READ TABLE command with the clause WITH KEY field = value, to read that record and use the value found.
Like this sample:
  SELECT bukrs lifnr umsks umskz augdt augbl zuonr gjahr belnr buzei
         waers xblnr blart gsber ebeln zfbdt zbd1t zlsch
  INTO TABLE tg_bsak
  FROM bsak
  FOR ALL ENTRIES IN tl_bkpf_sel
  WHERE bukrs EQ tl_bkpf_sel-bukrs AND
        lifnr IN s_lifnr AND
        augbl EQ tl_bkpf_sel-belnr.
LOOP AT tg_bseg INTO wa_bseg.
    READ TABLE tg_bsak INTO wa_bsak WITH KEY bukrs = wa_bseg-bukrs
                                             gjahr = wa_bseg-gjahr
                                             belnr = wa_bseg-belnr
                                             BINARY SEARCH.
if sy-subrc = 0.
* do something
endif.
ENDLOOP.

Similar Messages

  • Creating SELECT query between 3 tables

    Hi there,
    Im trying to create a SELECT query between 3 tables and it is driving me round the bend.
    I have 3 tables connected together which are:
    MODUL
    modulid
    modulname
    modulevel
    STUDENT
    studentid
    surname
    inits
    s e x
    phone
    email
    logon
    STUDREGOCCUR
    modulid
    acyear
    semester
    occletter
    studentid
    result
    I want to select the fields surname, inits, studentid from the STUDENT table, modulname from the MODUL table and result from my STUDREGOCCUR table that is NOT NULL.
    I have tried SELECT STUDENT.STUDENTID, STUDENT.INITS, STUDENT.SURNAME, MODUL.MODULNAME, STUDREGOCCUR.RESULT WHERE STUDREGOCCUR.RESULT IS NOT NULL;
    I have also tried many other ways and done research hwich hasnt really helped me unfortunately.
    Im quite new to SELECT queries and im not sure where im going wrong, i would greatly appreciate if someone could help me solve my problem.
    Thanks for the help :)
    Edited by: user633643 on 06-Dec-2008 08:09

    If you want data from multiple tables you would need to perform a join. The general form would be:
    select t1.cola, t2.col2, t3.col.x
    from table_a a, table_b b, table_c c
    where a.key = b.key
    and b.key = c.key
    or perhaps c relates back directly to a so it is a.key = c.key where key can be any column whose value is equilivent in what it represents to the value it is being compared to, that is, student_number = student_number or the columns regardless of name are both building numbers, room numbers, etc ....
    This is not your exact solution but it should help.
    HTH -- Mark D Powell --

  • Simple Select query with 'where', 'and', 'between' clauses takes time

    Hi,
    I have a select query as below
    SELECT * FROM (SELECT a.*,ROWNUM currentStartRecord From (select ai_inbound.ai_inb_seq tableseq,'AI_INBOUND' tablename,'INBOUND' direction,ai_inbound.appl,ai_inbound.ai_date datetime,ai_inbound.ic_receiver_id pg_id,ai_inbound.ic_sender_id tp_id,ai_inbound.session_no,ai_inbound.ic_ctl_no,ai_inbound.msg_set_id msg_type,ai_inbound.appl_msg_ctl_no reference_no,ai_inbound.fg_version version,ai_inbound.msg_status status,ai_inbound.input_file_name,ai_inbound.output_file_name,ai_inbound.ack_file_name from ai_inbound where ai_inbound.appl = ? and ai_inbound.ai_date between ? and ? )a where ROWNUM <= 49)where currentStartRecord >= 0
    The above query takes longer time through application than expected when the date fields are passed whereas it works fine when no date fields are passed. We are using oracle9.2 version of the database. All the indexed columns and partitioned indexed columns are rebuild.
    Kindly let me know how can i tune up the query to improve the performance.
    Thanks

    Hi,
    I have a select query as below
    SELECT * FROM (SELECT a.*,ROWNUM currentStartRecord From (select ai_inbound.ai_inb_seq tableseq,'AI_INBOUND' tablename,'INBOUND' direction,ai_inbound.appl,ai_inbound.ai_date datetime,ai_inbound.ic_receiver_id pg_id,ai_inbound.ic_sender_id tp_id,ai_inbound.session_no,ai_inbound.ic_ctl_no,ai_inbound.msg_set_id msg_type,ai_inbound.appl_msg_ctl_no reference_no,ai_inbound.fg_version version,ai_inbound.msg_status status,ai_inbound.input_file_name,ai_inbound.output_file_name,ai_inbound.ack_file_name from ai_inbound where ai_inbound.appl = ? and ai_inbound.ai_date between ? and ? )a where ROWNUM <= 49)where currentStartRecord >= 0
    The above query takes longer time through application than expected when the date fields are passed whereas it works fine when no date fields are passed. We are using oracle9.2 version of the database. All the indexed columns and partitioned indexed columns are rebuild.
    Kindly let me know how can i tune up the query to improve the performance.
    Thanks

  • Select Query Between two dates...

    Hi Guru's,
    I need a Select Query between two dates, also if the record not found for any in between date then it should return NULL or 0 ...
    for Example
    1. I am having two records in DB for date 2-10-2008 & 4-10-2008
    2. Now suppose I have given Query for date between 1-10-2008 to 5-10-2008
    Then it should return me 5 records with valid values for 2 & 4 and NULL for other 1,3,5
    Thanks.

    Try like this:
    with
      t as
          select date '2008-10-02' as dt, 'Record #1 (in DB)' as str from dual union all
          select date '2008-10-04' as dt, 'Record #2 (in DB)' as str from dual
    select v.dt, t.str
      from (
             select date '2008-10-01' + level - 1 as dt
               from dual
             connect by level <= (date '2008-10-05' - date '2008-10-01') + 1
           ) v
      left join t
        on v.dt = t.dt
    order by 1

  • Why cant we use sy-index in loop and endloop?where exactly we used sy-index

    hi
    can u help me for this

    Hi...
    Genereally Sy-index is used in iterative cases like
    while....endwhile
    and
    Do.... Enddo
    In LOOP ..... Endloop.... We should use SY-TABIX....
    It would be more consistent we use sy-tabix as we loop at internal table so this SY-TABIX points to the current record its reading...
    we can use sy-index but rarely depends on condition.....
    SY-INDEX and SY-TABIX will not be same always in LOOP and ENDLOOP
    Rewards points if satisfied..
    Regards
    Narin Nandivada

  • Itunes will not respond to my ipod touch, i have re-installed countless times and it still is not working. i have also tried different USB's and nothing. please help!

    Itunes will not respond to my ipod touch, i have re-installed countless times and it still is not working. i have also tried different USB's and nothing. please help!

    - Try here:
    iOS: Device not recognized in iTunes for Windows
    - Next try a different computer to help determine if you have a computer or iPod problem.

  • I'm trying to reinstall Logic Pro 9, and it says It's already installed. I have a project due for class and I need help asap. Please help!!!

    I'm trying to reinstall Logic Pro 9, and it says It's already installed. I have a project due for class and I need help asap. Please help!!!

    Yea I am. I deleted Logic Pro 9 and moved the App to the Trashcan like normal. Then when I go to install it, it says its already Installed. When I do this with other apps; it works fine, the install thing comes back up like it should once you have deleted the app

  • This morning i tried to restore my ipod and it said:"the ipod "ipod cannot be restored at this time because the ipod software update server could not be contacted or is temporarily unavalible." i have no idea what to do and i need help

    this morning i tried to restore my ipod and it said:"the ipod "ipod cannot be restored at this time because the ipod software update server could not be contacted or is temporarily unavalible." i have no idea what to do and i need help.

    Update Server
    Try:
    - Powering off and then back on your router.
    - iTunes for Windows: iTunes cannot contact the iPhone, iPad, or iPod software update server
    - Change the DNS to either Google's or Open DNS servers
    Public DNS — Google Developers
    OpenDNS IP Addresses
    - For one user uninstalling/reinstalling iTunes resolved the problem
    - Try on another computer/network
    - Wait if it is an Apple problem

  • Does anybody know to have a video of my face and make it start out as a blk

    Does anybody know to have a video of my face and make it start out as a black screen the make it gradually have a white line come up my face?(like the show on cartoon network, is it called "Fosters"?)

    You can do this if you create a key with your face or start with green screening it.
    Use a garbage matte if it is static.

  • I have iPhone 3 OS 6.12 and battery keeps running out very fast.

    I have iPhone 3 OS 6.12 and battery keeps running out very fast.

    Here are the iPhone battery conservation tips.
    iPhone
    Watch some of the things you may have set up as the article suggests.  Check email fetch frequency, push notifications, location services, etc.

  • How to avoid select query in loop

    Hi All,
    I have to select entries from table iclpay looping it_dfkkop and delete the entries in it_dfkkop_tmp which are not present in iclpay.
    For this If use below code its working fine, but there is performance issue
        CLEAR: it_iclpay[],it_iclpay.
        LOOP AT it_dfkkop_tmp.
          SELECT claim documentref paycat status FROM iclpay
                    APPENDING CORRESPONDING FIELDS OF TABLE it_iclpay
                            WHERE
                                  active = c_active AND
                                  claim = it_dfkkop_tmp-claim AND
                                  documentref = it_dfkkop_tmp-opbel.
          IF sy-subrc NE 0.
            DELETE it_dfkkop_tmp.
          ENDIF.
        ENDLOOP.
    If I write the code like below its not working
        SELECT claim documentref paycat status FROM iclpay
                INTO TABLE it_iclpay
                        FOR ALL ENTRIES IN it_dfkkop_tmp WHERE
                              active = c_active AND
                              claim = it_dfkkop_tmp-claim AND
                              documentref = it_dfkkop_tmp-opbel.
    Can anyone help on this.

    It did not dump but did not get final(required) output.
    I got the solution now.
    Thanks a lot for responding.
    I have written the below code
    SELECT claim
               documentref
               paycat
               status
               FROM
               iclpay
               APPENDING CORRESPONDING FIELDS OF TABLE it_iclpay
               FOR ALL ENTRIES IN it_dfkkop_tmp WHERE
                                  active = c_active AND
                                  claim = it_dfkkop_tmp-claim AND
                                  documentref = it_dfkkop_tmp-opbel.
        SORT it_dfkkop_tmp BY claim opbel.
        LOOP AT it_dfkkop_tmp.
          READ TABLE it_iclpay INTO  wa_iclpay WITH KEY
                              claim        = it_dfkkop_tmp-claim
                              documentref  = it_dfkkop_tmp-opbel.
          IF sy-subrc NE 0.
            DELETE it_dfkkop_tmp.
          ENDIF.
        ENDLOOP.

  • How to assign table name for select query in loop.

    Hi friends my requirement is count the no of records of all the database table which comes into an internal table ."Check the below coding". Iam  fetching the tables from dd03l table into an internal table .plz give me a sujjesion how to assign a table name in select query  in a loop.
      SELECT tabname FROM dd09l
                INTO TABLE i_dd09l
                WHERE protokoll = 'X'.
      IF sy-subrc = 0.
        SORT i_dd09l BY tabname.
      ENDIF.
      LOOP AT i_dd09l.
        SELECT COUNT(*) INTO val FROM i_dd09l-tabname.
        IF sy-subrc = 0.
          i_dd09l-count = val.
        ENDIF.
        MODIFY i_dd09l INDEX sy-index.
        CLEAR val.
      ENDLOOP.
    error : 'I_DD09L-TABNAME' is not defined in the abap dictionary as a table.

    data: dy_table type ref to data,
          dy_line type ref to data,
          xfc type lvc_s_fcat,
          ifc type lvc_t_fcat,
          dy_field type ref to data.
    LOOP AT i_dd09l.
    perform get_structure using i_dd09l-tabname .
    CREATE DATA dy_table TYPE TABLE OF (_dd09l-tab_name).
        UNASSIGN <dyn_table>.
        ASSIGN dy_table->* TO <dyn_table>.
    SELECT COUNT(*) INTO val FROM <dyn_table>.
    IF sy-subrc = 0.
    i_dd09l-count = val.
    ENDIF.
    MODIFY i_dd09l INDEX sy-index.
    CLEAR val.
    ENDLOOP.
    form get_structure using p_table.
      data : idetails type abap_compdescr_tab,
      xdetails type abap_compdescr.
      data : ref_table_des type ref to cl_abap_structdescr.
    Get the structure of the table.
      ref_table_des ?=
      cl_abap_typedescr=>describe_by_name( p_table ).
      idetails = ref_table_des->components.
      loop at idetails into xdetails.
        clear xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        append xfc to ifc.
      endloop.
    endform.                    "get_structure
    Try like this hope it will work.
    Regards,
    madan.

  • In  RSA1 transaction, I written SELECT QUERY while compile It shows error

    Hi All,
                   While compile my SELECT query in RSA1 trans, ENDROUTINE, It show error...
                Select single MAX( date )
                         from dbtable
                         into W_DATE
                        where DOC_NUMBER = w_itab-DOC_NUMBER
                          and S_ORD_ITEM = w_itab-S_ORD_ITEM
                          and Plant     = 'number'.
    ERROR
    E:Unknown column name " date ". not determined until runtime, you
    cannot specify a field list.
    help me please
    reward

    Hi,
    make sure the column 'date' exists in your dbtable. If that is the case, you may be need to take out the spaces in ( date ).
    regards
    Siggi

  • Query between docdate and doctime

    Hi,
    I am having trouble in my query.I want to get the date that has date between 03/09/2015 and 03/10/2015 and time between 6:00AM of 03/09/2015 and 7:00AM of 03/10/2015 but it only show date with time between 6:00AM and 7:00Am of each date.
    This is my query
    SELECT T0.[DocDate], T0.[DocNum], T1.[Dscription], T1.[Quantity],T0.[DocTime] FROM OIGN T0  INNER JOIN IGN1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[DocDate] between [%0] and [%1] and T0.[DocTime] >= [%2] and T0.[DocTime]<=[%3]
    Thanks,
    Raphael

    Hi Raphael Mendoza
    Have you check the database does it have data between those time slot...
    Also you use between option
    SELECT T0.[DocDate],
       T0.[DocNum],
       T1.[Dscription],
       T1.[Quantity],
       T0.[DocTime]
    FROM OIGN T0
    INNER JOIN IGN1 T1 ON T0.DocEntry = T1.DocEntry
    WHERE T0.[DocDate] BETWEEN [%0] AND [%1]
      AND T0.[DocTime] BETWEEN [%2] AND [%3]
    Regards
    Kennedy

  • Select row between x and y

    Hi,
    ;WITH CTE AS
    ( SELECT tblFuelCostDetails.TripId, tblFuelCostDetails.PurchaseDate, tblPetrolPumps.PumpName as Pump
    FROM           tblPetrolPumps INNER JOIN
    tblFuelCostDetails ON tblPetrolPumps.PumpId = tblFuelCostDetails.PumpId
    SELECT distinct TripID, PurchaseDate,DENSE_RANK() OVER (ORDER BY TripID) AS RowNumber,
        STUFF((SELECT ', '+Pump FROM CTE P2 WHERE P1.TripID = P2.TripID AND P1.PurchaseDate = P2.PurchaseDate
        FOR XML PATH('')),1,1,'') AS Pump    
        FROM CTE P1   
    This query output is,
    TripID
    PurchaseDate
    RowNumber
    Pump
    73
    1/15/2014
    1
     N.R, Masranga
    74
    1/16/2014
    2
     N.R
    75
    1/12/2014
    3
    JK
    76
    1/13/2014
    4
    YUJ
    77
    1/14/2014
    5
    UYI
    How can i get RowNumber between 2 and 4

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules (you did not). Temporal
    data should use ISO-8601 formats (you failed this basic IT standard! Shame on you!). Code should be in Standard SQL as much as possible and not local dialect. 
    Did you know that putting “tbl-” is such a bad coding practice it has name? You actually Tibbled! 
    >> I am trying to load time dimension in a specific order <<
    A table has no ordering by definition. Let me say that again, so you will hear this: A table has no ordering by definition. You have completely missed the foundations of RDBMS. 
    Your code is also bad. Why did you rename “pump_name” (a valid data element name) to “pump” (vague and invalid)? Why do you think naming a CTE to “CTE” is informative? 
    Why are you destroying First Normal Form with XML??? Are you smarter than Dr. Codd? I would fire you for this kind of sloppy coding. 
    Do you know how rate SELECT DISTINCT is in a good schema? We usually use a key in the queries so there are not redundant rows. But since we have no DDL and no sample data, we cannot help you clean up this mess. Your query is simply this:
    SELECT F.trip_nbr, F.purchase_date, P.pump_name 
      FROM Petrol_Pumps AS P, Fuel_Cost_Details AS F
     WHERE P.pump_nbr = F.pump_nbr;
    Now pass the result set to a presentation layer, as per any tiered architecture. Since we have no logical rule for the subset you want, adding a DENSE_RANK() may not do what you want. Why order by trip_nbr? This is a tag number, not part of a sequence. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

Maybe you are looking for

  • Output_text converter in EA4 no longer working

    I have been using the NumberFormat converters in EA3 for output_text with no problem. Now I am trying out EA4 and the standard converters have stopped working. So, I have build my own converter and registered it in faces-config.xml just like in carde

  • Problems upgrading from 10.2 to 10.3

    I'm trying to upgrade my eMac OS X 10.2 to 10.3. I put in the first installation CD, and followed the steps but now it's stuck. On the page that says "Select a Destination," no destinations show up in the box. I've restarted and tried many times but

  • Best way to warp type around a cylinder

    I need to warp type around a bottle to it curves up on the left and right and also condenses slightly at the edges (as it visually does). Using the mesh function not only doesn't squeeze the type correctly I can't grab more than one bezier handle at

  • LSO without CMS

    Dear Experts, Can we configure LSO without configuring Content Management Server (CMS), Is there any possibility or way around? All replies with be highly appreciated. Regards, FG

  • ISync with Motorola PEBL U9

    Is it possible to use ISync to synchronize contacts with the brand new Motorola ROKR PEBL U9? I have tried to do it connecting the cell phone through USB and Bluetooth, but ISync does not recognize the cell phone when I connect it through the USB Por