Select query join problem

hey guys,
i've used a select query to get details from KNA1, KNVV, ADRC, KNVP, pa0002. tables by joining. but i'm getting only about 170 records. there are more than 3000 records in the database. for each tables. here is my select query
SELECT KNA1KUNNR KNA1NAME1 KNA1NAME2 ADRCSTR_SUPPL1 ADRCSTR_SUPPL2 ADRCSTR_SUPPL3 ADRCCITY1 KNVVVWERK KNVPPERNR PA0002VORNA PA0002NACHN KNVVVKBUR KNVVKDGRP KNA1STCD1 KNA1~STCEG
    INTO CORRESPONDING FIELDS OF TABLE IT_FINAL FROM KNA1
    INNER JOIN KNVV ON KNA1KUNNR = KNVVKUNNR
    INNER JOIN ADRC ON KNA1ADRNR = ADRCADDRNUMBER
    INNER JOIN KNVP ON KNA1KUNNR = KNVPKUNNR
    INNER JOIN PA0002 ON KNVPPERNR = PA0002PERNR
    WHERE KNA1KUNNR IN S_KUNNR AND KNVVVWERK in P_VWERK AND PA0002PERNR IN S_PERNR AND KNVVVKBUR IN S_VKBUR AND KNVV~KDGRP IN S_KDGRP.
can anyone tell me the problem in the above query.
thanks.

Hi
you are using tables KNA1, KNVV, ADRC, KNVP, pa0002.
Create internal table for each table mentioned above with all the primary keys and find the links between them
then select data in one table and select data from another table into your internal table for all the entries exists in firs internal table.
go for below links.
http://www.sapdev.co.uk/abap/commands/select_forallentries.htm
http://wiki.sdn.sap.com/wiki/display/ABAP/FORALLENTRIES-Home+page
http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_ITAB.htm
Thanks
lalit

Similar Messages

  • Query/join problem

    Does anyone see any issues in my query/join?
    Select c.case_id, a.business_unit, a.field_name, a.change_date, a.old_value, a.new_value, a.created_by, a.creation_date, c.provider_group_id, c.creation_date, c.closed_dttm
    From ps_case c, ps_case_history_audit a
    where
    a.case_id = c.case_id and
    a.field_name = 'case_status' and
    a.new_value = 'Open - Dispatch' and
    a.created_by like '%tag%' and
    c.provider_group_id like '%tag%' and
    c.closed_dttm between '03-NOV-2013' and '10-NOV-2013'
    SQL Dev: All Rows Fetched: 0   But it should be returning something with the stated parameters.

    Hi,
    I'm willing to share what I know about SQL to help solve this problem.  Are you willing to share what you know about the data and the application?
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you expect from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002
    "0 rows found" is sometimes the correct answer.  Why do you think it's not in this case?
    If c.closed_dttm is a DATE (or a TIMESTAMP) then you shouldn't be comparing it to strings, as in
    c.closed_dttm between '03-NOV-2013' and '10-NOV-2013'
    However, that would probably produce too many rows in this case, not too few.
    At any rate, compare DATEs to other DATEs, for example
    c.closed_dttm between TO_DATE ('03-NOV-2013', 'DD-MON-YYYY') and ...
    If this isn't the cause of today's problem today, it will be tomorrow's.

  • 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

  • HELP - Query Join Problem

    I am trying to write a query to return data from 4 different tables and it is doubling my summed values. I can get the separate queries to work, but not combined and I need them combined so that I can get a balance due and limit the records to only those that had a total billed (fees) less than $200.
    Query #1 Gets the total of the fees due for each appeal type and invoice:
    Note: There is always at least one fee attached to an invoice.
    SELECT APT.APTY_DESCR "APPEAL TYPE",
    INV.INVC_ID_SEQ INVOICE,
    SUM( ALL FEE.AMT_DUE) "TOTAL BILLED AMOUNT"
    FROM WRD_APPEALS AP,
    WRD_INVOICES INV,
    WRD_FEES_DUE FEE,
    WRD_APPEAL_TYPES APT
    WHERE AP.APST_CD = 'PEND'
    AND AP.INVC_ID_SEQ = INV.INVC_ID_SEQ
    AND AP.INVC_ID_SEQ = FEE.INVC_ID_SEQ
    AND AP.APTY_CD = APT.APTY_CD
    GROUP BY APT.APTY_DESCR, INV.INVC_ID_SEQ
    ORDER BY APT.APTY_DESCR, INV.INVC_ID_SEQ
    4     BILLING CATEGORY INCORRECT     4147     1200
    5     BILLING CATEGORY INCORRECT     4203     1100
    6     BILLING CATEGORY INCORRECT     4216     72600
    7     BILLING CATEGORY INCORRECT     4826     1000
    8     BILLING CATEGORY INCORRECT     4951     2060
    Query #2 Gets the total amount paid for each appeal type and invoice:
    Note: An invoice may or may not have a payment, thus the outer join.
    SELECT APT.APTY_DESCR "APPEAL TYPE",
    INV.INVC_ID_SEQ INVOICE,
    SUM(ALL PMT.PAID_AMT) "AMOUNT PAID"
    FROM WRD_APPEALS AP,
    WRD_INVOICES INV,
    WRD_APPEAL_TYPES APT,
    WRD_PAYMENTS PMT
    WHERE AP.APST_CD = 'PEND'
    AND AP.INVC_ID_SEQ = INV.INVC_ID_SEQ
    AND AP.APTY_CD = APT.APTY_CD
    AND INV.INVC_ID_SEQ = PMT.INVC_ID_SEQ(+)
    GROUP BY APT.APTY_DESCR, INV.INVC_ID_SEQ
    ORDER BY APT.APTY_DESCR, INV.INVC_ID_SEQ
    4     BILLING CATEGORY INCORRECT     4147     200
    5     BILLING CATEGORY INCORRECT     4203     0
    6     BILLING CATEGORY INCORRECT     4216     72600
    7     BILLING CATEGORY INCORRECT     4826     
    8     BILLING CATEGORY INCORRECT     4951     
    Combined Query - Gets all of the above as well as the balance due. Note the doubled values for some records.
    SELECT APT.APTY_DESCR "APPEAL TYPE",
    INV.INVC_ID_SEQ INVOICE,
    SUM( ALL FEE.AMT_DUE) "TOTAL BILLED AMOUNT",
         SUM(ALL PMT.PAID_AMT) "AMOUNT PAID",
         (SUM(ALL FEE.AMT_DUE) -
         NVL2(SUM(ALL PMT.PAID_AMT), SUM(ALL PMT.PAID_AMT), 0)) "BALANCE DUE"
    FROM WRD_APPEALS AP,
    WRD_INVOICES INV,
    WRD_FEES_DUE FEE,
    WRD_APPEAL_TYPES APT,
         WRD_PAYMENTS PMT
    WHERE AP.APST_CD = 'PEND'
    AND AP.INVC_ID_SEQ = INV.INVC_ID_SEQ
         AND INV.INVC_ID_SEQ = PMT.INVC_ID_SEQ(+)
         AND INV.INVC_ID_SEQ = FEE.INVC_ID_SEQ
         AND AP.APTY_CD = APT.APTY_CD
    GROUP BY APT.APTY_DESCR, INV.INVC_ID_SEQ
    ORDER BY APT.APTY_DESCR, INV.INVC_ID_SEQ,
    4     BILLING CATEGORY INCORRECT     4147     1200     400     800
    5     BILLING CATEGORY INCORRECT     4203     2200     0     2200
    6     BILLING CATEGORY INCORRECT     4216     72600     435600     -363000
    7     BILLING CATEGORY INCORRECT     4826     1000          1000
    8     BILLING CATEGORY INCORRECT     4951     2060          2060
    HELP PLEASE!
    Thank you.

    When you have multiple child rows, the parent row gets returned once for each child row found. Therefore, if you have summed the invoice, it gets summed again for each payment. Perhaps this little example will help you understand the problem.
    Note that I used a sub query here to obtain the desired results. Analytic functions can do the same I believe, but I am still learning them :-)
      D> DROP TABLE DMILL.invoice;
    Table dropped.
      D>
      D> DROP TABLE DMILL.payments;
    Table dropped.
      D>
      D> CREATE TABLE invoice AS
         SELECT 1 id, 10 amount FROM DUAL UNION ALL
         SELECT 2 id, 10  FROM DUAL UNION ALL
         SELECT 2 id, 10  FROM DUAL UNION ALL
         SELECT 3 id, 10  FROM DUAL;
    Table created.
      D>
      D> CREATE TABLE payments AS
         SELECT 1 inv_id, 5 amount FROM DUAL UNION ALL
         SELECT 1 inv_id, 5 amount FROM DUAL UNION ALL
         SELECT 2 inv_id, 5 amount FROM DUAL UNION ALL
         SELECT 2 inv_id, 5 amount FROM DUAL UNION ALL
         SELECT 2 inv_id, 5 amount FROM DUAL;
    Table created.
      D>
      D> select * from invoice;
            ID     AMOUNT
             1         10
             2         10
             2         10
             3         10
      D>
      D> select * from payments;
        INV_ID     AMOUNT
             1          5
             1          5
             2          5
             2          5
             2          5
      D>
      D> select id
                  ,sum (amount)
          from  invoice
         group by id;
            ID SUM(AMOUNT)
             1          10
             2          20
             3          10
      D>
      D> select inv_id
                  ,sum(amount)
          from  payments
         group by inv_id;
        INV_ID SUM(AMOUNT)
             1          10
             2          15
      D>
      D> select inv.id
                  ,inv.amount
                  ,pay.amount
          from invoice  inv
                 ,payments pay
         where pay.inv_id = inv.id;
            ID     AMOUNT     AMOUNT
             1         10          5
             1         10          5
             2         10          5
             2         10          5
             2         10          5
             2         10          5
             2         10          5
             2         10          5
    8 rows selected.
      D>
      D> select inv.id
                  ,sum(inv.amount)
                  ,sum(pay.amount)
          from invoice  inv
                 ,payments pay
         where pay.inv_id = inv.id
         group by inv.id;
            ID SUM(INV.AMOUNT) SUM(PAY.AMOUNT)
             1              20              10
             2              60              30
      D>
      D> select inv.id
                  ,sum(inv.amount)
                  ,(SELECT sum(pay.amount)
                    FROM   payments pay
                    WHERE  pay.inv_id = inv.id)
          from invoice  inv
         group by inv.id;
            ID SUM(INV.AMOUNT) (SELECTSUM(PAY.AMOUNT)FROMPAYMENTSPAYWHEREPAY.INV_ID=INV.ID)
             1              10                                                           10
             2              20                                                           15
             3              10Let me know if you need further explanation.

  • SQL Query join problem

    Hi,
    I have two tables in my db, the patient table holds details of patients, the contact table holds details of contacts related to the patient.
    patient table
    patientid - primary key - int
    patient name - varchar
    contact table
    contactid - primary key - int
    patientid - foreign key from patient table - int
    incontact - foreign key from paient table to relate contacts - int
    My contact table has the following data:
    contactid patientid incontact
    2              19           21
    2               19          22
    I can retrieve data for the patients that have been in contact with patientid 19, by using the following join:
    SELECT * FROM PATIENT
    LEFT JOIN incontact
    ON incontact.incontact = patient.patientid
    WHERE incontact.patientid = 19
    However, can you please tell me how I can get data from the patients table where the incontact is 21?
    So I can get contacts from patients and patients from contacts?
    Thankyou

    Thanks very much for your replies again.
    Basically, I have a table of patients, and I would like to link them to each other, many to many.
    I populate the incontact table, which stores the original posted patientID, and the new generated patientID. I populate the DB with the code below.
    <cfquery name="update" datasource="staffdirectory">
    SET NOCOUNT ON
    INSERT INTO patient (title,firstname,surname,gender,DOB,telephone,address1,address2,address3,town,postcode
    VALUES ('#title#','#firstname#','#surname#','#gender#',#createodbcdate(createdate(startyear, startmonth, startday))#    ,'#telephone#','#address1#','#address2#','#address3#','#town#','#postcode#
    SELECT @@Identity AS newid   
    SET NOCOUNT OFF
    </cfquery>
          <cfquery name="insert" datasource="staffdirectory">
      INSERT INTO incontact (related,incontact)
    VALUES (#patientid#,#update.newid#)
    </cfquery>
    This works fine and I can get all related patients by usingthe following query:
    SELECT * FROM patient
    LEFT JOIN incontact
    ON patient.patientid  = incontact.related
    WHERE  incontact.incontact = #patientid#
    MY problem occurs when I want to find related patients from the related column, the reverse relationship. I use this seperate query:
    SELECT * FROM patient
    LEFT JOIN incontact
    ON patient.patientid  = incontact.incontact
    WHERE  incontact.related= #patientid#
    Is there a way I can combine both queries, or is there a better way I can achieve the same result?
    Many thanks again

  • Adhoc Query Join Problem

    Hi All,
    I have created a query on PNP logical database which looks very simple, Lets say it has pernr, first name, last name, and Mailing ZIP on the output. P0006-SUBTY = 'MAIL'
    Now, the problem is .... if someone do not have mailing address subtype populated then that pernr's record is not appearing on the output. ZIP should be blank if the Mailing Address subtype is not saved for that pernr.
    I am using PNP in my infoset so I think I do not have any control over the joins, PNP should not behave like this I guess, is it normal behavior or it can be fixed? or this is one of the reasons to go for Custom ABAP Reports as it cannot be done in SQ01?
    Is the only solution through Adhoc queries to add all these PA tables in Inner Joins instead of using PNP, in SQ02?
    Thanks in advance.

    It is a common behavior of Adhoc query in PNP. You will need to create custom fields and put logic for subtypes. Using joins is not a good solution, for performance issues you cannot join many tables and HR tables have begda and endda in tables which may create problems for proper joins.

  • Query - Join Problems

    Hello,
    I'm in need of query assistance. Per my query below, I am trying to output the name of the manager, # of outlets that he/she manages, total number of direct reports at each location, and total number of rental vehicles.
    As you can see between my "current" and "desired" outputs, I'm a little off. Could this be a join issue?
    I am using Oacle 11g Express and SQL*Plus.
    Thanks for your help!!
    QUERY:
    SELECT lname || ', ' || fname “OUTLET MANAGER”, COUNT(managerno) Outlets,
    COUNT(empno) Employees, COUNT(vehicle.outno) “# OF VEHICLES”
    FROM EMPLOYEE
    JOIN outlet ON employee.empno = outlet.managerno
    LEFT OUTER JOIN vehicle ON vehicle.outno = outlet.outno
    WHERE title = 'Manager'
    GROUP BY lname || ', ' || fname;
    CURRENT OUTPUT:
    OUTLET MANAGER            OUTLETS  EMPLOYEES # OF VEHICLES
    Smith, Sandy                    1          1             0
    Weaver, Brendan                 5          5             5
    Green, Eric                     3          3             0
    Hill, Wendy                     2          2             0
    DESIRED OUTPUT:
    OUTLET MANAGER            OUTLETS  EMPLOYEES # OF VEHICLES
    Smith, Sandy                    1          3             3
    Weaver, Brendan                 5          2             5
    Green, Eric                     3          1             0
    Hill, Wendy                     1          2             2
    SAMPLE DATA:
    CREATE TABLE EMPLOYEE
    (EmpNo NUMBER(6) PRIMARY KEY,
    Title VARCHAR2(30),
    Fname VARCHAR2(10) NOT NULL,
    Lname VARCHAR2(10) NOT NULL,
    OutNo NUMBER(4),
    SupervisorNo NUMBER(6));
    CREATE TABLE OUTLET
    (outNo NUMBER(4) PRIMARY KEY,
      ManagerNo NUMBER(6));
    CREATE TABLE VEHICLE
    (LicenseNo VARCHAR2(7) PRIMARY KEY,
      outNo NUMBER(4));
    INSERT INTO EMPLOYEE VALUES ('100001','Associate','Jenny','Smith','1001','100007');
    INSERT INTO EMPLOYEE VALUES ('100002','Associate','Fred','Frapples','1001','100007');
    INSERT INTO EMPLOYEE VALUES ('100003','Regional Manager','TJ','Safranski',NULL,'100004');
    INSERT INTO EMPLOYEE VALUES ('100004','CEO','Harry','Miller',NULL,NULL);
    INSERT INTO EMPLOYEE VALUES ('100005','Associate','Jolena','Koneski','1002','100009');
    INSERT INTO EMPLOYEE VALUES ('100006','Associate','Bruce','Peer','1002','100009');
    INSERT INTO EMPLOYEE VALUES ('100007','Manager','Sandy','Smith','1001','100003');
    INSERT INTO EMPLOYEE VALUES ('100008','Associate','Julie','Walker','1003','100010');
    INSERT INTO EMPLOYEE VALUES ('100009','Manager','Brendan','Weaver','1002','100003');
    INSERT INTO EMPLOYEE VALUES ('100010','Manager','Wendy','Hill','1003','100003');
    INSERT INTO EMPLOYEE VALUES ('100011','Associate','Jeorge','Peer','1004','100012');
    INSERT INTO EMPLOYEE VALUES ('100012','Manager','Eric','Green','1004','100003');
    INSERT INTO OUTLET VALUES ('1001','100009');
    INSERT INTO OUTLET VALUES ('1002','100008');
    INSERT INTO OUTLET VALUES ('1003','100008');
    INSERT INTO OUTLET VALUES ('1004','100009');
    INSERT INTO OUTLET VALUES ('1005','100010');
    INSERT INTO OUTLET VALUES ('1006','100010');
    INSERT INTO OUTLET VALUES ('1007','100012');
    INSERT INTO OUTLET VALUES ('1008','100012');
    INSERT INTO OUTLET VALUES ('1009','100012');
    INSERT INTO OUTLET VALUES ('1010','100007');
    INSERT INTO VEHICLE VALUES ('BH05J9U','1001');
    INSERT INTO VEHICLE VALUES ('H4L0DH8','1001');
    INSERT INTO VEHICLE VALUES ('5HDI9TG','1002');
    INSERT INTO VEHICLE VALUES ('GI0UJD7','1002');
    INSERT INTO VEHICLE VALUES ('GJU4Y7D','1001');
    INSERT INTO VEHICLE VALUES ('S5BNP2S','1003');
    INSERT INTO VEHICLE VALUES ('XCH4Y23','1002');
    INSERT INTO VEHICLE VALUES ('A12F8GH','1003');
    INSERT INTO VEHICLE VALUES ('C4YUTSA','1004');
    INSERT INTO VEHICLE VALUES ('634HV2E','1004');

    Actually, the desired output for "Smith, Sandy" is correct:
    OUTLET MANAGER            OUTLETS  EMPLOYEES # OF VEHICLES
    Smith, Sandy                    1          3             3
    Inside the OUTLET table, Sandy's "EmpNo" only appears once (e.g.- 1 outlet). Inside the EMPLOYEE table, both she and two other employees are located at one outlet (OutNo)... so the number of employees equals 3. Inside the VEHICLE table, based off the "OutNo" Sandy manages, a total of three cars are assigned.
    Outlet relates to employee because employees are both employed at, and manage, the outlet. Hinging off the "EmpNo" value, we can extrapolate who both works at each outlet and manages said outlet.
    Please let me know if I need to do a better job explaining.
    Thanks for your help!
    Message was edited by: 8bb7968b-e6ae-456c-8459-f418352e9e0a

  • Select Query Date Problem?

    Hi,
    I using 10g and here is my sample query which brings nothing. I know there are records in the database. It must be related with my date conversions.
    SELECT a.gm_cd, a.draw_cd, NVL(b.cpns, 0) cpns, NVL(b.clms, 0) clms, NVL(b.amn, 0) amn FROM (SELECT gm_cd,draw_cd,TO_DATE(draw_tm, 'DD/MM/YYYY') draw_tm FROM draw WHERE gm_cd = 10105 AND TO_DATE(draw_tm, 'DD/MM/YYYY') = TO_DATE(sysdate-1, 'DD/MM/YYYY') ) a, ( SELECT SUM (DECODE (a.from_draw, a.to_draw, a.cpns * b.sing_ind, 0)) cpns, SUM (a.clms* b.sing_ind) clms, SUM (a.amn* b.sing_ind) amn FROM draw_sales a, ACC_TYPE b WHERE a.tp = b.cd AND a.DT = TO_DATE(sysdate-1, 'DD/MM/YYYY') AND a.gm_cd = 10105 ) b ORDER BY a.gm_cd, a.draw_cd
    Any ideas?
    By the way, draw_tm is a DATE column (11/05/2013 03:59:59) and DT is also a DATE column (10/05/2013)

    raysefo wrote:
    Hi,
    I using 10g and here is my sample query which brings nothing. I know there are records in the database. It must be related with my date conversions.
    SELECT a.gm_cd, a.draw_cd, NVL(b.cpns, 0) cpns, NVL(b.clms, 0) clms, NVL(b.amn, 0) amn FROM (SELECT gm_cd,draw_cd,TO_DATE(draw_tm, 'DD/MM/YYYY') draw_tm FROM draw WHERE gm_cd = 10105 AND TO_DATE(draw_tm, 'DD/MM/YYYY') = TO_DATE(sysdate-1, 'DD/MM/YYYY') ) a, ( SELECT SUM (DECODE (a.from_draw, a.to_draw, a.cpns * b.sing_ind, 0)) cpns, SUM (a.clms* b.sing_ind) clms, SUM (a.amn* b.sing_ind) amn FROM draw_sales a, ACC_TYPE b WHERE a.tp = b.cd AND a.DT = TO_DATE(sysdate-1, 'DD/MM/YYYY') AND a.gm_cd = 10105 ) b ORDER BY a.gm_cd, a.draw_cd
    Any ideas?
    By the way, draw_tm is a DATE column (11/05/2013 03:59:59) and DT is also a DATE column (10/05/2013)If draw_tm is a DATE datatype then you shouldn't be doing a TO_DATE on it, as you don't need to convert it to a date. If you're trying to remove any time component from it, then you should use TRUNC(draw_tm).
    Likewise with sysdate, you should use TRUNC to truncate it. Never use TO_DATE on DATA datatypes otherwise you cause an implicit conversion to varchar2 which will depend on your NLS settings and can fail.

  • Problem with JOINs in SELECT query

    The parameter  wa_dob-e_dob is not getting its definition ....
    it contains DOB in current yr.
    As i am using Joins also Workarea.... so is it coz Joins & WA cant be used simultaneously in a SELECT query....
    Is there any other option to do the same...?
    *  Global Structure
    TYPES : BEGIN OF t_data ,                     "Structure
            emp_dob TYPE pa0002-gbdat,
            emp_Mailid TYPE pa0105-usrid,
           END OF t_data,
           BEGIN OF t_dob,
           e_dob TYPE pa0002-gbdat,
           e_pernr type pa0002-pernr,
           END OF t_dob.
    *  Global Internal Tables (I_)
    DATA : i_data TYPE TABLE OF t_data,           "Internal Table for output data
           i_dob TYPE TABLE OF t_dob.             "Internal table for Dob
    *  Global Work Area (WA_)
    DATA : wa_data TYPE  t_data,                  "Work Area for output data
           wa_dob TYPE  t_dob.                    "Work Area for Dob
    *this is the query where i am getting error
    * Field "WA_DOB-E_DOB" Not found.
    LOOP AT i_dob INTO wa_dob.
        SELECT pa0002~gbdat pa0105~usrid INTO CORRESPONDING FIELDS OF wa_data
          FROM pa0002
          INNER JOIN pa0105
          ON pa0002~pernr = pa0105~pernr
          WHERE  pa0105~subty EQ 'MAIL' AND
         wa_dob-e_dob BETWEEN w_sysdate AND w_edit_sysdate.
        ENDSELECT.
        APPEND wa_data TO i_data.
        CLEAR wa_data.
        CLEAR wa_dob.
        CLEAR l_temp_dob.
      ENDLOOP.

    Hi,
    you are checking the work area in the SELECT. IN WHERE condition of the select u should specify fields in either of the tables pa0002 , pa0105 for data population.
    The select is on the database table and not on the work area.for checking the data in the work area do this way:
    loop at it_dob into wa_dob.
    if wa_dob-e_dob between the range u want (w_sysdate AND w_edit_sysdate)
    endif.
    endloop.
    ie: wa_dob-e_dob >w_sysdate AND wa_dob-e_dob < w_edit_sysdate or
        wa_dob-e_dob < w_sysdate AND wa_dob-e_dob  >  w_edit_sysdate
    watever ur requirement is..
    regards,
    madhu

  • How can i use index in select query.. facing problem with the select query.

    Hi Friends,
    I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
    Here is the query:
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelat LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelatrprctr
        WHERE rldnr  = c_telstra_accounting
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          And rzzlstar in r_lstar                            
          AND rpmax  = c_max_period.
    There are 5 indices present for Table ZTFTELAT.
    Indices of ZTFTELAT:
      Name   Description                                               
      0        Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)                                          
      005    Profit (RCLNT,RPRCTR)
      1        Ledger, company code, account (RLDNR,RBUKRS, RACCT)                                
      2        Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)                           
      3        Account, cost center (RACCT,RCNTR)                                        
      4        RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR                        
      Z01    Activity Type, Account (RZZLSTAR,RACCT)                                        
      Z02    RYEAR-RBUKRS- RZZZBER-RLDNR       
    Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
    Thanks in advance.

    Hi Shiva,
    I am using two more select queries with the same manner ....
    here are the other two select query :
    ***************1************************
    SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelpt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelptrprctr
        WHERE rldnr  = c_telstra_projects
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar             
          AND rpmax  = c_max_period.
    and the second one is
    *************************2************************
      SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
        FROM ztftelnt LEFT JOIN ztfzberep
         ON  ztfzberep~gjahr = st_input-gjahr
         AND ztfzberep~poper = st_input-poper
         AND ztfzberepcntr  = ztftelntrprctr
        WHERE rldnr  = c_telstra_networks
          AND rrcty  = c_actual
          AND rvers  = c_ver_001
          AND rbukrs = st_input-bukrs
          AND racct  = st_input-saknr
          AND ryear  = st_input-gjahr
          and rzzlstar in r_lstar                              
          AND rpmax  = c_max_period.
    for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables.  if i will not use it will delete all the data fetched earlier.
    Thanks on advanced......
    Sourabh

  • Dynamic From statement in select query and/or outer join not working

    Dear Experts, I have a select query where the select columns are dynamic, the where condition is also dynamic. It is of the below format:
    Select (dynamic columns) INTO <wa>
    FROM a inner join b on af1 = bf1
    inner join c on af2 = cf2......
    WHERE (dynamic conditios)
    ORDER BY ( dynamic sort condition).
    Now I have to include some tables (dynamically depending on the user input) in the inner join statement which will give description for the selected fields. And these database tables may or may no be empty. So in this case, my select query will not return any data if these tables are empty. And I dont want that.
    I tried using outer join for the extra tables but it gave me a runtime error. I also tried forming the inner join statement dynamically but it was not supporting.
    Kindly give me pointers.
    Thanks

    Hey thanks for the reply, but the problem is not solved.
    I am already using  ( fileds, value) like table in my where condition and the select statement was working properly.
    the problem is that now I have to include some tables in the join statement which can be empty and so i want to use Outer join.
    But I am getting a runtime error as below:
    Error analysis
        An exception occurred that is explained in detail below.
        The exception, which is assigned to class 'CX_SY_DYNAMIC_OSQL_SYNTAX', was not
         caught in
        procedure "ZATSCSNG_RFC_READ_TABLE" "(FUNCTION)", nor was it propagated by a
         RAISING clause.
        Since the caller of the procedure could not have anticipated that the
        exception would occur, the current program is terminated.
        The reason for the exception is:
        The running ABAP program wanted to execute a SELECT statement whose
        WHERE condition was (partly) specified dynamically. The part that is
        specified in an internal table at runtime is compared to a field of the
        right table of an LEFT OUTER JOIN. Such comparisons are not supported by
         all database systems and are therefore not allowed.

  • Select query based on joining of tables from different database is taking too long

    Hi Team,
    Select query on table with millions of records is taking very long time. It took 50mins, the below query is joining on multiple table from two databases DB1.dbo.Table1 contains 100 million records and also Table3 and Table4 (of different database) might
    contain close to 1million records.
    Select T1.*
    From DB1.dbo.Table1 T1
    Join DB1.dbo.Table2 T2 on RTRIM(T1.Col3) = RTRIM(T2.Col3)
    Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1
    Join Table3 U on CA.Col2 = U.Col2 AND RTRIM(T2.Col2) = U.Col3
    Where U.Col4 NOT IN ('A1', 'A2', 'A3', 'A4', 'A5', 'A6','A7','A8','A9')
    And (T1.flg IS NULL OR T1.flg = 'N')
    And LTRIM(RTRIM(T2.Col2)) NOT IN ('B1','B2')
    How can i improve the performance of this query. Actual thing is update the data in Db1.dbo.table1 based on the conditions but if the select is taking close to 1hr then update will take hours together. Indexes already implemented on all the tables.
    Thanks,
    Eshwar.
    Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.

    Thanks.
    Join Table4 CA on RTRIM(T1.Col1) + T2.Col2 = CA.Col1
    This join is not working with spaces if Rtrim is not used.
    Thanks! Eshwar.
    Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.

  • Select query problem in JDBC sender adapter

    Hello Experts,
    We have a problem with PI sender adapter that PI has started to miss records in database some database records are missing and we are using the below selet query :
    SELECT * FROM [database name].[dbo].[Material_Movement] WHERE [Process_Order_Number] = (Select TOP 1 [Process_Order_Number] FROM [database name].[dbo].[Material_Movement] WHERE ([PI_Read_Date] IS NULL AND [Movement_Type] = (SELECT TOP 1 [Movement_Type] FROM [database name].[dbo].[Material_Movement] WHERE [Transaction_Code] = 'xyz' AND [PI_Read_Date] IS NULL ORDER BY Created_Date ASC))) AND [Transaction_Code] = 'xyz' AND [Movement_Type] = (SELECT TOP 1 [Movement_Type] FROM [database name].[dbo].[Material_Movement] WHERE [Transaction_Code] = 'xyz' AND [PI_Read_Date] IS NULL ORDER BY Created_Date ASC) AND [PI_Read_Date] IS NULL ORDER BY [Transaction_ID] ASC
    I am weak in select query could you please check and suggest how the query can be modified to avoid this issue .
    Thanks,
    Somenath

    Hi ,
    After looking into These Query .. I found ...
    Your Query Will run such Kind of scenario ..
    1.)   Movement Type will be fetched from from below Query
            SELECT TOP 1 Movement_Type
            FROM database name.dbo.Material_Movement
            WHERE Transaction_Code = 'xyz'
           AND PI_Read_Date IS NULL
            ORDER BY Created_Date ASC
    2.) on the  basis of abovr fetched  moment code . your Query will fetch 1 Process Order number
    Select TOP 1 Process_Order_Number
    FROM database name.dbo.Material_Movement
    WHERE ( PI_Read_Date IS NULL
                  AND Movement_Type =  Moment Type will be same as 1.
    3.)
    After  Getting 1 and 2 . Query will fetch Data  from table " dbo.Material_Movement "
    On the basis of ..
    Movement_Type = value from 1.
    Process_order_type = value from 2.
    Transaction_Code = 'xyz'
    ORDER BY Transaction_ID ASC
    So check Missed record Fullfill this Condition or not ....................
    If not ... You will get why they are not picked by your given Query ...........
    Hope it helps ..
    regards
    Prabhat Sharma.

  • 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 my Select query

    Hi Experts,
    I need a clarification in my Select query.
    Have created a custom search help and my requirement is I have Request ID, Last and First Name as my search parameters. I need to fetch the values from my Ztable on search with the above said search parameters, where its workflow status = 30.
       * Get Request ID
      lv_pattern = <ls_query_params>-request_id.
      IF lv_pattern CA '*'.
        REPLACE ALL OCCURRENCES OF '*' IN lv_pattern WITH '%'.
      ENDIF. " IF lv_pattern CA '*'
      IF lv_pattern IS INITIAL.
        lv_pattern = '%'.
      ENDIF. " IF lv_pattern IS INITIAL
    ** Get NACHN - Lastname
        lv_last_name = <ls_query_params>-nachn.
        IF lv_last_name CA '*'.
          REPLACE ALL OCCURRENCES OF '*' IN lv_last_name WITH '%'.
        ENDIF. " IF lv_pattern CA '*'
        IF lv_last_name IS INITIAL.
          lv_last_name = '%'.
        ENDIF. " IF lv_pattern IS INITIAL
    ** Get VORNA - First Name
        lv_first_name = <ls_query_params>-vorna.
        IF lv_first_name CA '*'.
          REPLACE ALL OCCURRENCES OF '*' IN lv_first_name WITH '%'.
        ENDIF. " IF lv_pattern CA '*'
        IF lv_first_name IS INITIAL.
          lv_first_name = '%'.
        ENDIF. " IF lv_pattern IS INITIAL
    *Selecting the RequestID/Last and First Name values with workflow status as 30.
    SELECT zzreq_id " Internal number for appropriation request
                nachn
               vorna
      INTO TABLE lt_select_list
      FROM ZTABLE
      WHERE (  ( zzreq_id LIKE lv_pattern ) and
                     ( nachn like lv_last_name ) or
                      ( vorna LIKE lv_first_name ) )
           AND zzstatus = lv_workflow_status.
    My problem is, ofcourse this query is selecting all the records where status = 30 and even it works correctly, If I searches with Request ID(* or *3*).
    But am not able to select the records, if I searches with Last or First Name. Guess I did some thing wrong in select query.
    Please advice me.
    With Regards,
    Ram.

    Re: Problem in my Select query
    Krishna kumar Jun 9, 2014 7:52 AM (in response to Ramakrishnan Murugan)
    Hi Ramakrishnan,
                         Can you just try the below Select Query,
    SELECT zzreq_id
                nachn
               vorna
      INTO TABLE lt_select_list
      FROM ZTABLE
      WHERE ( zzreq_id     LIKE    lv_pattern                and
                         nachn         LIKE    lv_last_name         and
                         vorna          LIKE     lv_first_name )    and
                          zzstatus = lv_workflow_status.
    Cheers,
    Krishnakumar B.
    I think the above suggested query is same as your solution.

Maybe you are looking for