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

Code to Join three tables.

Former Member
0 Likes
573

Hi All,

I am a fresher to this ABAP.

I have an task to join three tables which doesn't take much effort. But the problem is: the tables have same columns, (name, age and city) in all the three tables.

The layout is as shown below:

Table 1 ( T1 ) Table 2 ( T2 ) Table 3 ( T3 )

-


-


-


name | age | city name | age | city name | age | city -


-


-


Anju 21 HDD Anju 20 BGH Anju 21 SFF

Julie 23 JUH Julie 24 JUH Julie 20 JUH

-


-


-


Now, there should be a selection screen. If I enter a value for this varaible as "Anju", The output should be like:

Col T1 T2 T3

-


Name Anju Anju Anju

Age 21 20 21

City HDD BGH SFF

-


I am unable to appraoch how to solve this issue. Any pointers would be of great help.

Thanks in advance,

Anjum.

Edited by: nasarat anjum on Apr 23, 2008 8:43 AM

4 REPLIES 4
Read only

Former Member
0 Likes
545

in one of the way u can display like this: u can get all the data into one record only but u can display in 3 rows.

types : begin of itab,

name_t1, age_t1, city_t1,

name_t2, age_t2, city_t2,

name_t3, age_t3, city_t3,

end of itab,

*data declare for itab.

select t1name t1age t1~city

t2name t2age t2~city

t3name t3age t3~city

into itab

from t1 inner join t2 on t1name = t2name

and t1 inner join t3 on t1name = t3name

and t1~name = p_name.

write : /itab-name_t1, itab-name_t2, itab-name_t3,

/itab-age_t1, itab-age_t2, itab-age_t3,

/itab-city_t1, itab-city_t2, itab-city_t3.

Read only

Sm1tje
Active Contributor
0 Likes
545

Well, if all your columns are the same, no need for you to do a join. Just select the data from ONE database table into an internal table T0. and afterwards transfer the data to the other internal tables T1-T3.

Read only

Former Member
0 Likes
545

Hi,

U can take three internal tables for each of ur tables T1,T2,T3. Fetch the respective table data into ur internal tables.

Then write,

loop at itab1.

read table itba2 with key name eq itab1-name.

read table itab3 with key name eq itab1-name.

write : / name under <name heading>,

itab1-name under <T1 heading>,

itab2-name under <T2 heading>,

itab3-name under <T3 heading>.

write : / age under <age heading>,

itab1-age under <T1 heading>,

itab2-age under <T2 heading>,

itab3-age under <T3 heading>.

write : / city under <city heading>,

itab1-city under <T1 heading>,

itab2-city under <T2 heading>,

itab3-city under <T3 heading>.

<removed by moderator>

Thanks

Edited by: Mike Pokraka on Aug 6, 2008 8:30 AM

Read only

Former Member
0 Likes
545

Closed.