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 use innerjoin and select for all entries together

aarif_baig
Active Participant
5 REPLIES 5

0 Kudos

Hi Aarif,

Firstly to say the difference b/w for all and inner join would be..

1. INNER JOIN

DBTAB1 <----


> DBTAB2

It is used to JOIN two tables

having some COMMON fields.

2. Whereas

For All Entries,

DBTAB1 <----


> ITAB1

is not at all related to two tables.

It is related to internal table.

3. If we want to fetch data

from some DBTABLE1

but we want to fetch

for only some records

which are contained in some internal table,

then we use for alll entries.

Remember performance wil be very bad when you use both inner join and for all entries as for all entries is also another type of join.

A code that shows usage of both using MARA and MAKT tabs.

select mara~matnr makt

into corresponding fields table of itab

from mara

join makt on maramatnr = maktmatnr

and makt~spras = sy-langu

for all entries in itab

where matnr = itab-matnr.

<b>

Reward if found useful.</b>

Regards,

harish

Former Member
0 Kudos

Joins: joins will work on 2 DB tables.

SELECT A~KTOPL

A~ERSDA

A~KSTSN

B~KOKRS

B~KSTAR

B~DATBI

B~KATYP

C~SPRAS

C~KTEXT

C~LTEXT INTO CORRESPONDING FIELDS OF TABLE ITAB

FROM CSKA AS A

INNER JOIN CSKB AS B ON AKSTAR = BKSTAR

INNER JOIN CSKU AS C ON BKSTAR = CKSTAR

WHERE A~KSTAR IN S_KTO.

For all entries: in this first get data from one table and use that one in second query.

SELECT * FROM CSKA INTO TABLE IT_CSKA WHERE KSTAR IN S_KSTAR.

IF SY-SUBRC = 0.

SORT IT_CSKA BY KSTAR.

ENDIF.

SELECT * FROM CSKB INTO TABLE IT_CSKB

FOR ALL ENTRIES IN IT_CSKA

WHERE KSTAR = IT_CSKA-KSTAR.

I hope u can understand.

Award points helpful.

brahmaji.

Former Member
0 Kudos

Hi Aasif,

Use the Synatx as accordingly.

**********************************************************************************************

sort it_data by matnr werks.

select bmatnr bwerks abedvp from t461s as a inner join marc as b on astra1 = b~strgr into table it_strgt For all entries in it_data where matnr = it_data-matnr and werks = it_data-werks.

**********************************************************************************************

Hope this resolves your query.

Reward All the helpful answers.

Regards

Nagaraj

Former Member
0 Kudos

See the below example.

SELECT ekko~bukrs

ekko~lifnr

ekko~ebeln

ekko~waers

ekko~bsart

ekko~ekorg

ekko~ekgrp

ekpo~ebelp

ekpo~txz01

ekpo~matnr

ekpo~werks

ekpo~menge

ekpo~meins

ekpo~netpr

ekpo~netwr

INTO TABLE t_itab1 FROM

ekko INNER JOIN ekpo ON ekkoebeln = ekpoebeln

WHERE ekko~ebeln IN s_ebeln AND

ekko~bukrs IN s_bukrs AND

ekko~lifnr IN s_lifnr AND

ekko~ekorg IN s_ekorg AND

ekko~ekgrp IN s_ekgrp AND

ekpo~matnr IN s_matnr AND

ekko~bsart = p_bsart.

ENDIF.

IF NOT t_itab1[] IS INITIAL.

  • FETCHING NAME1

SELECT werks

name1

FROM t001w

INTO TABLE t_name1

FOR ALL ENTRIES IN t_itab1

WHERE werks = t_itab1-werks.

SORT t_itab1 BY werks.

SORT t_name1 BY werks.

Former Member
0 Kudos

use innerjoin technique and sort the itab so that all the duplicate rows will be gone

select * from mara as ma innerjoin marc as mr on mamatnr = mrmatnr innerjoin into table itab.

after that declare this so that duplicate rows wii be gone

sort itab.

regards