Application Development 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: 

Problem in Query

Former Member
0 Kudos

Hi All,

There is a query written in SQ00 which fetches data from EKKO and EKPO.In the output it is displaying identical records multiple times.I want to display only the fist encountered entry for the given combination of the input.How can this be done?

Thanks,

Rakesh.

8 REPLIES 8

Former Member
0 Kudos

Hi,

You can use SELECT SINGLE .... statement.

SELECT SINGLE columns ... 
FROM database table
INTO TABLE internal table
WHERE ...

To ensure that the line can be uniquely identified, you must specify values for all of the fields of the primary key of the table in the WHERE clause. If the WHERE clause does not contain all of the key fields, the syntax check produces a warning, and the SELECT statement reads the first entry that it finds that matches the key fields that you have specified.

The result of the selection is either an elementary field or a flat structure, depending on the number of columns you specified in <cols>. The target area in the INTO clause must be

appropriately convertible. If the system finds a line with the corresponding key, SY-SUBRC is set to 0, otherwise to 4.

thanx.

former_member188685
Active Contributor
0 Kudos

are you including all the keys from ekpo(ebeln, ebelp) may be you are not including all the keys that is the reason you get the duplicates, if you include the keys then you can see the difference.

Former Member
0 Kudos

Hi,

You can do it with the use of select single statement.

Select Single <fields> into corresponding fields of <internal table name>

from <database table> where <condition>.

note one thing we can not use the keyword TABLE with SINGLE, it will give u an error.

One thing more the you can skip the statement (corresponding fields of ) if your internal table and database are similar.

secondly you can try to change your condition like that only one can be fetched.

Hope this will help you.

Regards

Rajesh Kumar

0 Kudos

I know to write the select statment and fetch the records,but my question is how should i access the internal tables.How will the system know that my internal table has to be displayed?

Former Member
0 Kudos

hi,

you can use select single statement for this purpose...

Using select single, only the first record that meets your condition will be fetched and not all records in the database... thus saving time and increasing performance.

Select Single <fields>

into corresponding fields of < table name>

from <database table>

where <condition>.

Regards

preet

former_member497886
Participant
0 Kudos

H,

In the where clause use the primary key, then it will not give duplicate entries.

or use-

Delete adjacent duplicate statement.

Hope this will help u.

Regards,

Mohammadi.

Former Member
0 Kudos

Hi ,

If im right u want to display only unique records of internal table

for that u can delete the duplicate records using

DELETE DUPLICATES ....

And about SELECT SINGLE ....

SELECT SINGLE will fetch only first line from the database which satisfies the condition

thats why it will give error when u use table witha that ...

But as per ur requirement u want more than one record from table ....so u cant use select single ...

u dont want duplicates ... for that u can use delete duplicates ....

Hope it helps .......

0 Kudos

I am not asking you people to tell me how to write a selelct query.I want to access the internal table(in SQ01) so that i can delete adjacent duplicates

Edited by: Rakesh More on Sep 11, 2008 8:04 AM