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: 

Join Tables

Former Member
0 Kudos

Hi all,

I have a scenario where I have got three tables two std ones and the third one is the custom one bseg,bkpf and ztest, and based on three fields i.e. belnr, blart and bukrs( which is in all the three tables )to join these tables and need to retreive the following the data from each table:

From BSEG - - -> saknr,kostl

From BKPF- - - - > blart,bldat

and

From Ztest -


> co_num, co_name

So can you please tell me how can I achieve this.

Thanks,

Rajeev !!!

.....

2 REPLIES 2

Sm1tje
Active Contributor
0 Kudos

types: begin of ty_itab,

saknr type ..

kostl type ...

blart type ....

co_num type ....

co_name type...

types: end of ty_itab.

data: itab type table of ty_itab.

select BSEG~saknr

BSEG~kostl

BKPF~blart

BKPF~bldat

ztest~co_num

ztest~co_name

from bseg inner join

bkpf

on bsegbelnr = bkprbelnr

and bsegblart = bkpfblart

and bsegbukrs = bkpfbukrs inner join

ztest on ztestbelnr = bsegbelnr

and ztestblart = bsegblart

and ztestbukrs = bsegbukrs

into table itab

where .....

Former Member
0 Kudos

Hi,

You can do as below:



First get all the data from BKPF for the fields belnr, blart, bldat and bukrs into one internal table as this is the header table for document .

select bukrs belnr blart bldat budat from bkpf into table gt_bkpf where <condition>.

"Then go to BSEG table using BKPF details

select bukrs belnr blart saknr kostl from bseg into table gt_bseg  for all entries of gt_bkpf where <condition>.

"Then go to ZTable using the details of BSEG gt_bseg using for all entries .

select co_num, co_name from ztable into table gt_table where <condition>.

"You can use the gt_table for the output.

Please use the fields depends upon your requirement.

Thanks,

Sriram Ponna.