‎2010 Feb 01 7:42 AM
Hi All,
I am facing a problem with the select query where in SELECT UP TO 1 ROWS is used.There are 2 records in the table abc which
are satisfting WHERE caluse conditions of query, but query is sometimes returning right record and some times wrong record.
What could be the reason behind this random behaviour of query?Please help.
SELECT vkorg
vtweg
spart
kschl
kunnr
matnr
datab
zgocoahnid
zzacseq
aufnr
INTO TABLE t_abc
FROM abc UP TO 1 ROWS
FOR ALL ENTRIES IN t_xyx
WHERE vkorg EQ t_wa-vkorg
AND vtweg EQ t_wa-vtweg
AND spart EQ zt_wa-spart
AND kschl EQ t_xyz-kschl.
‎2010 Feb 01 7:45 AM
Hi
In Select UP TO 1 ROW statement sort or order by the select query to get the correct result.
Thanks
Khushboo
‎2010 Feb 01 7:47 AM
Hi,
Select upto 1 record always gets one record ryt.. Moreover what is there in the table , it always get the first record only.
Regards,
Nagaraj
‎2010 Feb 01 8:19 AM
Hello ,
Also if you check this [WIKI|https://wiki.sdn.sap.com/wiki/display/ABAP/ABAPPerformanceand+Tuning#ABAPPerformanceandTuning-WhatisthedifferencebetweenSELECTSINGLEandSELECT...UPTO1ROWS%3F]:
SELECT SINGLE and SELECT UP TO n ROWS return the first matching row/rows for the given condition. It may not be unique, if there are more matching rows for the given condition.
This is the reason why your SELECT UP TO stmt is not returning the same record.
BR,
Suhas
Edited by: Suhas Saha on Feb 1, 2010 1:50 PM
‎2010 Feb 01 7:47 AM
Hi,
Please go though the below thread....
Regards
Arbind
‎2010 Feb 01 9:40 AM
Select up to 1 row will fetch all records satisfying the condition and keep it in a buffer. From there, the first record is fetched. It will try to find the most suitable index.
Try using select single giving all the primary keys in the where condition.
‎2010 Feb 01 12:00 PM
In a table in a relational database no first nor last record exists. There is no sequence guaranteed except you specify an order by clause.
‎2010 Feb 01 12:09 PM
Hi,
If the fields in the table are in primary key then write select single
or create Secondary index for the fields whic dont have primary key.
Regards
Azeez
‎2010 Feb 02 6:10 AM
HI,
it is better to u delete ADJACENT DUPLICATES FROM itab after select query..