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

loop query

Former Member
0 Likes
918

i have a simple loop query. I want to get same data from 3 different tables into a single internal table like

if tab1 data is not available then tab2 then tab3.

now when i use my internal table how do i fill data into my internal table and what will be my loop condition.

i have already written select statement.

a sample code will be of great help

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
723

Hi,

The above said code I think it doesn't work properly because in the select statement from table name placed after the internal table and also no need of append statement.

Use like this...(itab-Internal table name)

Select * from tab1 into table itab

where (condition).

if sy-subrc <> 0.

Select * from tab2 into table itab

where(condition).

if sy-subrc <> 0.

Select * from tab3 into table itab

where (condition).

endif.

endif.

Now you will get value in the internal table itab.Three different tables where tab1,tab2,tab3.

Thanks,

Sakthi C

*Rewards if useful--*

6 REPLIES 6
Read only

Former Member
0 Likes
723

Hi,

Paste your code here which you have written, so that it will be easy for us to guide you.

Regards,

Satish

Read only

Former Member
0 Likes
723

to get data from different table into one table use following code

select * from ztab1 into table itab where <...>.

select * from ztab2 appending table itab where <.....>.

Read only

0 Likes
723

paste ur code here so that problem can b understood clearly

for getting data

first select

if sy-subrc <> 0 " in case of not getting data in first select

put here 2nd select

then again

put if sy-subrc <> 0 " in case of not getting data in 2nd and first select

put third select statement

if u provide ur code then may b we can help a little more

regards

Read only

Former Member
0 Likes
723

Hi, sample code below:

select * into ITAB from TAB1 where <conditions>.
  append ITAB.
endselect.

if sy-subrc <> 0.
  select * into ITAB from TAB2 where <conditions>.
    append ITAB.
  endselect.

  if sy-subrc <> 0.
    select * into ITAB from TAB3 where <conditions>.
      append ITAB.
    endselect.
  endif.
endif.

Read only

Former Member
0 Likes
724

Hi,

The above said code I think it doesn't work properly because in the select statement from table name placed after the internal table and also no need of append statement.

Use like this...(itab-Internal table name)

Select * from tab1 into table itab

where (condition).

if sy-subrc <> 0.

Select * from tab2 into table itab

where(condition).

if sy-subrc <> 0.

Select * from tab3 into table itab

where (condition).

endif.

endif.

Now you will get value in the internal table itab.Three different tables where tab1,tab2,tab3.

Thanks,

Sakthi C

*Rewards if useful--*

Read only

Former Member
0 Likes
723

Thanks for your help guys.

I was able to resolve it looking at the sample code provided.

I have awarded points

Regards