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

error in INNER JOIN

Former Member
0 Likes
1,820

Hello friends,

I'm getting an error for a select statement involving an inner join. Could you check and clarify. I would appreciate it.

select *

from kna1 into a inner join knvv as b on akunnr = bkunnr

inner join knb1 as c on akunnr = ckunnr

inner join knvp as e on akunnr = ekunn2

where a~kunnr in s_kunnr.

Thanks!

BG

8 REPLIES 8
Read only

Former Member
0 Likes
1,089

There is problem in the query you have framed,

select *

from kna1 into <b>< Details missing here></b> a inner join knvv as b on akunnr = bkunnr

inner join knb1 as c on akunnr = ckunnr

inner join knvp as e on akunnr = ekunn2

where a~kunnr in s_kunnr.

A sample I found here in SDN,

SELECT a~mandt

a~vbeln

a~posnr

a~lprio

a~matnr

a~kwmeng

a~vrkme

a~netwr

a~waerk

a~kdmat

a~werks

a~pstyv

a~charg

a~route

u~absta

u~fksta

u~gbsta

u~lfsta

a~posex

a~vgbel

u~besta

v~bsark

v~ihrez

INTO TABLE i_vbap

FROM vbap AS a

INNER JOIN vbup AS u ON uvbeln = avbeln AND uposnr = aposnr

INNER JOIN vbkd AS v ON vvbeln = avbeln AND vposnr = aposnr

FOR ALL ENTRIES IN i_vbak

WHERE a~vbeln EQ i_vbak-vbeln.

Please refer how to use joins

http://www.sap-img.com/abap/inner-joins.htm

Regards

Kathirvel

Read only

Former Member
0 Likes
1,089

What kind of error - syntax, runtime?

Rob

Read only

Former Member
0 Likes
1,089

Hi,

Check this change..

1) Remove the * and select the specific fields..

2) Have the INTO clause to move the values to the work area.

<b>select a~kunnr

into wa_kunnr

from kna1 as a</b> inner join knvv as b on akunnr = bkunnr

inner join knb1 as c on akunnr = ckunnr

inner join knvp as e on akunnr = ekunn2

where a~kunnr in s_kunnr.

Thanks,

Naren

Read only

Former Member
0 Likes
1,089

You're missing the INTO clause. Try:


REPORT ztest MESSAGE-ID 00.

TABLES: kna1, knvv, knb1, knvp.

SELECT-OPTIONS: s_kunnr FOR kna1-kunnr.

DATA: BEGIN OF itab OCCURS 0,
        f1,
      END   OF itab.

SELECT *
  FROM kna1 AS a
    INNER JOIN knvv AS b
      ON a~kunnr = b~kunnr
    INNER JOIN knb1 AS c
      ON a~kunnr = c~kunnr
    INNER JOIN knvp AS e
      ON a~kunnr = e~kunn2
  INTO CORRESPONDING FIELDS OF TABLE itab
  WHERE a~kunnr IN s_kunnr.

ITAB is just a generic internal table for my example. You will have to put in the fields you want.

Rob

Message was edited by:

Rob Burbank

Read only

0 Likes
1,089

Thanks bro !

Read only

0 Likes
1,089

Glad to help - close the thread please.

Rob

Read only

0 Likes
1,089

Hi,

although everything has been said:

There is no reason to use alias as from kna1 as a. Just say from kna1 and for instance whetre kna1~kunrr = ... This helps a lot for transparency. Hopefully one day SAP help will also get this.

There is a real need for an alias if you want to koin a table on itself as might be necessary i.e. with VBFA as VBFA_FOLLOWUP.

Also please note: If you use select * and you have the same field name with different contents in the joined tables, this field will not be filled at all. Avoid select * and specify the fields you need as tabname~fieldname. This is also best for performance.

Regards,

Clemens

Read only

Former Member
0 Likes
1,089

thanks for all the help.