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: 

How to write a join for KNA1 and KNVH.

Former Member
0 Kudos

Howdy,

Is it possible to write a join for KNA1 and KNVH?

Would this be okay:

<b>select *

into table itab

from knvh inner join kna1

on knvhkunnr = kna1kunnr

for all entries in cust_tab

where knvh~hityp = 'A'

and knvh~kunnr = cust_tab-kunnr

and knvh~vkorg = p_vkorg

and knvh~vtweg = p_vtweg

and knvh~spart = p_spart

and knvh~datab le sy-datum

and knvh~datbi ge sy-datum

and knvhhzuor ne kna1hzuor.</b>

1 ACCEPTED SOLUTION

Former Member
0 Kudos

It is actually based on what you need and not based on query.

a) Check whether you want <b>multiple</b> entries from <i>KNA1</i> table for every single entry in <i>KNVH</i>

b) Check whether you want <b>single</b> entry from <i>KNA1</i> table for every single entry in <i>KNVH</i>

Make sure, when using, FOR ALL ENTRIES, you do :

if not cust_tab[] is initial.
...
endif.

Regards,

Subramanian V.

3 REPLIES 3

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

If you know that knvh-hityp is ALWAYS = 'A' . Then I would say yes, looks ok to me.

Regards,

Rich Heilman

Former Member
0 Kudos

Should work okay. Are you having a problem? I prefer to use the dictionary for inner joins whenever possible. Never know when you will need to share the defintion. If you are getting an error, please post.

Former Member
0 Kudos

It is actually based on what you need and not based on query.

a) Check whether you want <b>multiple</b> entries from <i>KNA1</i> table for every single entry in <i>KNVH</i>

b) Check whether you want <b>single</b> entry from <i>KNA1</i> table for every single entry in <i>KNVH</i>

Make sure, when using, FOR ALL ENTRIES, you do :

if not cust_tab[] is initial.
...
endif.

Regards,

Subramanian V.