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

select data from two tables

Former Member
0 Likes
1,372

tab1 : select 10 rows.

tab2 : for the above 10 rows for each has 20 rows in tab2 ( duplicare records ).

but both tables common field is BUKRS only .

how can i select data .

Regards,

Mk.

10 REPLIES 10
Read only

Former Member
0 Likes
1,271

Hi Kumar,

What r the Tables.. I mean the table Name & what is your scenario..

Read only

Former Member
0 Likes
1,271

Hi,

Use Upto 10 rows in select statement.

eg.

SELECT * FROM mara UP TO 10 ROWS INTO TABLE itab.

in the first select query and use for all entries in first select query internal table the second select query.

This will solve ur problem.

Read only

Former Member
0 Likes
1,271

first select ..

select bukrs f2 f3 ... from table1 into itab1 up to 10 rows.

if sy-subrc = 0.

select (all the key fields) from table2 into itab2

for all entries in itab1

where bukrs = itab1-bukrs.

endif.

Read only

0 Likes
1,271

Thanks to all for reply,

the code is below plz coorect me :

form get_data.

SELECT bukrs belnr budat awkey

INTO TABLE it_final

FROM bkpf

WHERE bukrs = bukrs AND

budat IN budat AND

( blart = 'RE' OR

blart = 'RN' ) .

SORT IT_FINAL BY belnr.

LOOP at it_final.

V_AWKEY = it_final-awkey(10).

SELECT BUKRS belnr ebeln ebelp matnr menge salk3 kschl wrbtr lifnr shkzg xblnr BUZEI

INTO TABLE it_rseg

from rseg

where belnr = V_AWKEY .

SORT it_rseg by belnr.

LOOP AT it_rseg.

it_final-belnr = it_rseg-belnr.

it_final-xblnr = it_rseg-xblnr.

it_final-buzei = it_rseg-buzei.

enDLOOP.

modify it_final.

CLEAR it_final.

CLEAR V_AWKEY.

CLEAR it_rseg.

ENDLOOP.

ENDFORM.

Read only

faisalatsap
Active Contributor
0 Likes
1,271

HI,

Use LEFT OUTER JOIN hope will solve out your problem, Have a look at the following Sample Code.

select anla~anln1 anla~ord41 anla~ord43 anla~ord44 anla~invnr anla~sernr anlu~zdate anlu~zztot_status
         a~ordtx as tot_desc b~ordtx as mod_desc c~ordtx as injec_cat
          into corresponding fields of table it_asset_details
          from anla
          inner join anlu  on ( anla~bukrs = anlu~bukrs and anla~anln1 = anlu~anln1 and anla~anln2 = anlu~anln2 )
          left outer join t087t as a on ( anla~ord41 = a~ord4x and a~spras = 'E' and a~ordnr = '1' )
          left outer join t087t as b on ( anla~ord43 = b~ord4x and b~spras = 'E' and b~ordnr = '3' )
          left outer join t087t as c on ( anla~ord44 = c~ord4x and c~spras = 'E' and c~ordnr = '4' )
          where anlu~zzssok = outlet_id.
  sort it_asset_details by zdate.

Kind Regards,

Faisal

Read only

Former Member
0 Likes
1,271

Hi,

Use FOR ALL ENTERIES,

for the second table query write as

select <required Fields> from <tabname> into table itab2 FOR ALL ENTERIES <first Table Name>

where BUKRS = itab1-BUKRS.

Read only

Former Member
0 Likes
1,271

Hi,

Try this:

select * from tab1 into itab1.

select * from tab2 FOR all entries in itab1 into itab2 where bukrs = itab1-bukrs.

Cheers,

Surinder

Read only

Former Member
0 Likes
1,271

try this,

use for all entries ....

{select <field names>

bukrs

from tale1

into table itab1.

if sy-subrc = 0.

select <field names>

from table2

into table itab2

for all entries in itab1

where bukrs = itab1-bukrs.

endif.}

Read only

Former Member
0 Likes
1,271

Hi,

Don't post same question multiple times, Use same thread.

Read only

Former Member
0 Likes
1,271

yes