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

Inner Join

Former Member
0 Likes
805

Hi All,

I have recently came across this statement.

select t001wwerks t001wekorg t001w~vlfkz

from ( t001w inner join t024w on t024wwerks = t001wwerks )

into table lt_t001w

where t001w~vlfkz in lr_vlfkz and

t001w~ekorg in lr_ekorg.

Basically in T024W, I have 25 entries of WERKS of different EKORG and in T001W, i have 13 entries of WERKS of EKORG = 1001 and VLFKZ = A. When running the statement above with the condition 1001 in LR_EKORG and A in LR_VLFKZ repectively, I get all 25 entries with those WERKS which is not originally EKORG = 1001 in T024W becomes 1001 in the output result. I couldn't put my fingers together for this...anyone can help me here?

Thanks!

Moderator message: please use more descriptive subject lines when starting a thread.

Edited by: Thomas Zloch on Nov 22, 2010 4:33 PM

1 ACCEPTED SOLUTION
Read only

brad_bohn
Active Contributor
0 Likes
716

Well, that other post isn't really going to help - adding an alias and changing the field selection for one field...

To answer your question, think about the restriction you have put on the selection and the join: the join is by PLANT and the restriction is by purchasing org from T001W (only). You did not restrict the purchasing org selection from T024W. This means that the join will pick up all purchasing org entries for the plants that were found in T001W. Look at a trace and you'll see how it works. It sounds like since you received all 25 entries from T024W, then the plants found in the T001W cover all of those entries?

4 REPLIES 4
Read only

Former Member
0 Likes
716

Try with the below code...

select awerks bekorg b~vlfkz

from t024w as a inner join t001w as b

on awerks = bwerks

into table it_t001w

where b~vlfkz in lr_vlfkz and

b~ekorg in lr_ekorg.

Regards

Praveen

Read only

brad_bohn
Active Contributor
0 Likes
717

Well, that other post isn't really going to help - adding an alias and changing the field selection for one field...

To answer your question, think about the restriction you have put on the selection and the join: the join is by PLANT and the restriction is by purchasing org from T001W (only). You did not restrict the purchasing org selection from T024W. This means that the join will pick up all purchasing org entries for the plants that were found in T001W. Look at a trace and you'll see how it works. It sounds like since you received all 25 entries from T024W, then the plants found in the T001W cover all of those entries?

Read only

tushar_shukla
Active Participant
0 Likes
716

Cady,

Brad has already pointed out the root cause . You can add EKORG in where clause while joining the two tables e.g.

select t001wwerks t001wekorg t001w~vlfkz

from ( t001w inner join t024w on t024wwerks = t001wwerks AND t024wekorg = t001wekorg )

into table lt_t001w

where t001w~vlfkz in lr_vlfkz and

t001w~ekorg in lr_ekorg.

- Tushar

Read only

0 Likes
716

I just realized there's duplicates entries in the return result...after deleting duplicates, it's fine.

Thanks for all your input.