Select Query Fetching same records multiple time

Hi ABAPers,
I have an issue where the select query is fetching the same records more than one time for particular sale order.
Kindly help to solve the issue.
Thanks in advance..
Here is the Select Query:-
SELECT  VBAK~VKORG VBAK~VTWEG VBAK~VBELN VBAK~KUNNR
               VBAK~ERDAT VBAK~LIFSK VBKD~INCO1 VBKD~INCO2
               VBAP~MATNR VBAP~ARKTX VBAP~MATKL VBAK~BSTNK
               VBAK~BSTDK VBAK~KNUMV VBAP~UEPOS VBAP~POSNR
               VBAP~KWMENG VBAK~VDATU VBAP~VRKME VBAK~ERNAM VBAK~WAERK
  INTO CORRESPONDING FIELDS OF TABLE IT_PENDING FROM VBAK
  INNER JOIN VBAP ON VBAK~VBELN = VBAP~VBELN
  INNER JOIN VBKD ON VBAK~VBELN = VBKD~VBELN
  WHERE
  VBAK~VBELN IN SO_VBELN AND
  VBAK~ERDAT IN SO_ERDAT AND
  ( AUART EQ 'OR' OR AUART EQ 'ZEO' OR AUART EQ 'TA' OR AUART EQ 'LP' OR AUART EQ 'ZFOC' ) AND
  VKORG IN SO_VKORG AND
  VTWEG IN SO_VTWEG AND
  SPART IN SO_SPART AND
  KUNNR IN SO_KUNNR AND
  MATNR IN SO_MATNR AND
  MATKL IN SO_MATKL AND
  ABGRU EQ '' AND LIFSK <> '35'.
Edited by: Suhas Saha on Jan 14, 2012 3:42 PM

Hello Suhale,
On retrospection, I found the query in my above response STILL HAS ONE ISSUE. When we are making a left outer join on vbkdposnr = vbapposnr we are only fetching vbkdinco1 and vbkdinco2 values where item level entries exist in VBKD which match with vbkdposnr = vbapposnr.
Actually we should bring inco1 and inco2 from vbkd when a matching entry exists in vbkd where vbkdposnr = vbapposnr and if there is no entry matching vbkdposnr = vbapposnr, then we should fetch inc01 and inco2 from VBKD where posnr = '000000' (i.e., from header).
This is how SAP behaves when you open an item in VA03 and look at inco1 and inco2. They come from the item if an entry corresponding to that item exists in VBKD otherwise they come from VBKD header record (where vbkd~posnr = '000000')
We can't use VBKD in the joins and still be able to do the above. So we need to fetch inco1, inco2 from VBKD separately like below.
FIELD-SYMBOLS: <fs_pending> LIKE LINE OF it_pending.
SELECT vbak~vkorg vbak~vtweg vbak~vbeln vbak~kunnr
       vbak~erdat vbak~lifsk "vbkd~inco1 vbkd~inco2
       vbap~matnr vbap~arktx vbap~matkl vbak~bstnk
       vbak~bstdk vbak~knumv vbap~uepos vbap~posnr
       vbap~kwmeng vbak~vdatu vbap~vrkme vbak~ernam vbak~waerk
  INTO CORRESPONDING FIELDS OF TABLE it_pending
    FROM vbak INNER JOIN vbap
      ON vbak~vbeln = vbap~vbeln
        WHERE vbak~vbeln IN so_vbeln AND
              vbak~erdat IN so_erdat AND
            ( vbak~auart EQ 'OR' OR vbak~auart EQ 'ZEO' OR
              vbak~auart EQ 'TA' OR vbak~auart EQ 'LP' OR
              vbak~auart EQ 'ZFOC' ) AND
              vbak~vkorg IN so_vkorg AND
              vbak~vtweg IN so_vtweg AND
              vbak~spart IN so_spart AND
              vbak~kunnr IN so_kunnr AND
              vbap~matnr IN so_matnr AND
              vbap~matkl IN so_matkl AND
              vbap~abgru EQ '' AND
              vbak~lifsk NE '35'.
  LOOP AT it_pending ASSIGNING <fs_pending>.
    SELECT SINGLE inco1 inco2
      FROM vbkd
        INTO (<fs_pending>-inco1,<fs_pending>-inco2)
          WHERE vbkd~vbeln = <fs_pending>-vbeln AND
                vbkd~posnr = <fs_pending>-posnr.
    IF sy-subrc NE 0.
      SELECT SINGLE inco1 inco2
        FROM vbkd
          INTO (<fs_pending>-inco1, <fs_pending>-inco2)
            WHERE vbkd~vbeln = <fs_pending>-vbeln AND
                  vbkd~posnr = '000000'.
    ENDIF.
  ENDLOOP.
Best regards,
Vishnu Tallapragada.

Similar Messages

  • How to insert same record multiple times in a loop..

    Dear All,
    I need to insert a record multiple time how it can be accomplish...
    eg:
    ref no name dept
    123     abc 1     
    122 def 2
    121 feg 1
    120 hhh 2
    while inserting into another table:
    all dept no 1 with should inserted 3 times for each record above
    final out put should be :
    table abc
    ref no name dept
    123     abc 1
    123     abc 1
    123     abc 1     
    122 def 2
    121 feg 1
    121 feg 1
    121 feg 1
    120 hhh 2
    Thank You

    user3029023 wrote:
    Dear All,
    I need to insert a record multiple time how it can be accomplish...
    eg:
    ref no name dept
    123     abc 1     
    122 def 2
    121 feg 1
    120 hhh 2
    while inserting into another table:
    all dept no 1 with should inserted 3 times for each record above
    final out put should be :
    table abc
    ref no name dept
    123     abc 1
    123     abc 1
    123     abc 1     
    122 def 2
    121 feg 1
    121 feg 1
    121 feg 1
    120 hhh 2
    Thank YouTry this .
    SQL> ed
    Wrote file afiedt.buf
      1  with t as
      2  (select '123' AS ref_no,'abc' AS name,'1' as Dept
      3  from dual
      4  union all
      5  select '122','def','2' from dual
      6  union all
      7  select '333','feg','1' from dual
      8  union all
      9  select '120','hhh','2' from dual
    10  )
    11  select ref_no,name,Dept from t,(select level x from dual connect by  level <4)
    12* order by 1
    SQL> /
    REF NAM D
    120 hhh 2
    120 hhh 2
    120 hhh 2
    122 def 2
    122 def 2
    122 def 2
    123 abc 1
    123 abc 1
    123 abc 1
    333 feg 1
    333 feg 1
    333 feg 1
    12 rows selected.And insert the same onto your desired table.
    Hope this Helps..
    Regards,
    Achyut

  • Select query is taking lot of time to fetch data.....

    Select query is taking lot of time to fetch data.
        SELECT algnum atanum  abdatu abzeit abname abenum bmatnr bmaktx bqdatu bqzeit bvlenr bnlenr bvltyp bvlber b~vlpla
               bnltyp bnlber bnlpla bvsola b~vorga INTO TABLE it_final FROM ltak AS a
                       INNER JOIN ltap AS b ON  btanum EQ atanum AND algnum EQ blgnum
                       WHERE a~lgnum = p_whno
                       AND a~tanum IN s_tono
                       AND a~bdatu IN s_tocd
                       AND a~bzeit IN s_bzeit
                       AND a~bname IN s_uname
                       AND a~betyp = 'P'
                       AND b~matnr IN s_mno
                       AND b~vorga <> 'ST'.
    Moderator message: Please Read before Posting in the Performance and Tuning Forum
    Edited by: Thomas Zloch on Mar 27, 2011 12:05 PM

    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

  • Same parameter multiple times in Execute SQL Task

    Hi all,
    i have a fairly long parametrized query that needs to be run within an Execute SQL task. It has only 2 unique parameters, but these need to be used multiple within that query. The connection is OLEDB.
    ill simplify my requirement by making up an arbitrary T-SQL "where" clause that will illustrate what i need:
    where
    x = @param1
    and y = @param1
    and z > @param2
    and w > @param2
    moving this into an SSIS execute SQL task will require the following:
    where
    x = ?
    and y = ?
    and z > ?
    and w > ?
    I know i need to specify 4 parameters and remap the same variables multiple times.. like so:
    User:aram1   -> 0
    User:aram1   -> 1
    User:aram2   -> 2
    User:aram2   -> 3
    isnt there a better way? i ask this because in my real task i have 2 params, each is reused 4 and 5 times respectively and it seems stupid to repeat params like this.

    @ _proffy_
    you can pass the same variable or value as parameter multiple times sql task.
    follow the steps below.
    1) type the sql query with parameters in SQL statement tab of sql task editor
    2. in the parameter mapping, select the variables.
      you can select the same variables more than once.
     give the parameter name as 0,1,2,3..... based on variables you require.
    do not forget to chooose the appropriate Datatype.
    ex:
    select * from table1
    where a= ?
    and b=?
    and c= ?
    parameters:
    Var name               param Name
    user::Var1               0   
    user::Var1               1
    user::Var2               2
    so the value becomes a=var1, b= var1 and c= var2

  • Openscript records multiple times

    Hi,
    It records the same step multiple times.  I'm using Openscript 12x with Siebel. 
    Thanks,
    Will

    Hum very difficult to tell you...
    Is that a load or a functional test script?
    Do you use the proper OpenScript script template?
    Have you properly configured Siebel to be able to record HI user actions?
    JB

  • How to know query fetched % of record till now

    Hi ,
    Please tell me hoe to know query fetched % of record till now
    suppose table having 20 lack record, it is taking time but i want to know
    how many % fetch is completed.
    Regards

    I dont't have access to but try to see:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1099233454171
    Regards
    Etbin

  • Why is Apple TV showing the same computer multiple times for Home Sharing?

    Why is my Apple TV showing the same computer multiple times for Home Sharing? Also have connectivity issues. Sometimes will lose signal.
    JonRod's music
    JonRod's music
    JonRod's music
    JonRod's music
    JonRod's music
    I recently updated to Yosemite and never had this issue before.

    I'm not 100% sure of the ins and outs, but it's some sort of known issue between Yosemite, Airport and wifi. All you can do is wait for a fix and keep restarting your equipment as and when needed, unless you have the ability to connect your Mac via ethernet.

  • Can I gift the same app multiple times to multiple users?

    Can I gift the same app multiple times to multiple users?
    Like, if I wanted to buy iMovie for 3 friends, could I buy the app as a gift 3 times?

    You should be able to gift it multiple times
    Gifting content : http://support.apple.com/kb/HT2736

  • Is it possible to copy the same database multiple times simultaneously?

    This is the setup of my environment.
    I have a 'master' database that contains the full schema plus some pre-populated data such as default settings. When database schema changes are made, they get made to the master database. When a new customer signs up for the service, I make a copy of this
    master database (using SMO) that will now be the database containing all of the customer's information. The database is rather large, and the copy operation can take a couple minutes.
    Everything works fine as expected, unless I try to provision two new customers at the same time. It appears that Azure only allows for one DB copy operation at a time. Is there a way to allow for copying the same database multiple times simultaneously?
    Thanks for you input. I understand that this is likely not the optimal setup, and that there is many better ways of doing this, but I am somewhat heavily invested in the current process and I would like to find out how to make it work if I can.

    BTW, you can do this programatically by using PowerShell (https://msdn.microsoft.com/en-us/library/ee210569.aspx), SqlPackage (http://www.benday.com/2012/12/18/deploy-a-sql-server-database-projects-dacpac-with-sqlpackage-exe/)
    or the SQL Server binaries for .NET (http://www.vijayt.com/Post/Deploying-a-data-tier-application-in-SQL-Azure-programatically)
    Hope this helps.
    Alex

  • TS3276 how do I get Mail to stop downloading the same email multiple times?

    My mail keeps downloading the same email multiple times.  I've had as many as 10 of the same emial.  How do I stop this?

    Me too - did you ever figure it out?
    You can't even delete from the server in mountain lion.... I did it from my old mac, but it didn't work. I keep having 11,000 new emails that can not even be deleted in blocks!!!
    Was it a gmail account? Mine is, and my other 2 are fine...

  • How to automate saving the same image multiple times?

    Hello. I wish to save the same image multiple times in a folder... is there a way to automate this function? I also need the flexibility of determining the starting number in this image sequence. Thanks.

    Good day!
    I would recommend asking for help over at
    Photoshop Scripting
    And going into more detail about what you want to achieve (maybe post a screenshot, diagram, mock-up to illustrate it).
    Regards,
    Pfaffenbichler

  • Address book has same entries multiple times how can I go back to original cesium

    Address book has same entries multiple times how can I go back to original cesium

    After a couple of days, I'm noticing that the repeat(ing) offenders have more than 10 episodes, and seem to keep repeating them every time I sync.
    They only show once in my phone and in the iTunes Podcasts, but through iTunes and looking at what's in my phone is when I see the repeats.
    Even after I've marked a podcast as played, and deleted it from within my phone, as well as telling iTunes to delete the played episodes, it still shows multiples of the played episodes.
    There doesn't seem to be any rhyme or reason to it either. They aren't the newest ones either.

  • Running the same code multiple times with different paramters automatica​lly

    Hi guys,
    I want to run the same code multiple times with different paramters automatically. Actually, I am doing some sample scans which takes around 2 hours n then I have to be there to change the paramters and run it again. Mostly I do use folowing paramters only
    X_Intial, X_Final, X-StepSize
    Y_Intial, Y_Final, Y-StepSize
       Thanks,
    Dushyant

    All you have to di is put all of the parameters for each run into a cluster array. Surround your main program with a for loop and wire the cluster array through the for loop. A for loop will autoindex an input array so inside the for loop you just have to unbundle the cluster to get the parameters for each run.
    Message Edited by Dennis Knutson on 07-13-2006 07:50 AM
    Attachments:
    Cluster Array.JPG ‏9 KB

  • Provision same resource multiple times

    All,
    I have a scenario to provision same resource multiple times for the same user.
    How to make a resource to allow provisioning multiple times in OIM 11gR2. I am not seeing th option "allow multiple" in resource object in the design console.
    Please help.

    In OIM 11g R2 you can assign same resource multiple time.
    The account which gets assigned first time will be marked as primary and the rest others will be marked as "other"
    HTH

  • Avoid opening same Form Multiple times

    hi
    Can anyone help me , how to put restruction not to open the same form multiple times .
    regds/sanjay

    I'm not suggesting that the following is great idea but..
    You could start a timer and keep updating the row in the table with a timestamp and then have a job which checks if there are rows in the table that have timestamps older than the timer interval.
    I actually think that that is really bad idea.
    I think its more important to ask why this is a requirement? I currently write sytems for police officers and even they can grasp the concept that someone else might be updating the same data at the same time as them and can work multiple sessions. Its hard for them, and sometimes I think they may just be hitting their keyboards with a truncheon, but they do get it.

Maybe you are looking for

  • Downloading Adobe Photoshop Lightroom 4 JRun Serlet Error

    I am trying to download Adobe Photoshop Lightroom 4, that I purchased back in 2012 for my windows laptop, to my new Mac laptop but when I click the download button all I get is JRun Serlet Error 413 Header length to Large. I have no idea what this me

  • What program do I use to install Reader under Ubuntu

    I am trying to install a later version of Adobe Reader than comes from the Ubuntu repository. When I use Adobe's download Reader page, I get the typical download box that asks if I want to open the file or save it. The default opening program on my s

  • Can't connect to X11 window server using ':0.0' as the value of the DISPLAY

    i try to use jfreechart to create a piechart on a aix os with jdk1.3.1 and the aix system does not have a xwindow installed and the found the following error java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the

  • Won't let me edit "rolling credits" title! AGGGH!

    I'm pretty new to iMovie, but I've made a few very simple ones successfully, i.e., title and single clip, no transitions, no external sound files, etc. I've got a 17 minute movie with about 100 clips and a couple dozen titles here and there which are

  • Oracle FO processor ignoring color attribute

    Hello, I have the following: <fo:inline font-weight="bold" color="red">blah</fo:inline> iin my report xml. When I use BI Publisher desktop to convert my template to pdf or html, the selected text is shown in bold but the color is not in red but black