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: 

intersection from 3 tables

Former Member
0 Kudos

Hellow I have an 3 selects and n all select I doing iNTO CORRESPONDING FIELDS OF TABLE itab (1,2,3) how can Iintersection from the 3 tables (values I wont) into one table .example is very help regards

6 REPLIES 6

Former Member
0 Kudos

Hello,

Declare one final table...

LOOP AT ITAB1.

MOVE-CORRESPONDING TO ITAB1 to ITAB_FINAL.

READ TABLE ITAB2 WITH KEY FILED1 = ITAB1-FIELD1.

if sy-subrc = 0.

MOVE-CORRESPONDING TO ITAB2 to ITAB_FINAL.

endif,

READ TABLE ITAB3 WITH KEY FILED1 = ITAB1-FIELD1.

if sy-subrc = 0.

MOVE-CORRESPONDING TO ITAB2 to ITAB_FINAL.

endif,

append itab_final.

clear itab_final.

endloop

If useful reward,

Vasanth

anversha_s
Active Contributor
0 Kudos

hi,

check this code.

data : begin of itab1 occurs 0. "itab with work area.
key_field1 like ztable1-key_field1,
field1 like ztable1-field1,
field2 like ztable1-field2,
endof itab1. 

data : begin of itab2 occurs 0. "itab with work area.
key_field2 like ztable2-key_field2,
field3 like ztable2-field3,
field4 like ztable2-field4,
endof itab2. 

data : begin of itab_final occurs 0.
key_field1 like ztable1-key_field1,
field1 like ztable1-field1,
field2 like ztable1-field2,
field3 like ztable2-field3,
field4 like ztable2-field4,
endof itab_final. 


put the date final(merged) internal table
*****************************************
1. loop at itab1.
read table itab2 with key keyfield2 = itab1-keyfield1.
if sy-surc = 0.
itab_final-key_field1 = itab1-keyfield1
itab_final-field1 = itab1-field1.
itab_final-field2 = itab1-keyfield2.
itab_final-field3 = itab2-field2.
itab_final-field4 = itab2-keyfield2.
append itab_final.
clear itab_final.
endif.
endloop.

Regards

Anver

if hlped pls mark points

Former Member
0 Kudos

Check this code you can put into the internal table

SELECT aequnr abis aab adevloc bzzmun cmatnr

FROM egerh AS a INNER JOIN

iflot AS b

ON adevloc EQ btplnr

INNER JOIN equi AS c

ON aequnr EQ cequnr

INTO TABLE i_dpoint

FOR ALL ENTRIES IN i_bill_reg

WHERE a~equnr EQ i_bill_reg-equnr .

Former Member
0 Kudos

Hi..

You can try joining two of the tables and then use for all entries for third table.

or otherwise you can write two jon statements in single select statement.

e.g.

Select *

from (

INNER JOIN AFIH "afih: Maint order header

ON AFIHAUFNR = AUFKAUFNR

INNER JOIN ILOA "iloa: PM Obj Loc & Acct Assgmt

ON ILOAILOAN = AFIHILOAN

INNER JOIN AFVV "afvv: qty/dates in operation

ON AFVVAUFPL = AFKOAUFPL

) where condition.

Former Member
0 Kudos

Hi

Code like this

<b>select p1field1 p2field2 p3field3 from tab1 as p1 inner join tab2 as p2 on p1field = p2field inner join tab3 as p3 on p3field = p1~field into corresponding fields of table itab.</b>

Mark points if helpful.

Regs

Manas Ranjan Panda

Former Member
0 Kudos

hi,

declare all internal table what u required,

LOOP AT ITAB1.

MOVE-CORRESPONDING TO ITAB1 to ITAB_FINAL.

READ TABLE ITAB2 WITH KEY FILED1 = ITAB1-FIELD1.

if sy-subrc = 0.

MOVE-CORRESPONDING TO ITAB2 to ITAB_FINAL.

endif,

READ TABLE ITAB3 WITH KEY FILED1 = ITAB1-FIELD1.

if sy-subrc = 0.

MOVE-CORRESPONDING TO ITAB2 to ITAB_FINAL.

endif,

append itab_final.

clear itab_final.

endloop