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

Select Query - a different perspective.

Former Member
0 Likes
1,179

Hello all,

I have to write a query to retrieve data from T156T ( movement type table ).

Each movement type has got many Movement type description text.

Now i need to get 3 movement types descriptions but only the top most value in the table of that particular movement type.

So my query may look like this.

SELECT DISTINCT BWART BTEXT FROM T156T
    INTO TABLE ITAB_BTEXT
    WHERE SPRAS EQ 'EN' AND BWART IN ('542', '101', '122').

Now i have to limit the query to retreive only the top most of that particular movement type.

Is it possible in just one query?

I just wonder whether we can do this directly in the query instead of working with the ITAB and deleting the other rows.

If you have any suggestions then please advice.

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,030

Hi,

I think, if you want to achieve this using only the select query, you have to pass all the primary key fields of the table in the where condition of your query.

Regards

Vinod

5 REPLIES 5
Read only

Former Member
0 Likes
1,030

Hello

Try like this:


SELECT BWART BTEXT FROM T156T
    INTO TABLE ITAB_BTEXT
    WHERE SPRAS EQ 'EN' AND BWART IN ('542', '101', '122')
    AND SOBKZ EQ SAPCE
    AND KZZUG EQ SPACE
    AND KZVBR EQ SPACE.   

Read only

0 Likes
1,030

Hi Dzed Maroz,

Do you have any other suggestions other than mentioning all the field names of that table in the condition?

Your following code wont work as the table has 2 data for each movement type with your condition.

SOBKZ EQ SPACE
   AND KZZUG EQ SPACE
   AND KZVBR EQ SPACE.

Therefore i get 2 data for each movement type.

Any other way to retrieve just the top row for that particular condition?

Thanks.

Read only

Former Member
0 Likes
1,030

Ashok,

Though it is possible,I am not sure about that,it is better to fetch the data into internal table and work on it rather than working on select query which will have more performance

Thanks

Bala Duvvuri

Read only

Former Member
0 Likes
1,031

Hi,

I think, if you want to achieve this using only the select query, you have to pass all the primary key fields of the table in the where condition of your query.

Regards

Vinod

Read only

Former Member
0 Likes
1,030

I dont think its possible to acheive what you are trying with just SPRAS and BWART in the where condition. Either you should specify all the primary keys to get the unique records or manipulate the internal table after the select query as it is now.

Vikranth