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

2 queries into one

Former Member
0 Likes
1,171

Hi Gems,

I had wriiten two queries as below. Can somene tell me how do i combine the below 2 quesries into one using table aliasing or any other way?

get the func location

IF NOT IT_BUS[] IS INITIAL.

SELECT TPLNR IWERK

FROM IFLOT

INTO CORRESPONDING FIELDS OF TABLE IT_TECH

FOR ALL ENTRIES IN IT_BUS[]

WHERE TPLNR = IT_BUS-HAUS

AND FLTYP EQ 'C'.

IF IT_TECH[] IS NOT INITIAL.

obtain the Superior Func location(TPLMA) again from IFLOT

SELECT TPLNR TPLMA IWERK

FROM IFLOT

INTO CORRESPONDING FIELDS OF TABLE IT_TECH2

FOR ALL ENTRIES IN IT_TECH[]

WHERE TPLMA = IT_TECH-TPLNR

AND IWERK = P_WERKS

AND FLTYP = 'L'.

Please suggest.

thanks

Dan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,140

Hi,

If you use a sub-query, it may effect the performance. So I think you don't need to combine these two queries.

Regards,

Chris Gu

Hi Gems,

I had wriiten two queries as below. Can somene tell me how do i combine the below 2 quesries into one using table aliasing or any other way?

get the func location

IF NOT IT_BUS[] IS INITIAL.

SELECT TPLNR IWERK

FROM IFLOT

INTO CORRESPONDING FIELDS OF TABLE IT_TECH

FOR ALL ENTRIES IN IT_BUS[]

WHERE TPLNR = IT_BUS-HAUS

AND FLTYP EQ 'C'.

IF IT_TECH[] IS NOT INITIAL.

obtain the Superior Func location(TPLMA) again from IFLOT

SELECT TPLNR TPLMA IWERK

FROM IFLOT

INTO CORRESPONDING FIELDS OF TABLE IT_TECH2

FOR ALL ENTRIES IN IT_TECH[]

WHERE TPLMA = IT_TECH-TPLNR

AND IWERK = P_WERKS

AND FLTYP = 'L'.

Please suggest.

thanks

Dan

8 REPLIES 8
Read only

Former Member
0 Likes
1,140

one way can be combining the data of two of your internal tables into one final table.

and then use that table for final query.

Regards

Neha

Read only

0 Likes
1,140

Hi Neha Shukla,

Thanks! but I want to AVOID hitting the DB tabe IFLOT twice. Your suggestion still maked me to hit the table once again.

Any alternative idea...?

thanks

Dan

Read only

Former Member
0 Likes
1,140

A sub-query might work, but you would end up with only one internal table.

Rob

Read only

0 Likes
1,140

Yes Rob that seems to be helpful. Can you please go ahead how to write that?

Read only

0 Likes
1,140

First, check the documentation on SELECT and give it a try. If you still have problems, get back to the forum.

Rob

Read only

Former Member
0 Likes
1,141

Hi,

If you use a sub-query, it may effect the performance. So I think you don't need to combine these two queries.

Regards,

Chris Gu

Read only

0 Likes
1,140

>

> If you use a sub-query, it may effect the performance. So I think you don't need to combine these two queries.

Chris - do you have an example where a sub-query affects performance poorly?

Rob

Read only

Former Member
0 Likes
1,140

better not to write any aliasing