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

reg select query problem

Former Member
0 Likes
737

hi all,

hope all r doing fine?

anyway i have a query which is mentioned below:-

select field1,.....fieldn

from <dbtable1>

into corresponding fields of table itab

where <condition>.

select field1,...fieldn

from <dbtable2>

appending corresponding fields of table itab

where <condition>.

the above two select stmts retrieve same set of fields from two different database tables into same internal table itab..

now my question is ...........is any other way to change 2nd select statement without using appending correspondin fields

but the functionality should remain the same as it is after changing..................

bcos appending corresponding is causing performance problem in data retrieval.

thanx alot in advance.

for sure points will be given for all the helpful answers

Jack

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
716

Hi,

You can use like that:

select field1,.....fieldn

from <dbtable1>

into corresponding fields of table itab1

where <condition>.

select field1,...fieldn

from <dbtable2>

appending corresponding fields of table itab2

where <condition>.

now u use:

loop at itab2 into w_itab2.

read table itab1 into w_itab1 with key w_itab1-<primary field> = w_itab2-<Primary field>.

if sy-subrc = 0.

append w_final into i_final.

else continue.

endif.

endloop.

*i_final table having all data ( i.e itab2 & itab1 data)

5 REPLIES 5
Read only

dhruv_shah3
Active Contributor
0 Likes
716

Hi,

You can First Select all the Data into the Internal Table,

and then you can have the Loop..EndLoop Statement

inside that you can place the read table statement and append the data to the Internal table.

HTH

Regards,

Dhruv Shah

Read only

Former Member
0 Likes
716

Hi ,

First point don't use

INTO CORRESPONDING FIELDS OF TABLE ITAB.

Use INTO TABLE ITAB when your extracting fields and internal table fields are same.

2.

select field1,.....fieldn

from <dbtable1>

into table itab1

where <condition>.

select field1,...fieldn

from <dbtable2>

INTO table itab2

where <condition>.

LOOP AT ITAB2.

MOVE LINES OF TABLE ITAB2 TO ITAB1.

APPEND ITAB1

CLEAR ITAB1.

ENDLOOP.

FREE ITAB2.

Read only

Former Member
0 Likes
717

Hi,

You can use like that:

select field1,.....fieldn

from <dbtable1>

into corresponding fields of table itab1

where <condition>.

select field1,...fieldn

from <dbtable2>

appending corresponding fields of table itab2

where <condition>.

now u use:

loop at itab2 into w_itab2.

read table itab1 into w_itab1 with key w_itab1-<primary field> = w_itab2-<Primary field>.

if sy-subrc = 0.

append w_final into i_final.

else continue.

endif.

endloop.

*i_final table having all data ( i.e itab2 & itab1 data)

Read only

Former Member
0 Likes
716

Don't use 'into corresponding fields' ..

select field1,.....fieldn

from <dbtable1>

into table itab

where <condition>.

select field1,...fieldn

from <dbtable2>

into table itab1

where <condition>.

loop at itab1.

itab = itab1. <-- since both itab and itab1 have the same structure

append itab.

clear itab.

endloop.

Read only

Former Member
0 Likes
716

Hi,

1. Avoid using 'into corresponding fields of'. Instead declare internal table in the same order as that of database selection.

2. After first select query move it to an temporary internal table and do the second select query. If u need all data (from 2 select queries) in the same internal table, append it later.

Reward if helpful.

Regards,

Ramya