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

Report

Former Member
0 Likes
534

Hi,

How to select records from two tables?

Regards.

Sudhan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
508

manikam,

For this you have to use innerjoins.

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.

Don't forget ot reward if useful

5 REPLIES 5
Read only

Former Member
0 Likes
508

Hi Manikam,

U can use joins on two tables if they have any fields in common.

e.g. if we want to select the data from tables VBAK and VBAK then we can write as follows :

SELECT VBAKVBELN VBAKAUART VBAPPOSNR into correspodning fields of table itab from VBAK join VBAP on VBAKVBELN = VBAP~VBELN WHERE

<conditions>.

Other way is to use SELECT ...... FOR ALL ENTRIES.

Regards,

Himanshu

Read only

Former Member
0 Likes
509

manikam,

For this you have to use innerjoins.

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.

Don't forget ot reward if useful

Read only

Former Member
0 Likes
508

hi,

u have make use of inner join for selecting records from more than onew table but u have to have atleast one common field in both the tables.

regards,

ravi

Read only

Former Member
0 Likes
508

Hi,

There are two ways of doing this.

1. Using Joins as mentioned earlier by some.

2. Declare two internal tables for the two database tables and populate any one of them. then use FOR ALL ENTRIES in that filled internal table and populate the other internal table from the other database table. Now declare one final internal table and move the data from the two tables into this. Use the final internal table for displaying the records or for reports.

hope this helps....

reward if helpful....

naba

Read only

Former Member
0 Likes
508

hi

good

you can select data from two table using the INNER JOIN or OUTER JOIN statement.

thanks

mrutyun^