Data fetching problem in select query

HI Expert,
               Pls check the below code as data is not fetching due to BGMKOBJ-OBJNR(22)  not equal to EQKT-EQUNR(18).
select  EQUNR
        EQKTX
       from EQKT into corresponding fields of table IT_EQKT
       from EQKT into table IT_EQKT
         into table IT_EQKT
         from EQKT
       for all entries in IT_BGMKOBJ
       for all entries in IT_ITOB
         where EQUNR = IT_ITOB-OBJNR
        and spras eq 'EN'.
Pls help me with code.
Thanks & Regards,
Singha

Create a new internal table with the field EQUNR with BGMKOBJ-OBJNR values and do for all entries on this table.There is no alternative on this.
e.g,
types: begin of t_equnr,
equnr type EQKT-EQUNR,
end of t_equnr.
data : it_equnr type table of t_equnr,
         wa_equnr type t_equnr.
loop at IT_BGMKOBJ into wa_BGMKOBJ .
wa_equnr-equnr  =  wa_BGMKOBJ-OBJNR.
append wa_equnr to it_equnr.
endloop.
select EQUNR
EQKTX
from EQKT into corresponding fields of table IT_EQKT
from EQKT into table IT_EQKT
into table IT_EQKT
from EQKT
for all entries in IT_BGMKOBJ
for all entries in it_equnr
where EQUNR = it_equnr-EQUNR

Similar Messages

  • Can I retrieve data from a multiple select query?

    I recently have been able to consolidate many queries into one large one, or into large compound queries. I found an instance where I am using a select query in a for loop that may execute up to 400 times. I tried building a huge compound query, and using DB Tools Execute Query vi, followed by the DB Tools Fetch Recordset Data vi. The query executes at the database without an error, but the Fetch Recordset Data vi only returns the first instance. Is there a way to retrieve all the data without having to send up to 400 separate select queries?

    Sorry I didn't replt earlier, I was on vacation. The query I am using is to check serial numbers, and determine if they are all valid. The programs purpose is to define a serial number to a pre-existing part number. Our company makes inclinometers and accelerometers, and this entire series of LabVIEW programs is designed to automate the calibration and testing of these units. The part number definitions can contain 3 or 4 hundred parameters, so the database itself consistes of 44 tables with potentially several hundred columns per table. It is designed to not only provide definitions to every part number, but also to store all potential raw unit data to be calculated and formed into a report at any time. The logistics of getting that much data in and out of the database have forced me to do things more effeciently. The actual query in question is to take each serial number either manually entered, or automatically picked, and see if they already exist with the part number they are being defined as. If there are any duplicates, then the program will alert the operator that serial numbers x, y, and z for instance have already been asigned as the part number in question. Currently I run a simple query once for each serial number. This works, but there may be 200 serial numbers assigned. Also the serial numbers can contain upper or lower case letters. By making all the serial number letters into capitals, then into lower case, it could mean up to 400 individual queries going out over the LAN. This is a bandwidth hog, and time consuming. I started experimenting with compound queries. The actual query used is below.
    SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000005';SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000006';SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000007';SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000008';SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000009'
    When I execute this query, SQL Server 2000 has no problem with it, but the DB Tools Fetch Recordset Data vi only returns the first match. I think my answer may lie with OR statements. Rather than sending what amounts to potentially dozens of individual queries, I should be able to chain them into one query with a lot of OR statements. As long as the OR statement is not an exclusive OR statement, I think it should work. I haven't tried it yet, and it may take some time to get the syntax right. The query is built in a for loop with the number of iterations equal to the number of serial numbers being defined. Once I get this working I will alter it to include both upper and lower case letters that can be included in the query. Any suggestiona of how the query should be structured would be most helpful, or another way to achieve what I am trying to accomplish.
    SciManStev

  • Performance Problem in Select query

    Hi,
    I have performance Problem in following Select Query :
    SELECT VBELN POSNR LFIMG VRKME VGBEL VGPOS
      FROM LIPS INTO CORRESPONDING FIELDS OF TABLE GT_LIPS
       FOR ALL ENTRIES IN GT_EKPO1
       WHERE VGBEL = GT_EKPO1-EBELN
         AND VGPOS = GT_EKPO1-EBELP.
    as per trace i have analysed that it is fetch the complete table scan from the LIPS table and table contants almost 3 lakh records.
    Kindly Suggest what we can do to optimize this query.
    Regards,
    Harsh

    types: begin of line,
              vbeln type lips-vbeln
              posnr type lips-posnr
              lfimg type lips-lfimg
             vrkme type lips-vrkme
             vgbel type lips- vgbel
             vgpos type lips-vgpos
             end of line.
    data: itab type standard table of line,
             wa type line.
    IF GT_EKPO1[] IS NOT INITIAL.
    SELECT VBELN POSNR LFIMG VRKME VGBEL VGPOS
    FROM LIPS INTO  TABLE ITAB
    FOR ALL ENTRIES IN GT_EKPO1
    WHERE VGBEL = GT_EKPO1-EBELN
    AND VGPOS = GT_EKPO1-EBELP.
    ENDIF.

  • Problem in select query in QUERY INFOSET

    Hi All
    I have requirement to find the sales text maintained for sales order in mass in production. By using the FM READ_TEXT i can pass the necessary values to get the sales text. We dont want to write a program and then transprot to P01. So what i did in SQ02 i create a infoset and worte code in the infoset. Here i am facing the problem that in the select query where clause what ever  on the selection screen values, for that the query need to fetch the records. But selection screen is dymically selected based on SQVI t-code.
    In select query if i write like this
    SELECT TDOBJECT TDNAME TDID TDSPRAS
           FROM STXH
           INTO TABLE IT_TEXT_DETAIL
           WHERE TDOBJECT     EQ C_KNMT .
    Here i have hardcoded KNMT so it will fetch only that value irrespective of any values on the selection screen. How to get the values based on the selection screen. I debugged the query it automatically generates the code for selection screen which i am not able to pass in the program.
    SAP has generated this code
    select-options SP$00004 for STXH-TDOBJECT.
    select-options SP$00005 for STXH-TDNAME.
    select-options SP$00006 for STXH-TDID.
      If i pass SP$00004 on where clause its giving me error. So how to pass it dynamically. Waiting for experts answer.
    Regards
    Vijay

    Hi Vijay,
    In this case concatenate 'TDOBJECT' 'EQ' C_KNMT INTO V_WHERE (Say) SEPERATED BY SPACE.
    DATA : v_where(90) type c.
    clear v_where.
    CONCATENATE  'TDOBJECT'
                               'EQ'
                               C_KNMT
                               INTO V_WHERE
                               SEPERATED BY SPACE.
    SELECT TDOBJECT TDNAME TDID TDSPRAS
           FROM STXH
           INTO TABLE IT_TEXT_DETAIL
           WHERE (V_WHERE) .
    Try to do this and let me know in case of any.
    Regards,
    SRinivas

  • Problem in select query

    Hi Friends
    I am using a table a981 and fetching data in internal table but the table has a fieil Country whose technical name is ALAND in dev and LAND1 in production.Now i cannot use LAND1 as it wont let me to activate the report and if i use ALAND i cannot move the request to production as it fails. So how can i achive dynamic table field in the select query based on server.My query is-
    select kschl
               wkreg
               matnr
               knumh
       from a981 into corresponding fields of table it_a981
       for all entries in it_marc where matnr = it_marc-matnr
                                    and kschl in ('MWST','ZSER')
                                    and aland = 'IN'
                                    and datab le sy-datum
                                    and datbi ge sy-datum.
    I need to make aland dynamic.Pls suggest

    If you insist on having a workaround, you could always create dynamic WHERE conditions.
    DATA: cond TYPE string.
    IF sy-sysid EQ <your dev sysid>.
        cond = 'matnr = it_marc-matnr
                and kschl in (''MWST'',''ZSER'')
                and datab le sy-datum
                and datbi ge sy-datum'
                and land1 = ''IN''.
    ELSE.
        cond = 'matnr = it_marc-matnr
                and kschl in (''MWST'',''ZSER'')
                and datab le sy-datum
                and datbi ge sy-datum'
                and aland = ''IN''.
    ENDIF.
    select kschl
               wkreg
               matnr
               knumh
       from a981 into corresponding fields of table it_a981
       for all entries in it_marc where (cond).
    Kyle

  • Time out problem for select query

    I am fetching data from BKPF for my report.
    I have written following query.But this query always time out.
    SELECT
        BUKRS
        BELNR
        GJAHR
        BLART
        BLDAT
        BUDAT
        MONAT
        XBLNR
        BKTXT
        WAERS
        KURSF
        HWAER
        FROM BKPF
        INTO TABLE I_BKPF
        WHERE BUKRS IN S_BUKRS
         AND BELNR IN S_BELNR
         AND GJAHR IN S_GJAHR
         AND BLART IN S_BLART
         AND BLDAT IN S_BLDAT
         AND BUDAT IN S_BUDAT
         AND MONAT IN S_MONAT
         AND CPUDT IN S_CPUDT
         AND BSTAT = SPACE.
    So please suggest me solution.

    Hi..
    1) Try to make Some of the Fields such as BUKRS , GJAHR  as PARAMETERS so that ROWS are restrited mostly.
    2) Make fields like BLDAT and BUDAT as OBLIGATORY if possible.
    3) And in the SELECT query add the PACKAGE SIZE addition.
    <b>Reward if Helpful.</b>

  • Data fetch problem from EBAN table

    Hi All,
    I have a problem in data fetching. My SQL statement is
            SELECT    A~BANFN
                      A~FRGDT
                      A~MATNR
                      A~MENGE
                      A~MEINS
                      A~AFNAM
                      A~EKGRP
                      A~PRIO_URG
                      A~STATU
                      A~RLWRT
                      A~EBELN
                      A~LOEKZ
                      A~EBELP
                      A~FRGKZ
              INTO CORRESPONDING FIELDS OF TABLE ITAB_DATA
              FROM EBAN AS A
              WHERE     A~STATU IN S_STATU
              AND       A~EKGRP  = S_EKGRP
              AND       A~BANPR  = '05'
              AND       AFNAM  IN P_AFNAM
              AND       BEDNR  IN P_BEDNR .
    In EBAN table data in AFNAM field is like 'Mech', 'mech' & 'Mech'
    Now in selection screen if user give Mech then system picks only that data where 'Mech' is there but requirement is it should pick all data related to ('Mech', 'mech', 'Mech') in AFNAM field. How do I do?
    Thanks and regards,
    Rajesh Vasudeva

    Hello,
    What you ask is not easy but it is feasible.
    We had the same request to make a case-insensitive search on a text field.
    As a reference for our development we took the following example:
    [http://wiki.sdn.sap.com/wiki/display/Snippets/CaseInsensitiveSearchHelpExitforMaterialGroup|http://wiki.sdn.sap.com/wiki/display/Snippets/CaseInsensitiveSearchHelpExitforMaterialGroup]
    In short : the purpose is that first of all you build up a list of all possible values in a separate internal table.
    Then use this separate internal table in the FOR ALL ENTRIES clause when you perform the select on the actual data.
    Success.
    Wim

  • Problem is select query.

    Hello SDNites,
    I have a req where I need to use select query to fetch data. But the conditions which is to be placed in this select query has 3 checkboxes corresponding to the same field. Either of them can be selected at a time. Please let me know how can we put this condition effectively in one select query.
    Thanks,
    Abhishek

    Hi Abhishek,
    Depending on your check box selection u can concatenate the string for where ckause....
    For eg:-
    concatenate `'` 'A' `'` into fs.
    concatenate `'` 'F' `'` into fs1.
    if cb1 = 'X' and CB2 = 'X'.
    CONCATENATE  'bstyp' '='   FS  'OR' 'bstyp' '='  FS1  INTO FS SEPARATED BY SPACE.
    endif.
    select * from dbtab into table itab where (fs).
    depending on ur check box selection u can change ur VARIABLE FS to be used in where clause....... But u just need to use single select query.

  • Problem with select query

    Hi All,
    i_dfkkko-xblnr
      IF NOT i_dfkkko[] IS INITIAL       .
        SELECT opbel
               belnr
               FROM erchc
               INTO TABLE i_erchc1
               FOR ALL ENTRIES IN i_dfkkko
               WHERE opbel EQ i_dfkkko-xblnr.
      ENDIF.
    I am using the above select query.problem is when i put the value
    of i_dfkkko-xblnr by going to the table erchc i am getting the record.But this qury is not resulting any value.
    i have checked in debug mode copied the value of xblnr of i_dfkkko
    and went to erchc table and passed to opbel of erchc i got the reords.
    can anybody pls help..
    Rgds,
    Sai

    Hi,
    The database would be having the value with leading zeroes.
    Use FM "CONVERSION_EXIT_ALPHA_INPUT" to conver the values & then pass to select query.
    _dfkkko-xblnr
    IF NOT i_dfkkko[] IS INITIAL .
    loop at i_dfkkko.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
    VALUE(INPUT) = i_dfkkko-xblnr
    IMPORITNG
    VALUE(OUTPUT) = i_dfkkko-xblnr.
    modify i_dfkkko.
    endloop.
    SELECT opbel
    belnr
    FROM erchc
    INTO TABLE i_erchc1
    FOR ALL ENTRIES IN i_dfkkko
    WHERE opbel EQ i_dfkkko-xblnr.
    ENDIF.

  • Add Minutes to Date Time Stamp in Select Query

    Hi,
    I have date in one column and Minutes (240,480,.....etc) in another column.
    Below is the date format which i select in select query, now how should i add date column below with Minutes Column.
    to_char(Last_update_date,'DD/MM/YYYY HH:MI:SS AM')
    Thanks
    Pravin

    892547 wrote:
    Hi,
    I have date in one column and Minutes (240,480,.....etc) in another column.
    Below is the date format which i select in select query, now how should i add date column below with Minutes Column.
    to_char(Last_update_date,'DD/MM/YYYY HH:MI:SS AM')
    Thanks
    Pravinyou can NOT add to character datatype.
    what datatype is MINUTES column?

  • Offset problem in select query

    Hi experts,
    I have a select query , in my where condition , comparing fields types are different
    following is my select query
    SELECT spras  prctr  ktext FROM cepct INTO CORRESPONDING FIELDS OF TABLE it_cepct FOR ALL ENTRIES IN it_vbsegd
                                                               WHERE prctr = it_vbsegd-bupla .
    here prctr length = 10
    and bupla length = 4.
    we can give offset after "=" sign, but i want to use on prctr field,  could anybody please give me some idea to achieve this.
    thanks in advance

    Hi,
    created another internal table it_tab to get the result which you wanted.
    DATA : it_cepct TYPE TABLE OF cepct,
               it_vbsegd TYPE TABLE OF vbsegd,
               wa_vbsegd type vbsegd.
    TYPES : BEGIN OF ty_tab,
             bupla(10),
             END OF ty_tab.
             DATA : it_tab TYPE TABLE OF ty_tab,
                    lv_bupla(10).
       select * UP TO 2 ROWS  FROM vbsegd INTO TABLE it_vbsegd.
       loop at it_vbsegd INTO wa_vbsegd.
         UNPACK wa_vbsegd-bupla to lv_bupla.
         append lv_bupla to it_tab.
         CLEAR : lv_bupla,wa_vbsegd.
       ENDLOOP.
       SELECT spras  prctr  ktext FROM cepct INTO CORRESPONDING FIELDS OF TABLE it_cepct FOR ALL ENTRIES IN it_tab
                                                                WHERE prctr = it_tab-bupla.

  • Reg: Problem in select query..

    Hi all,
    I want to write a select query for table COEP. Like if you open SE16 and give KSTAR with S5* we will get full data related to S5xxxxx. Same like I am trying to write for select.
    TYPES: BEGIN OF T_COEP,
             BELNR  TYPE CO_BELNR,  " PLANT
             PERIO  TYPE CO_PERIO,  " Period
             KSTAR  TYPE KSTAR,     " Cost Element
             WERKS  TYPE WERKS_D,   " PLANT
             MATNR  TYPE MATNR,     " Material Number
           END OF T_COEP.
    data: I_COEP   TYPE STANDARD TABLE OF T_COEP,
          W_COEP   TYPE T_COEP.
      SELECT BELNR  " DOCUMENT NO
             PERIO  " Period
             KSTAR  " Cost Element
             WERKS  " PLANT
             MATNR  " Material Number
        FROM COEP
        INTO CORRESPONDING FIELDS OF TABLE I_COEP
        WHERE KSTAR = C_S5.(HERE want I need give)*
      LOOP AT I_COEP INTO W_COEP.
        WRITE:/ W_COEP-BELNR, W_COEP-PERIO, W_COEP-KSTAR,
                W_COEP-WERKS, W_COEP-MATNR.
      ENDLOOP.
    Moderator message - Please search before asking - post locked
    Edited by: Rob Burbank on May 15, 2009 1:34 PM

    Hi,
    write the code like this..
       SELECT BELNR  " DOCUMENT NO
              PERIO  " Period
              KSTAR  " Cost Element
              WERKS  " PLANT
              MATNR  " Material Number
         FROM COEP
         INTO CORRESPONDING FIELDS OF TABLE I_COEP
         *WHERE KSTAR = C_S5*.(HERE want I need give)*
          where kstar in 'c_s%'.     "write % it will acts like *
    Regards,
    Prabhudas

  • PROBLEM WITH MY DATE BETWEEN CLAUSE IN SELECT QUERY

    WHEN I RUN THE CODE IT'S FETCHING DATA FROM 2007,2008,2009.
    SELECT ERDAT VBELN NETWR
    FROM VBRK INTO CORRESPONDING FIELDS OF TABLE IT_VBRK
    WHERE ERDAT BETWEEN '01.11.2008' AND '30.11.2008'.
    PLEASE GIVE ME A SOLUTION GUYS.

    Hi, Zubaer,
    Please Don't Use All Caps in Subject and Body Text too
    Have a look at [Rules of Engagement|https://www.sdn.sap.com/irj/scn/wiki?path=/display/home/rulesofEngagement]
    Under Heading
    - Use a Good Subject Line
    Do not use words in capital letters
    Use the following way. it will solve out your Problem,
    SELECT erdat vbeln netwr
    FROM vbrk INTO CORRESPONDING FIELDS OF TABLE it_vbrk
    WHERE erdat BETWEEN '20081101' AND '20081130'.
    Best Regards,
    Faisal

  • Problem with select query that includes a date

    I've been fighting with this for about 4 hours - yes, quite literally... I've never been good with date stuff. I have a brain block.
    Anyway, here's the situation:
    I have an Access database that has a time/date field. There are no times, just a date in mm/dd/yyyy format.
    That table is a list of classes held for the past three years. I want to make a query that only shows the classes that have ended after January 1 of this year. I don't want to put 01/01/2010 in the query itself because I want it to still work next year.
    This is the current query:
    <cfquery name="classes" datasource="#DSN#" dbtype="ODBC">
    SELECT classesTitles.ClassTitle, classesTitles.ClassDesc, classCatagories.catagoryName, classes.classStart, classes.classEnd, classes.classNotes, owners.fName, owners.lName, classTime.timeSlot, classes.classID, classes.classLimit
    FROM classCatagories INNER JOIN (((classes INNER JOIN classesTitles ON classes.classTitle = classesTitles.classTitleID) INNER JOIN classTime ON classes.classTime = classTime.timeID) INNER JOIN owners ON classes.classInstructor = owners.ownerID) ON classCatagories.catagoryID = classesTitles.ClassType
    WHERE  classes.classEnd <  01/01/#DatePart("yyyy", now())#
    ORDER BY classes.classStart, classCatagories.catagoryName, classTime.timeSlot, classesTitles.ClassTitle
    </cfquery>
    I don't get any results, but I should get a list of every class that has an end date before January 1 of this year - about 200 records.
    When I swap around the where clause to:
    <cfquery name="classes" datasource="#DSN#" dbtype="ODBC">
    SELECT classesTitles.ClassTitle, classesTitles.ClassDesc, classCatagories.catagoryName, classes.classStart, classes.classEnd, classes.classNotes, owners.fName, owners.lName, classTime.timeSlot, classes.classID, classes.classLimit
    FROM classCatagories INNER JOIN (((classes INNER JOIN classesTitles ON classes.classTitle = classesTitles.classTitleID) INNER JOIN classTime ON classes.classTime = classTime.timeID) INNER JOIN owners ON classes.classInstructor = owners.ownerID) ON classCatagories.catagoryID = classesTitles.ClassType
    WHERE  classes.classEnd > 01/01/#DatePart("yyyy", now())#
    ORDER BY classes.classStart, classCatagories.catagoryName, classTime.timeSlot, classesTitles.ClassTitle
    </cfquery>
    I get EVERY class in the database, and I should only be getting about 50
    The classes are about 8 weeks long, the begin date and end date are in the database as date/time fields, so I need to show everything that ended in 2010, regardless of when it started.
    I'm sure it's something glaringly obvious, but it's escaping me.
    THANKS
    Michelle

    The format of your date field in access is irrelevent to the situation at hand.  Use proper date objects instead of trying to build a suitable string.  For the first of January of the current year, the coldfusion functions createdate(), year(), and now() are your freinds.  Then, in case Adam's post was not clear, use cfqueryparam with the resulting variable.

  • Problem with Select query fetching records.

    Hi All,
    SELECT bukrs belnr gjahr bldat cpudt aedat cputm usnam xblnr bktxt waers
                       FROM bkpf INTO TABLE bkpf_tbl
                       WHERE bukrs IN s_bukrs AND blart IN ('RE' , 'ZL')
    AND ( ( cpudt > prv_date )
                       OR    ( cpudt = prv_date AND cputm >= prv_time ) )
                       OR  ( ( aedat > prv_date )
                       OR    ( aedat = prv_date AND cputm >= prv_time ) )
                       AND gjahr IN s_gjahr
                       AND monat IN s_monat
                       AND belnr IN s_belnr
    My prv_date is 05/04/2010 while debugging.
    CPUDT (Accounting Document Entry Date) in BKPF doesnu2019t have any entries.
    But AEDAT (Date of the Last Document Change by Transaction) is having a single entry on date 05/04/2010.
    While this query is showing number of records around 200000. I feel something is wrong with the AND/OR statements.
    Please suggest some ideas?

    Hi Mishra,
    I dont know the excaly wht u r passing in the prv_date and cpudt . But one thing i notice that blart part.
    SELECT bukrs belnr gjahr bldat cpudt aedat cputm usnam xblnr bktxt waers
                       FROM bkpf INTO TABLE bkpf_tbl
                       WHERE bukrs IN s_bukrs AND blart eq  'RE' or  blart eq 'ZL'
      AND ( ( cpudt > prv_date )
                       OR    ( cpudt = prv_date AND cputm >= prv_time ) )
                       OR  ( ( aedat > prv_date )
                       OR    ( aedat = prv_date AND cputm >= prv_time ) )
                       AND gjahr IN s_gjahr
                       AND monat IN s_monat
                       AND belnr IN s_belnr.
    With Regards,
    Sumodh.P

Maybe you are looking for