Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem with SELECT UP TO 1 ROWS STATEMENT

Former Member
0 Likes
1,917

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.

8 REPLIES 8
Read only

Former Member
0 Likes
1,275

Hi

In Select UP TO 1 ROW statement sort or order by the select query to get the correct result.

Thanks

Khushboo

Read only

former_member404244
Active Contributor
0 Likes
1,275

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

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,275

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

Read only

Former Member
0 Likes
1,275

Hi,

Please go though the below thread....

Regards

Arbind

Read only

Former Member
0 Likes
1,275

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.

Read only

rainer_hbenthal
Active Contributor
0 Likes
1,275

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.

Read only

Former Member
0 Likes
1,275

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

Read only

Former Member
0 Likes
1,275

HI,

it is better to u delete ADJACENT DUPLICATES FROM itab after select query..