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: 

fetch the data from two tables

Former Member
0 Kudos

hell all

i want to fetch the data from two tables, one is from internal table and another one is data base table. what syntax i have to use either FOR ALL ENTRIES or INNER JOIN?

8 REPLIES 8

Former Member
0 Kudos

Select *

from (Standard Table)

into table ITAB

where (conditions)

if not ITAB is initial.

Select *

from (Standard table 2)

into table ITAB2

FOR ALL ENTRIES IN ITAB

where (Conditions eq itab-fields atleast one).

endif.

Regards

Kannaiah

Former Member
0 Kudos

hi,

you can not fetch data from internal table because its already there for temporary.

select queries are applied for data base fetch.

you can fetch data from database table.

you can make use of your internal table data.

i don know your requirement..

Former Member
0 Kudos

Hi.

Use All Entries.

use this code

Select * from EKKO table into it_ekko.

IF it_EKKO[] IS NOT INITIAL.

SELECT * FROM EKPO

INTO TABLE it_EKPO

FOR ALL ENTRIES IN it_EKKO

WHERE vbeln = it_EKKO-vbeln.

endif.

Regards,

jay

Former Member
0 Kudos

Hi,

You have to use for all entries only. Just have a glance with the following code. It will give you some sense.

data : itab like mara occurs 0 with header line,

itab1 like mseg occurs 0 with header line.

start-of-selection.

select * from mara into table itab where mtart = 'FERT'.

select * from mseg into corresponding fields of table itab1

for all entries in itab where matnr = itab-matnr

and bwart = '131'.

Regards,

Sankar.

Former Member
0 Kudos

hi

'FOR ALL ENTRIES' is used to improve ur system performance

its good practice to write code which use less db access.

'FOR ALL ENTRIES' is used with internal tables.

1) fetch data for single itab and use it with 'FOR ALL ENTRIES'

and populate the other tables.

sample code for the same:

select vbeln

posnr

matwa

matkl

from vbap into table vbap_it where vbeln in salesdoc.

select vbeln

erdat

ernam

from vbak into table vbap_it1 for all entries in vbap_it

where vbeln = vbap_it-vbeln.

use inner in ur prog. and populate itab1

then use for all entries in next select query

reward points if helpful

regards

mano

Former Member
0 Kudos

hi

Use FOR ALL ENTRIES.

see the sample code

select * into table tvbrk from vbrk

where fkart in ('F2', 'F3', 'RE',

'ZVEC' , 'ZVEM' , 'ZVED',

'S1')

and erdat in so_erdat

and kunag in s_kunag.

erdat in so_erdat

and fkart in ('F2', 'F3', 'RE',

'ZVEC' , 'ZVEM').

if not tvbrk is initial.

select * into table t_zregion from zregion

for all entries in tvbrk

where country = tvbrk-land1

and region = s_regio.

endif.

thanks

sitaram

Former Member
0 Kudos

Hi,

Use 'All Entries'

code :

Select * from TableA(Database Table) into itab.

IF itab[] IS NOT INITIAL.

SELECT * FROM TableA

INTO TABLE itab

FOR ALL ENTRIES IN itab

WHERE Field1(Database Table field) = itab-Field1.

endif.

Regards,

Biswanath

Former Member
0 Kudos

Hi Swamy,

Its not advisable to use INNER JOIN for than 3 tables.

Its better to use FOR ALL ENTRIES instead.